mage-engine 3.23.20 → 3.23.24

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 +1114 -459
  2. package/package.json +1 -1
package/dist/mage.js CHANGED
@@ -53992,6 +53992,7 @@ var DEPRECATIONS = {
53992
53992
  };
53993
53993
  var IMPORTER_ERROR_ELEMENT_CREATION = "".concat(PREFIX, " Error while creating element: ");
53994
53994
  var IMPORTER_ERROR_LIGHT_CREATION = "".concat(PREFIX, " Error while creating light: ");
53995
+ var IMPORTER_ERROR_SOUND_CREATION = "".concat(PREFIX, " Error while creating sound: ");
53995
53996
  var IMPORTER_ERROR_UNKNOWN_ELEMENT_SUBTYPE = "".concat(PREFIX, " Unknown element subtype: ");
53996
53997
  var ONCREATE_NOT_AVAILABLE = "".concat(PREFIX, " Your scene needs a onCreate method.");
53997
53998
  var PATH_NOT_FOUND = "".concat(PREFIX, " can't find requested path");
@@ -54035,7 +54036,8 @@ var AUDIO_CONTEXT_NOT_AVAILABLE = "".concat(PREFIX, " No Audio Context available
54035
54036
  var AUDIO_UNABLE_TO_LOAD_SOUND = "".concat(PREFIX, " Unable to load sound, sorry.");
54036
54037
  var AUDIO_SOURCE_NOT_DEFINED = "".concat(PREFIX, " No audio source defined. Set a source for this sound.");
54037
54038
  var LIGHT_NOT_FOUND = "".concat(PREFIX, " This light was not created properly.");
54038
- var LIGHT_HOLDER_MODEL_NOT_FOUND$1 = "".concat(PREFIX, " This light holder model can't be found.");
54039
+ var LIGHT_HOLDER_MODEL_NOT_FOUND = "".concat(PREFIX, " This light holder model can't be found.");
54040
+ var SOUND_HOLDER_MODEL_NOT_FOUND = "".concat(PREFIX, " This sound holder model can't be found.");
54039
54041
  var LABEL_DOMELEMENT_MISSING = "".concat(PREFIX, " Could not create Label, domElement is missing. Did you forget to set the this.element ref on your component?");
54040
54042
  var NO_VALID_LEVEL_DATA_PROVIDED = "".concat(PREFIX, " No valid level data (json or url) provided");/*
54041
54043
  A dynamic script that can be attached to an entity.
@@ -56323,7 +56325,7 @@ var convertAmmoVector = function convertAmmoVector(_ref2) {
56323
56325
  };
56324
56326
  };var utils=/*#__PURE__*/Object.freeze({__proto__:null,DEFAULT_DESCRIPTION:DEFAULT_DESCRIPTION$1,mapColliderTypeToAddEvent:mapColliderTypeToAddEvent$1,extractBoundingBox:extractBoundingBox,extractBiggestBoundingBox:extractBiggestBoundingBox,extractBoundingSphere:extractBoundingSphere,extractBiggestBoundingSphere:extractBiggestBoundingSphere,parseBoundingBoxSize:parseBoundingBoxSize,extractPositionAndQuaternion:extractPositionAndQuaternion$1,extractBoxDescription:extractBoxDescription,extractSphereDescription:extractSphereDescription,getBoxDescriptionForElement:getBoxDescriptionForElement$1,getSphereDescriptionForElement:getSphereDescriptionForElement,mapColliderTypeToDescription:mapColliderTypeToDescription$1,iterateGeometries:iterateGeometries$1,convertAmmoVector:convertAmmoVector});var getHostURL = function getHostURL() {
56325
56327
  return "".concat(document.location.protocol, "//").concat(document.location.host);
56326
- };var _excluded$a = ["uuid"];
56328
+ };var _excluded$c = ["uuid"];
56327
56329
  var COLLIDER_TYPES = COLLIDER_TYPES$1;
56328
56330
  var getBoxDescriptionForElement = getBoxDescriptionForElement$1,
56329
56331
  extractPositionAndQuaternion = extractPositionAndQuaternion$1,
@@ -56397,7 +56399,7 @@ var Physics = /*#__PURE__*/function (_EventDispatcher) {
56397
56399
 
56398
56400
  _defineProperty$1(_assertThisInitialized(_this), "handleBodyUpdate", function (_ref3) {
56399
56401
  var uuid = _ref3.uuid,
56400
- data = _objectWithoutProperties(_ref3, _excluded$a);
56402
+ data = _objectWithoutProperties(_ref3, _excluded$c);
56401
56403
 
56402
56404
  var element = Universe$1.getByUUID(uuid);
56403
56405
 
@@ -58256,8 +58258,8 @@ function applyMiddleware() {
58256
58258
  }
58257
58259
 
58258
58260
  var thunk = createThunkMiddleware();
58259
- thunk.withExtraArgument = createThunkMiddleware;var name$1 = "mage-engine";
58260
- var version$1 = "3.23.20";
58261
+ thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
58262
+ var version$1 = "3.23.24";
58261
58263
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
58262
58264
  var main = "dist/mage.js";
58263
58265
  var author$1 = {
@@ -58340,7 +58342,7 @@ var devDependencies = {
58340
58342
  "rollup-plugin-web-worker-loader": "1.6.1"
58341
58343
  };
58342
58344
  var packageJSON = {
58343
- name: name$1,
58345
+ name: name,
58344
58346
  version: version$1,
58345
58347
  description: description,
58346
58348
  main: main,
@@ -59533,7 +59535,7 @@ if (!self.fetch) {
59533
59535
  self.Headers = Headers;
59534
59536
  self.Request = Request;
59535
59537
  self.Response = Response;
59536
- }var _excluded$9 = ["wheels", "accelerationKey", "brakingKey", "rightKey", "leftKey", "debug", "autostart"];
59538
+ }var _excluded$b = ["wheels", "accelerationKey", "brakingKey", "rightKey", "leftKey", "debug", "autostart"];
59537
59539
 
59538
59540
  var BaseCar = /*#__PURE__*/function (_BaseScript) {
59539
59541
  _inherits(BaseCar, _BaseScript);
@@ -59561,7 +59563,7 @@ var BaseCar = /*#__PURE__*/function (_BaseScript) {
59561
59563
  options.debug;
59562
59564
  var _options$autostart = options.autostart,
59563
59565
  autostart = _options$autostart === void 0 ? true : _options$autostart,
59564
- physicsOptions = _objectWithoutProperties(options, _excluded$9);
59566
+ physicsOptions = _objectWithoutProperties(options, _excluded$b);
59565
59567
 
59566
59568
  this.car = element;
59567
59569
  this.wheels = wheels;
@@ -61781,7 +61783,7 @@ var populateMap = function populateMap(map, data) {
61781
61783
  map.set(k, data[k]);
61782
61784
  });
61783
61785
  return map;
61784
- };var map$1=/*#__PURE__*/Object.freeze({__proto__:null,serializeMap:serializeMap,deserialiseMap:deserialiseMap,populateMap:populateMap});var _excluded$8 = ["position", "quaternion"],
61786
+ };var map$1=/*#__PURE__*/Object.freeze({__proto__:null,serializeMap:serializeMap,deserialiseMap:deserialiseMap,populateMap:populateMap});var _excluded$a = ["position", "quaternion"],
61785
61787
  _excluded2 = ["applyPhysicsUpdate"],
61786
61788
  _excluded3 = ["dt", "event"];
61787
61789
  var COLLIDER_TAG = "collider";
@@ -61971,7 +61973,7 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
61971
61973
  _defineProperty$1(_assertThisInitialized(_this), "handlePhysicsUpdate", function (_ref6) {
61972
61974
  var position = _ref6.position,
61973
61975
  quaternion = _ref6.quaternion,
61974
- data = _objectWithoutProperties(_ref6, _excluded$8);
61976
+ data = _objectWithoutProperties(_ref6, _excluded$a);
61975
61977
 
61976
61978
  _this.setPosition(position);
61977
61979
 
@@ -62334,7 +62336,11 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
62334
62336
  var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MATERIAL_PROPERTIES_DEFAULT_VALUES[PROPERTIES.COLOR];
62335
62337
 
62336
62338
  var _setColor = function _setColor(material) {
62337
- return material.color = new Color$1(color);
62339
+ if (color && _typeof(color) === 'object' && 'r' in color && 'g' in color && 'b' in color) {
62340
+ material.color.setRGB(color.r, color.g, color.b);
62341
+ } else {
62342
+ material.color = new Color$1(color);
62343
+ }
62338
62344
  };
62339
62345
 
62340
62346
  if (color) {
@@ -62490,7 +62496,15 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
62490
62496
  var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MATERIAL_PROPERTIES_DEFAULT_VALUES[PROPERTIES.SPECULAR];
62491
62497
 
62492
62498
  var _setSpecularColor = function _setSpecularColor(material) {
62493
- return material[PROPERTIES.SPECULAR] = new Color$1(color);
62499
+ if (color && _typeof(color) === 'object' && 'r' in color && 'g' in color && 'b' in color) {
62500
+ if (!material[PROPERTIES.SPECULAR]) {
62501
+ material[PROPERTIES.SPECULAR] = new Color$1();
62502
+ }
62503
+
62504
+ material[PROPERTIES.SPECULAR].setRGB(color.r, color.g, color.b);
62505
+ } else {
62506
+ material[PROPERTIES.SPECULAR] = new Color$1(color);
62507
+ }
62494
62508
  };
62495
62509
 
62496
62510
  applyMaterialChange(this.getBody(), _setSpecularColor);
@@ -62554,7 +62568,15 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
62554
62568
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MATERIAL_PROPERTIES_DEFAULT_VALUES[PROPERTIES.EMISSIVE];
62555
62569
 
62556
62570
  var _setEmissive = function _setEmissive(material) {
62557
- return material[PROPERTIES.EMISSIVE] = new Color$1(value);
62571
+ if (value && _typeof(value) === 'object' && 'r' in value && 'g' in value && 'b' in value) {
62572
+ if (!material[PROPERTIES.EMISSIVE]) {
62573
+ material[PROPERTIES.EMISSIVE] = new Color$1();
62574
+ }
62575
+
62576
+ material[PROPERTIES.EMISSIVE].setRGB(value.r, value.g, value.b);
62577
+ } else {
62578
+ material[PROPERTIES.EMISSIVE] = new Color$1(value);
62579
+ }
62558
62580
  };
62559
62581
 
62560
62582
  applyMaterialChange(this.getBody(), _setEmissive);
@@ -63723,7 +63745,7 @@ var Plane = /*#__PURE__*/function (_Element) {
63723
63745
  }]);
63724
63746
 
63725
63747
  return Box;
63726
- }(Element$1);var _excluded$7 = ["anisotropy", "sizeAttenuation", "depthTest", "depthWrite"];
63748
+ }(Element$1);var _excluded$9 = ["anisotropy", "sizeAttenuation", "depthTest", "depthWrite"];
63727
63749
 
63728
63750
  var validateAnisotropy = function validateAnisotropy(anisotropy) {
63729
63751
  var max = Scene$1.getRenderer().capabilities.getMaxAnisotropy();
@@ -63759,7 +63781,7 @@ var Sprite = /*#__PURE__*/function (_Element) {
63759
63781
  depthTest = _options$depthTest === void 0 ? true : _options$depthTest,
63760
63782
  _options$depthWrite = options.depthWrite,
63761
63783
  depthWrite = _options$depthWrite === void 0 ? true : _options$depthWrite,
63762
- rest = _objectWithoutProperties(options, _excluded$7);
63784
+ rest = _objectWithoutProperties(options, _excluded$9);
63763
63785
 
63764
63786
  var texture = Images$1.get(spriteTexture);
63765
63787
 
@@ -87038,7 +87060,7 @@ var Proton = three_proton_min.exports;var ParticleEmitterGroup = /*#__PURE__*/fu
87038
87060
  }]);
87039
87061
 
87040
87062
  return ParticleEmitterGroup;
87041
- }(Entity);var _excluded$6 = ["initializers", "behaviours", "texture", "color", "rate"];
87063
+ }(Entity);var _excluded$8 = ["initializers", "behaviours", "texture", "color", "rate"];
87042
87064
  var DEFAULT_PARTICLE_COLOR = PALETTES.BASE.BLACK;
87043
87065
  var SYSTEM_DISPOSE_TIMEOUT = 700;
87044
87066
 
@@ -87063,7 +87085,7 @@ var ProtonParticleEmitter = /*#__PURE__*/function (_ParticleEmitter) {
87063
87085
  _options$color = options.color,
87064
87086
  color = _options$color === void 0 ? DEFAULT_PARTICLE_COLOR : _options$color,
87065
87087
  rate = options.rate,
87066
- rest = _objectWithoutProperties(options, _excluded$6);
87088
+ rest = _objectWithoutProperties(options, _excluded$8);
87067
87089
 
87068
87090
  var parsedOptions = _objectSpread2$1({
87069
87091
  initializers: initializers,
@@ -87280,7 +87302,7 @@ var Explosion = /*#__PURE__*/function (_ParticleEmitterGroup) {
87280
87302
  }
87281
87303
 
87282
87304
  return Explosion;
87283
- }(ParticleEmitterGroup);var _excluded$5 = ["texture", "direction", "size", "strength", "colors"];
87305
+ }(ParticleEmitterGroup);var _excluded$7 = ["texture", "direction", "size", "strength", "colors"];
87284
87306
 
87285
87307
  var getFireRate = function getFireRate() {
87286
87308
  return new Proton.Rate(new Proton.Span(10, 15), new Proton.Span(0.05, 0.1));
@@ -87314,7 +87336,7 @@ var Fire = /*#__PURE__*/function (_ProtonParticleEmitte) {
87314
87336
  _options$strength = options.strength,
87315
87337
  strength = _options$strength === void 0 ? 100 : _options$strength,
87316
87338
  colors = options.colors,
87317
- rest = _objectWithoutProperties(options, _excluded$5);
87339
+ rest = _objectWithoutProperties(options, _excluded$7);
87318
87340
 
87319
87341
  var fireOptions = _objectSpread2$1({
87320
87342
  rate: getFireRate(),
@@ -91178,7 +91200,7 @@ var storage = new Storage();var Light$1 = /*#__PURE__*/function (_Entity) {
91178
91200
  _this.holder = holderSprite;
91179
91201
  return true;
91180
91202
  } else {
91181
- console.warn(LIGHT_HOLDER_MODEL_NOT_FOUND$1);
91203
+ console.warn(LIGHT_HOLDER_MODEL_NOT_FOUND);
91182
91204
  return false;
91183
91205
  }
91184
91206
  });
@@ -91307,7 +91329,11 @@ var storage = new Storage();var Light$1 = /*#__PURE__*/function (_Entity) {
91307
91329
  }, {
91308
91330
  key: "setColor",
91309
91331
  value: function setColor(color) {
91310
- this.body.color = color;
91332
+ if (color && _typeof(color) === 'object' && 'r' in color && 'g' in color && 'b' in color) {
91333
+ this.body.color.setRGB(color.r, color.g, color.b);
91334
+ } else {
91335
+ this.body.color.set(color);
91336
+ }
91311
91337
  }
91312
91338
  }, {
91313
91339
  key: "getColor",
@@ -91621,6 +91647,37 @@ var PointLight$1 = /*#__PURE__*/function (_Light) {
91621
91647
  shadowCamera: this.getShadowCameraNearFar()
91622
91648
  });
91623
91649
  }
91650
+ }], [{
91651
+ key: "create",
91652
+ value: function create() {
91653
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
91654
+ var color = data.color,
91655
+ intensity = data.intensity,
91656
+ name = data.name,
91657
+ position = data.position,
91658
+ distance = data.distance,
91659
+ decay = data.decay,
91660
+ bias = data.bias,
91661
+ mapSize = data.mapSize,
91662
+ shadowCamera = data.shadowCamera;
91663
+
91664
+ var _ref3 = shadowCamera || {},
91665
+ near = _ref3.near,
91666
+ far = _ref3.far;
91667
+
91668
+ return new PointLight({
91669
+ color: color,
91670
+ intensity: intensity,
91671
+ name: name,
91672
+ position: position,
91673
+ distance: distance,
91674
+ decay: decay,
91675
+ near: near,
91676
+ far: far,
91677
+ mapSize: mapSize,
91678
+ bias: bias
91679
+ });
91680
+ }
91624
91681
  }]);
91625
91682
 
91626
91683
  return PointLight;
@@ -91729,7 +91786,16 @@ var AmbientLight$1 = /*#__PURE__*/function (_Light) {
91729
91786
  key: "create",
91730
91787
  value: function create() {
91731
91788
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
91732
- return new AmbientLight(data.options);
91789
+ var color = data.color,
91790
+ intensity = data.intensity,
91791
+ name = data.name,
91792
+ position = data.position;
91793
+ return new AmbientLight({
91794
+ color: color,
91795
+ intensity: intensity,
91796
+ name: name,
91797
+ position: position
91798
+ });
91733
91799
  }
91734
91800
  }]);
91735
91801
 
@@ -92035,6 +92101,41 @@ var SpotLight$1 = /*#__PURE__*/function (_Light) {
92035
92101
  angle: this.getAngle()
92036
92102
  });
92037
92103
  }
92104
+ }], [{
92105
+ key: "create",
92106
+ value: function create() {
92107
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
92108
+ var color = data.color,
92109
+ intensity = data.intensity,
92110
+ name = data.name,
92111
+ position = data.position,
92112
+ distance = data.distance,
92113
+ angle = data.angle,
92114
+ penumbra = data.penumbra,
92115
+ decay = data.decay,
92116
+ bias = data.bias,
92117
+ mapSize = data.mapSize,
92118
+ shadowCamera = data.shadowCamera;
92119
+
92120
+ var _ref3 = shadowCamera || {},
92121
+ near = _ref3.near,
92122
+ far = _ref3.far;
92123
+
92124
+ return new SpotLight({
92125
+ color: color,
92126
+ intensity: intensity,
92127
+ name: name,
92128
+ position: position,
92129
+ distance: distance,
92130
+ angle: angle,
92131
+ penumbra: penumbra,
92132
+ decay: decay,
92133
+ near: near,
92134
+ far: far,
92135
+ mapSize: mapSize,
92136
+ bias: bias
92137
+ });
92138
+ }
92038
92139
  }]);
92039
92140
 
92040
92141
  return SpotLight;
@@ -92074,7 +92175,7 @@ var SpotLight$1 = /*#__PURE__*/function (_Light) {
92074
92175
  _this.holder = holderSprite;
92075
92176
  return true;
92076
92177
  } else {
92077
- console.warn(LIGHT_HOLDER_MODEL_NOT_FOUND$1);
92178
+ console.warn(LIGHT_HOLDER_MODEL_NOT_FOUND);
92078
92179
  return false;
92079
92180
  }
92080
92181
  });
@@ -92203,7 +92304,11 @@ var SpotLight$1 = /*#__PURE__*/function (_Light) {
92203
92304
  }, {
92204
92305
  key: "setColor",
92205
92306
  value: function setColor(color) {
92206
- this.body.color = color;
92307
+ if (color && _typeof(color) === 'object' && 'r' in color && 'g' in color && 'b' in color) {
92308
+ this.body.color.setRGB(color.r, color.g, color.b);
92309
+ } else {
92310
+ this.body.color.set(color);
92311
+ }
92207
92312
  }
92208
92313
  }, {
92209
92314
  key: "getColor",
@@ -92324,9 +92429,20 @@ var HemisphereLight$1 = /*#__PURE__*/function (_Light) {
92324
92429
  sky = _ref.sky,
92325
92430
  ground = _ref.ground;
92326
92431
 
92327
- if (sky && ground) {
92328
- _this.getBody().color = sky;
92329
- _this.getBody().groundColor = ground;
92432
+ if (sky !== undefined) {
92433
+ if (_typeof(sky) === 'object' && 'r' in sky && 'g' in sky && 'b' in sky) {
92434
+ _this.getBody().color.setRGB(sky.r, sky.g, sky.b);
92435
+ } else {
92436
+ _this.getBody().color.set(sky);
92437
+ }
92438
+ }
92439
+
92440
+ if (ground !== undefined) {
92441
+ if (_typeof(ground) === 'object' && 'r' in ground && 'g' in ground && 'b' in ground) {
92442
+ _this.getBody().groundColor.setRGB(ground.r, ground.g, ground.b);
92443
+ } else {
92444
+ _this.getBody().groundColor.set(ground);
92445
+ }
92330
92446
  }
92331
92447
  });
92332
92448
 
@@ -92420,6 +92536,21 @@ var HemisphereLight$1 = /*#__PURE__*/function (_Light) {
92420
92536
  } : color
92421
92537
  });
92422
92538
  }
92539
+ }], [{
92540
+ key: "create",
92541
+ value: function create() {
92542
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
92543
+ var color = data.color,
92544
+ intensity = data.intensity,
92545
+ name = data.name,
92546
+ position = data.position;
92547
+ return new HemisphereLight({
92548
+ color: color,
92549
+ intensity: intensity,
92550
+ name: name,
92551
+ position: position
92552
+ });
92553
+ }
92423
92554
  }]);
92424
92555
 
92425
92556
  return HemisphereLight;
@@ -92666,12 +92797,666 @@ var SunLight$1 = /*#__PURE__*/function (_Light) {
92666
92797
  key: "create",
92667
92798
  value: function create() {
92668
92799
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
92669
- return new SunLight(data.options);
92800
+ var color = data.color,
92801
+ intensity = data.intensity,
92802
+ name = data.name,
92803
+ position = data.position,
92804
+ bias = data.bias,
92805
+ mapSize = data.mapSize,
92806
+ shadowCamera = data.shadowCamera;
92807
+
92808
+ var _ref3 = shadowCamera || {},
92809
+ near = _ref3.near,
92810
+ far = _ref3.far,
92811
+ fov = _ref3.fov;
92812
+
92813
+ return new SunLight({
92814
+ color: color,
92815
+ intensity: intensity,
92816
+ name: name,
92817
+ position: position,
92818
+ near: near,
92819
+ far: far,
92820
+ mapSize: mapSize,
92821
+ bias: bias,
92822
+ fov: fov
92823
+ });
92670
92824
  }
92671
92825
  }]);
92672
92826
 
92673
92827
  return SunLight;
92674
- }(Light$1);var difference = function difference(a, b) {
92828
+ }(Light$1);var DEFAULT_SETUP_CONFIG$1 = {
92829
+ deferred: false
92830
+ };
92831
+
92832
+ var Sound$1 = /*#__PURE__*/function (_Entity) {
92833
+ _inherits(Sound, _Entity);
92834
+
92835
+ var _super = _createSuper(Sound);
92836
+
92837
+ function Sound() {
92838
+ var _this;
92839
+
92840
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
92841
+
92842
+ _classCallCheck(this, Sound);
92843
+
92844
+ var source = options.source,
92845
+ _options$loop = options.loop,
92846
+ loop = _options$loop === void 0 ? false : _options$loop,
92847
+ loopStart = options.loopStart,
92848
+ loopEnd = options.loopEnd,
92849
+ autoplay = options.autoplay,
92850
+ reconnectOnReset = options.reconnectOnReset,
92851
+ _options$setupConfig = options.setupConfig,
92852
+ setupConfig = _options$setupConfig === void 0 ? DEFAULT_SETUP_CONFIG$1 : _options$setupConfig,
92853
+ _options$name = options.name,
92854
+ name = _options$name === void 0 ? generateRandomName("sound") : _options$name;
92855
+ _this = _super.call(this, _objectSpread2$1(_objectSpread2$1({}, options), {}, {
92856
+ source: source,
92857
+ loop: loop,
92858
+ loopStart: loopStart,
92859
+ loopEnd: loopEnd,
92860
+ autoplay: autoplay,
92861
+ reconnectOnReset: reconnectOnReset,
92862
+ name: name
92863
+ }));
92864
+
92865
+ _defineProperty$1(_assertThisInitialized(_this), "reset", function () {
92866
+ _this.playing = false;
92867
+
92868
+ _this.disconnect();
92869
+
92870
+ _this.setupAudio();
92871
+
92872
+ _this.connect();
92873
+ });
92874
+
92875
+ _this.setupConfig = setupConfig;
92876
+ _this.source = source;
92877
+ _this.loop = loop;
92878
+ _this.loopStart = loopStart;
92879
+ _this.loopEnd = loopEnd;
92880
+ _this.autoplay = autoplay;
92881
+ _this.reconnectOnReset = reconnectOnReset;
92882
+ _this.name = name;
92883
+ _this.connected = false;
92884
+ _this.playing = false;
92885
+ _this.setupCompleted = false;
92886
+ _this.hasPlayed = false;
92887
+ _this.buffer = null;
92888
+ _this.audioNode = null;
92889
+ _this.volumeNode = null;
92890
+ _this.detuneValue = 0;
92891
+
92892
+ if (!_this.setupConfig.deferred) {
92893
+ _this.setupAudio();
92894
+ }
92895
+
92896
+ _this.setName(name);
92897
+
92898
+ _this.setBody({
92899
+ body: new Object3D()
92900
+ });
92901
+
92902
+ _this.setEntityType(ENTITY_TYPES.AUDIO.TYPE);
92903
+
92904
+ _this.setEntitySubtype(ENTITY_TYPES.AUDIO.SUBTYPES.DEFAULT);
92905
+
92906
+ Scene$1.add(_this.getBody(), _assertThisInitialized(_this));
92907
+ Audio$1.add(_assertThisInitialized(_this));
92908
+
92909
+ if (_this.isSetupCompleted()) {
92910
+ _this.connect();
92911
+ }
92912
+
92913
+ return _this;
92914
+ }
92915
+
92916
+ _createClass(Sound, [{
92917
+ key: "addHelpers",
92918
+ value: function addHelpers() {
92919
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
92920
+ _ref$holderName = _ref.holderName,
92921
+ holderName = _ref$holderName === void 0 ? "soundholder" : _ref$holderName,
92922
+ _ref$holderSize = _ref.holderSize,
92923
+ holderSize = _ref$holderSize === void 0 ? 0.05 : _ref$holderSize;
92924
+
92925
+ var holderSprite = new HelperSprite(holderSize, holderSize, holderName, {
92926
+ name: holderName
92927
+ });
92928
+
92929
+ if (holderSprite) {
92930
+ holderSprite.setSizeAttenuation(false);
92931
+ holderSprite.setDepthTest(false);
92932
+ holderSprite.setDepthWrite(false);
92933
+ holderSprite.setSerializable(false);
92934
+ holderSprite.setPosition(this.getPosition());
92935
+ holderSprite.addTags([TAGS.HELPER, TAGS.SOUNDS.HELPER, TAGS.SOUNDS.HOLDER, holderName]);
92936
+ holderSprite.setHelperTarget(this);
92937
+ this.holder = holderSprite;
92938
+ return true;
92939
+ } else {
92940
+ console.warn(SOUND_HOLDER_MODEL_NOT_FOUND);
92941
+ return false;
92942
+ }
92943
+ }
92944
+ }, {
92945
+ key: "isPlaying",
92946
+ value: function isPlaying() {
92947
+ return this.playing;
92948
+ }
92949
+ }, {
92950
+ key: "isSetupCompleted",
92951
+ value: function isSetupCompleted() {
92952
+ return this.setupCompleted;
92953
+ }
92954
+ }, {
92955
+ key: "isConnected",
92956
+ value: function isConnected() {
92957
+ return this.connected;
92958
+ }
92959
+ }, {
92960
+ key: "setupAudio",
92961
+ value: function setupAudio() {
92962
+ this.createAudioNode();
92963
+ this.createVolumeNode();
92964
+ this.setBuffer();
92965
+ this.setupAudioNodeLoop();
92966
+ this.audioNode.removeEventListener(ENTITY_EVENTS.AUDIO.ENDED, this.onSoundEnded.bind(this));
92967
+ this.audioNode.addEventListener(ENTITY_EVENTS.AUDIO.ENDED, this.onSoundEnded.bind(this));
92968
+ this.setupCompleted = true;
92969
+ }
92970
+ }, {
92971
+ key: "setSource",
92972
+ value: function setSource(source) {
92973
+ this.source = source;
92974
+ }
92975
+ }, {
92976
+ key: "getSource",
92977
+ value: function getSource() {
92978
+ return this.source;
92979
+ }
92980
+ }, {
92981
+ key: "createAudioNode",
92982
+ value: function createAudioNode() {
92983
+ this.audioNode = Audio$1.context.createBufferSource();
92984
+ }
92985
+ }, {
92986
+ key: "setupAudioNodeLoop",
92987
+ value: function setupAudioNodeLoop() {
92988
+ this.audioNode.loop = this.loop;
92989
+ this.audioNode.loopEnd = this.loopEnd === undefined ? this.duration : this.loopEnd;
92990
+ this.audioNode.loopStart = this.loopStart === undefined ? this.duration : this.loopStart;
92991
+ }
92992
+ }, {
92993
+ key: "createVolumeNode",
92994
+ value: function createVolumeNode() {
92995
+ this.volumeNode = Audio$1.context.createGain();
92996
+ this.volumeNode.gain.value = DEFAULT_AUDIO_NODE_VOLUME;
92997
+ }
92998
+ }, {
92999
+ key: "tryAutoplay",
93000
+ value: function tryAutoplay() {
93001
+ if (this.autoplay && !this.hasPlayed && !this.setupConfig.deferred) {
93002
+ this.play();
93003
+ }
93004
+ }
93005
+ }, {
93006
+ key: "connect",
93007
+ value: function connect() {
93008
+ if (this.isConnected()) {
93009
+ this.disconnect();
93010
+ }
93011
+
93012
+ this.volumeNode.connect(Audio$1.getMasterVolumeNode());
93013
+ this.audioNode.connect(this.volumeNode);
93014
+ this.connected = true;
93015
+ this.tryAutoplay();
93016
+ }
93017
+ }, {
93018
+ key: "disconnect",
93019
+ value: function disconnect() {
93020
+ if (this.isConnected()) {
93021
+ this.volumeNode.disconnect();
93022
+ this.audioNode.disconnect();
93023
+ this.connected = false;
93024
+ }
93025
+ }
93026
+ }, {
93027
+ key: "dispose",
93028
+ value: function dispose() {
93029
+ _get(_getPrototypeOf(Sound.prototype), "dispose", this).call(this);
93030
+
93031
+ this.stop();
93032
+ this.disconnect();
93033
+ }
93034
+ }, {
93035
+ key: "getVolume",
93036
+ value: function getVolume() {
93037
+ return this.volumeNode ? this.volumeNode.gain.value : Audio$1.getVolume();
93038
+ }
93039
+ }, {
93040
+ key: "setVolume",
93041
+ value: function setVolume() {
93042
+ var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_AUDIO_NODE_VOLUME;
93043
+ this.volumeNode.gain.setValueAtTime(value, Audio$1.context.currentTime);
93044
+ }
93045
+ }, {
93046
+ key: "hasBuffer",
93047
+ value: function hasBuffer() {
93048
+ return !!this.buffer;
93049
+ }
93050
+ }, {
93051
+ key: "setBuffer",
93052
+ value: function setBuffer() {
93053
+ if (!this.getSource()) {
93054
+ console.error(AUDIO_SOURCE_NOT_DEFINED);
93055
+ return false;
93056
+ }
93057
+
93058
+ var buffer = Audio$1.get(this.source);
93059
+
93060
+ if (!buffer) {
93061
+ console.error(AUDIO_UNABLE_TO_LOAD_SOUND);
93062
+ return false;
93063
+ }
93064
+
93065
+ this.buffer = buffer;
93066
+ this.audioNode.buffer = buffer;
93067
+ return true;
93068
+ }
93069
+ }, {
93070
+ key: "play",
93071
+ value: function play() {
93072
+ var volume = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getVolume();
93073
+ var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_AUDIO_NODE_RAMP_TIME;
93074
+ var ramp = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : AUDIO_RAMPS.LINEAR;
93075
+ if (this.isPlaying()) return this;
93076
+ if (!this.isSetupCompleted()) this.setupAudio();
93077
+ if (!this.isConnected()) this.connect();
93078
+ this.setVolume(0);
93079
+ this.audioNode.start();
93080
+ this.hasPlayed = true;
93081
+ this.playing = true;
93082
+ var audioDelay = delay / 1000; // linearRampToValueAtTime/exponentialRampToValueAtTime requires time to be expressed in seconds
93083
+
93084
+ if (ramp === AUDIO_RAMPS.LINEAR) {
93085
+ this.volumeNode.gain.linearRampToValueAtTime(volume, Audio$1.context.currentTime + audioDelay);
93086
+ } else {
93087
+ this.volumeNode.gain.exponentialRampToValueAtTime(volume, Audio$1.context.currentTime + audioDelay);
93088
+ }
93089
+
93090
+ return this;
93091
+ }
93092
+ }, {
93093
+ key: "onSoundEnded",
93094
+ value: function onSoundEnded() {
93095
+ this.reset();
93096
+ this.dispatchEvent({
93097
+ type: ENTITY_EVENTS.AUDIO.ENDED
93098
+ });
93099
+ }
93100
+ }, {
93101
+ key: "stop",
93102
+ value: function stop() {
93103
+ var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_AUDIO_NODE_RAMP_TIME;
93104
+ var ramp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : AUDIO_RAMPS.LINEAR;
93105
+ var audioDelay = delay / 1000; // linearRampToValueAtTime/exponentialRampToValueAtTime requires time to be expressed in seconds
93106
+
93107
+ if (ramp === AUDIO_RAMPS.LINEAR) {
93108
+ this.volumeNode.gain.linearRampToValueAtTime(ALMOST_ZERO, Audio$1.context.currentTime + audioDelay);
93109
+ } else {
93110
+ this.volumeNode.gain.exponentialRampToValueAtTime(ALMOST_ZERO, Audio$1.context.currentTime + audioDelay);
93111
+ }
93112
+
93113
+ setTimeout(this.reset, delay);
93114
+ return this;
93115
+ }
93116
+ }, {
93117
+ key: "detune",
93118
+ value: function detune(value) {
93119
+ if (this.audioNode) {
93120
+ this.detuneValue = value;
93121
+ this.audioNode.detune.value = this.detuneValue;
93122
+ }
93123
+ }
93124
+ }, {
93125
+ key: "getDetune",
93126
+ value: function getDetune() {
93127
+ return this.detuneValue;
93128
+ }
93129
+ }, {
93130
+ key: "addEffect",
93131
+ value: function addEffect(effect) {
93132
+ if (!this.hasEffect() && effect) {
93133
+ this.convolverNode = Audio$1.context.createConvolver();
93134
+ this.mixerNode = Audio$1.createGain();
93135
+
93136
+ if (this.hasPannerNode()) {
93137
+ this.pannerNode.disconnect();
93138
+ this.pannerNode.connect(this.mixerNode);
93139
+ } else {
93140
+ this.volumeNode.disconnect();
93141
+ this.volumeNode.connect(this.mixerNode);
93142
+ } //creating gains
93143
+
93144
+
93145
+ this.plainGainNode = Audio$1.context.createGain();
93146
+ this.convolverGainNode = Audio$1.context.createGain(); //connect mixer to new gains
93147
+
93148
+ this.mixerNode.connect(this.plainGainNode);
93149
+ this.mixerNode.connect(this.convolverGainNode);
93150
+ this.plainGainNode.connect(Audio$1.getMasterVolumeNode());
93151
+ this.convolverGainNode.connect(Audio$1.getMasterVolumeNode());
93152
+ this.convolverNode.buffer = Audio$1.get(effect);
93153
+ this.convolverGainNode.gain.setValueAtTime(0.7, Audio$1.context.currentTime);
93154
+ this.plainGainNode.gain.setValueAtTime(0.3, Audio$1.context.currentTime);
93155
+ }
93156
+ }
93157
+ }, {
93158
+ key: "setPosition",
93159
+ value: function setPosition(where) {
93160
+ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
93161
+ _ref2$updateHolder = _ref2.updateHolder,
93162
+ updateHolder = _ref2$updateHolder === void 0 ? true : _ref2$updateHolder;
93163
+
93164
+ var position = _objectSpread2$1(_objectSpread2$1({}, this.getPosition()), where);
93165
+
93166
+ var x = position.x,
93167
+ y = position.y,
93168
+ z = position.z;
93169
+
93170
+ if (this.hasBody()) {
93171
+ this.body.position.set(x, y, z);
93172
+ }
93173
+
93174
+ if (this.hasHolder() && updateHolder) {
93175
+ this.holder.setPosition({
93176
+ x: x,
93177
+ y: y,
93178
+ z: z
93179
+ });
93180
+ }
93181
+ }
93182
+ }, {
93183
+ key: "usingHelper",
93184
+ value: function usingHelper() {
93185
+ return !!this.isUsingHelper;
93186
+ }
93187
+ }, {
93188
+ key: "hasHolder",
93189
+ value: function hasHolder() {
93190
+ return !!this.holder;
93191
+ }
93192
+ }, {
93193
+ key: "toJSON",
93194
+ value: function toJSON() {
93195
+ var parseJSON = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
93196
+ return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(Sound.prototype), "toJSON", this).call(this, parseJSON)), {}, {
93197
+ source: this.source,
93198
+ loop: this.loop,
93199
+ loopStart: this.loopStart,
93200
+ loopEnd: this.loopEnd,
93201
+ autoplay: this.autoplay,
93202
+ reconnectOnReset: this.reconnectOnReset,
93203
+ volume: this.getVolume(),
93204
+ detune: this.getDetune(),
93205
+ hasPlayed: this.hasPlayed,
93206
+ playing: this.isPlaying(),
93207
+ connected: this.isConnected(),
93208
+ duration: this.hasBuffer() ? this.duration : 0,
93209
+ sampleRate: this.hasBuffer() ? this.sampleRate : 0,
93210
+ numberOfChannels: this.hasBuffer() ? this.numberOfChannels : 0
93211
+ });
93212
+ }
93213
+ }, {
93214
+ key: "sampleRate",
93215
+ get: function get() {
93216
+ return this.buffer.sampleRate;
93217
+ }
93218
+ }, {
93219
+ key: "duration",
93220
+ get: function get() {
93221
+ return this.buffer.duration * 1000;
93222
+ }
93223
+ }, {
93224
+ key: "numberOfChannels",
93225
+ get: function get() {
93226
+ return this.buffer.numberOfChannels;
93227
+ }
93228
+ }], [{
93229
+ key: "create",
93230
+ value: function create() {
93231
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
93232
+ var source = data.source,
93233
+ loop = data.loop,
93234
+ loopStart = data.loopStart,
93235
+ loopEnd = data.loopEnd,
93236
+ autoplay = data.autoplay,
93237
+ reconnectOnReset = data.reconnectOnReset,
93238
+ _data$options = data.options,
93239
+ options = _data$options === void 0 ? {} : _data$options;
93240
+ return new Sound(_objectSpread2$1({
93241
+ source: source,
93242
+ loop: loop,
93243
+ loopStart: loopStart,
93244
+ loopEnd: loopEnd,
93245
+ autoplay: autoplay,
93246
+ reconnectOnReset: reconnectOnReset
93247
+ }, options));
93248
+ }
93249
+ }]);
93250
+
93251
+ return Sound;
93252
+ }(Entity);var _excluded$6 = ["name"];
93253
+
93254
+ var AmbientSound$1 = /*#__PURE__*/function (_Sound) {
93255
+ _inherits(AmbientSound, _Sound);
93256
+
93257
+ var _super = _createSuper(AmbientSound);
93258
+
93259
+ function AmbientSound(source) {
93260
+ var _this;
93261
+
93262
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
93263
+ _ref$name = _ref.name,
93264
+ name = _ref$name === void 0 ? generateRandomName("AmbientSound") : _ref$name,
93265
+ options = _objectWithoutProperties(_ref, _excluded$6);
93266
+
93267
+ _classCallCheck(this, AmbientSound);
93268
+
93269
+ _this = _super.call(this, _objectSpread2$1({
93270
+ source: source,
93271
+ name: name
93272
+ }, options));
93273
+
93274
+ _this.setEntityType(ENTITY_TYPES.AUDIO.TYPE);
93275
+
93276
+ _this.setEntitySubtype(ENTITY_TYPES.AUDIO.SUBTYPES.AMBIENT);
93277
+
93278
+ return _this;
93279
+ }
93280
+
93281
+ _createClass(AmbientSound, null, [{
93282
+ key: "create",
93283
+ value: function create() {
93284
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
93285
+ var source = data.source,
93286
+ loop = data.loop,
93287
+ loopStart = data.loopStart,
93288
+ loopEnd = data.loopEnd,
93289
+ autoplay = data.autoplay,
93290
+ reconnectOnReset = data.reconnectOnReset,
93291
+ name = data.name,
93292
+ _data$options = data.options,
93293
+ options = _data$options === void 0 ? {} : _data$options;
93294
+ return new AmbientSound(source, _objectSpread2$1({
93295
+ loop: loop,
93296
+ loopStart: loopStart,
93297
+ loopEnd: loopEnd,
93298
+ autoplay: autoplay,
93299
+ reconnectOnReset: reconnectOnReset,
93300
+ name: name
93301
+ }, options));
93302
+ }
93303
+ }]);
93304
+
93305
+ return AmbientSound;
93306
+ }(Sound$1);var _excluded$5 = ["name"];
93307
+
93308
+ var DirectionalSound$1 = /*#__PURE__*/function (_Sound) {
93309
+ _inherits(DirectionalSound, _Sound);
93310
+
93311
+ var _super = _createSuper(DirectionalSound);
93312
+
93313
+ function DirectionalSound(source) {
93314
+ var _this;
93315
+
93316
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
93317
+ _ref$name = _ref.name,
93318
+ name = _ref$name === void 0 ? generateRandomName("DirectionalSound") : _ref$name,
93319
+ options = _objectWithoutProperties(_ref, _excluded$5);
93320
+
93321
+ _classCallCheck(this, DirectionalSound);
93322
+
93323
+ _this = _super.call(this, _objectSpread2$1({
93324
+ source: source,
93325
+ name: name
93326
+ }, options));
93327
+
93328
+ _this.setEntityType(ENTITY_TYPES.AUDIO.TYPE);
93329
+
93330
+ _this.setEntitySubtype(ENTITY_TYPES.AUDIO.SUBTYPES.DIRECTIONAL);
93331
+
93332
+ return _this;
93333
+ }
93334
+
93335
+ _createClass(DirectionalSound, [{
93336
+ key: "setupAudio",
93337
+ value: function setupAudio() {
93338
+ _get(_getPrototypeOf(DirectionalSound.prototype), "setupAudio", this).call(this);
93339
+
93340
+ this.createPannerNode(this.options);
93341
+ }
93342
+ }, {
93343
+ key: "hasPannerNode",
93344
+ value: function hasPannerNode() {
93345
+ return !!this.pannerNode;
93346
+ }
93347
+ }, {
93348
+ key: "createPannerNode",
93349
+ value: function createPannerNode() {
93350
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
93351
+ var _options$coneInnerAng = options.coneInnerAngleDegrees,
93352
+ coneInnerAngleDegrees = _options$coneInnerAng === void 0 ? 360 : _options$coneInnerAng,
93353
+ _options$coneOuterAng = options.coneOuterAngleDegrees,
93354
+ coneOuterAngleDegrees = _options$coneOuterAng === void 0 ? 0 : _options$coneOuterAng,
93355
+ _options$coneOuterGai = options.coneOuterGain,
93356
+ coneOuterGain = _options$coneOuterGai === void 0 ? 0 : _options$coneOuterGai,
93357
+ _options$maxDistance = options.maxDistance,
93358
+ maxDistance = _options$maxDistance === void 0 ? 10000 : _options$maxDistance,
93359
+ _options$rolloffFacto = options.rolloffFactor,
93360
+ rolloffFactor = _options$rolloffFacto === void 0 ? 1 : _options$rolloffFacto,
93361
+ _options$refDistance = options.refDistance,
93362
+ refDistance = _options$refDistance === void 0 ? 1 : _options$refDistance;
93363
+ this.pannerNode = Audio$1.context.createPanner();
93364
+ this.pannerNode.panningModel = "HRTF";
93365
+ this.pannerNode.distanceModel = "inverse";
93366
+ this.pannerNode.refDistance = refDistance;
93367
+ this.pannerNode.maxDistance = maxDistance;
93368
+ this.pannerNode.rolloffFactor = rolloffFactor;
93369
+ this.pannerNode.coneInnerAngle = coneInnerAngleDegrees;
93370
+ this.pannerNode.coneOuterAngle = coneOuterAngleDegrees;
93371
+ this.pannerNode.coneOuterGain = coneOuterGain;
93372
+ }
93373
+ }, {
93374
+ key: "connect",
93375
+ value: function connect() {
93376
+ if (this.connected) {
93377
+ this.disconnect();
93378
+ }
93379
+
93380
+ this.volumeNode.connect(Audio$1.getMasterVolumeNode());
93381
+ this.pannerNode.connect(this.volumeNode);
93382
+ this.audioNode.connect(this.pannerNode);
93383
+ this.connected = true;
93384
+ this.tryAutoplay();
93385
+ }
93386
+ }, {
93387
+ key: "disconnect",
93388
+ value: function disconnect() {
93389
+ if (this.connected) {
93390
+ this.volumeNode.disconnect();
93391
+ this.pannerNode.disconnect();
93392
+ this.audioNode.disconnect();
93393
+ this.connected = false;
93394
+ }
93395
+ }
93396
+ }, {
93397
+ key: "updatePannerOrientation",
93398
+ value: function updatePannerOrientation() {
93399
+ var vec = new Vector3$1(0, 0, 1);
93400
+ var m = this.getBody().matrixWorld;
93401
+ var mx = m.elements[12],
93402
+ my = m.elements[13],
93403
+ mz = m.elements[14];
93404
+ m.elements[12] = m.elements[13] = m.elements[14] = 0;
93405
+ vec.applyMatrix4(m);
93406
+ vec.normalize();
93407
+ this.pannerNode.orientationX.setValueAtTime(vec.x, Audio$1.context.currentTime);
93408
+ this.pannerNode.orientationY.setValueAtTime(vec.y, Audio$1.context.currentTime);
93409
+ this.pannerNode.orientationZ.setValueAtTime(vec.z, Audio$1.context.currentTime);
93410
+ m.elements[12] = mx;
93411
+ m.elements[13] = my;
93412
+ m.elements[14] = mz;
93413
+ }
93414
+ }, {
93415
+ key: "updatePannerPosition",
93416
+ value: function updatePannerPosition() {
93417
+ this.getBody().updateMatrixWorld();
93418
+ var position = new Vector3$1();
93419
+ position.setFromMatrixPosition(this.getBody().matrixWorld);
93420
+ this.pannerNode.positionX.setValueAtTime(position.x, Audio$1.context.currentTime);
93421
+ this.pannerNode.positionY.setValueAtTime(position.y, Audio$1.context.currentTime);
93422
+ this.pannerNode.positionZ.setValueAtTime(position.z, Audio$1.context.currentTime);
93423
+ }
93424
+ }, {
93425
+ key: "update",
93426
+ value: function update(dt) {
93427
+ _get(_getPrototypeOf(DirectionalSound.prototype), "update", this).call(this, dt);
93428
+
93429
+ if (this.hasPannerNode()) {
93430
+ this.updatePannerOrientation();
93431
+ this.updatePannerPosition();
93432
+ }
93433
+ }
93434
+ }], [{
93435
+ key: "create",
93436
+ value: function create() {
93437
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
93438
+ var source = data.source,
93439
+ loop = data.loop,
93440
+ loopStart = data.loopStart,
93441
+ loopEnd = data.loopEnd,
93442
+ autoplay = data.autoplay,
93443
+ reconnectOnReset = data.reconnectOnReset,
93444
+ name = data.name,
93445
+ _data$options = data.options,
93446
+ options = _data$options === void 0 ? {} : _data$options;
93447
+ return new DirectionalSound(source, _objectSpread2$1({
93448
+ loop: loop,
93449
+ loopStart: loopStart,
93450
+ loopEnd: loopEnd,
93451
+ autoplay: autoplay,
93452
+ reconnectOnReset: reconnectOnReset,
93453
+ name: name
93454
+ }, options));
93455
+ }
93456
+ }]);
93457
+
93458
+ return DirectionalSound;
93459
+ }(Sound$1);var difference = function difference(a, b) {
92675
93460
  var s = new Set(b);
92676
93461
  return a.filter(function (x) {
92677
93462
  return !s.has(x);
@@ -92986,7 +93771,7 @@ var Importer = /*#__PURE__*/function () {
92986
93771
  value: function completeElementCreation(element, elementData, options) {
92987
93772
  Importer.completeCommonCreationSteps(element, elementData, options); // setting material
92988
93773
 
92989
- if (elementData.materials.length) {
93774
+ if (elementData.materials && elementData.materials.length) {
92990
93775
  var defaultMaterialOptionKeys = MATERIAL_PROPERTIES_MAP[elementData.materialType];
92991
93776
  var disallowedMaterialOptions = difference(Object.keys(elementData.materials[0]), defaultMaterialOptionKeys);
92992
93777
  var materialOptions = omit(disallowedMaterialOptions, elementData.materials[0]);
@@ -92994,14 +93779,43 @@ var Importer = /*#__PURE__*/function () {
92994
93779
  } // setting textures
92995
93780
 
92996
93781
 
92997
- var parsedTextures = JSON.parse(elementData.textures);
92998
- element.setNormalScale();
92999
- Object.keys(parsedTextures).forEach(function (textureType) {
93000
- var _parsedTextures$textu = parsedTextures[textureType],
93001
- id = _parsedTextures$textu.id,
93002
- options = _parsedTextures$textu.options;
93003
- element.setTexture(id, textureType, options);
93004
- });
93782
+ if (elementData.textures) {
93783
+ var parsedTextures = JSON.parse(elementData.textures);
93784
+ element.setNormalScale();
93785
+ Object.keys(parsedTextures).forEach(function (textureType) {
93786
+ var _parsedTextures$textu = parsedTextures[textureType],
93787
+ id = _parsedTextures$textu.id,
93788
+ options = _parsedTextures$textu.options;
93789
+ element.setTexture(id, textureType, options);
93790
+ });
93791
+ } // setting shadow properties
93792
+
93793
+
93794
+ if (elementData.shadow) {
93795
+ var castShadow = elementData.shadow.cast;
93796
+ var receiveShadow = elementData.shadow.receive;
93797
+
93798
+ if (castShadow !== undefined) {
93799
+ element.getBody().castShadow = castShadow;
93800
+ }
93801
+
93802
+ if (receiveShadow !== undefined) {
93803
+ element.getBody().receiveShadow = receiveShadow;
93804
+ } // For models, also traverse children
93805
+
93806
+
93807
+ if (element.isModel()) {
93808
+ element.getBody().traverse(function (child) {
93809
+ if (castShadow !== undefined) {
93810
+ child.castShadow = castShadow;
93811
+ }
93812
+
93813
+ if (receiveShadow !== undefined) {
93814
+ child.receiveShadow = receiveShadow;
93815
+ }
93816
+ });
93817
+ }
93818
+ }
93005
93819
  }
93006
93820
  }, {
93007
93821
  key: "completeLightCreation",
@@ -93012,7 +93826,12 @@ var Importer = /*#__PURE__*/function () {
93012
93826
  })); // setting color and intensity
93013
93827
 
93014
93828
  light.setColor(lightData.color);
93015
- light.setIntensity(lightData.intensity); // setting light-specific properties
93829
+ light.setIntensity(lightData.intensity); // setting castShadow
93830
+
93831
+ if (lightData.castShadow !== undefined) {
93832
+ light.setCastShadow(lightData.castShadow);
93833
+ } // setting light-specific properties
93834
+
93016
93835
 
93017
93836
  if (lightData.distance !== undefined) {
93018
93837
  light.setDistance(lightData.distance);
@@ -93028,14 +93847,6 @@ var Importer = /*#__PURE__*/function () {
93028
93847
 
93029
93848
  if (lightData.penumbra !== undefined) {
93030
93849
  light.setPenumbra(lightData.penumbra);
93031
- } // setting ground color for hemisphere lights
93032
-
93033
-
93034
- if (lightData.ground !== undefined && lightData.sky !== undefined) {
93035
- light.setColor({
93036
- sky: lightData.sky,
93037
- ground: lightData.ground
93038
- });
93039
93850
  } // setting shadow properties
93040
93851
 
93041
93852
 
@@ -93145,6 +93956,22 @@ var Importer = /*#__PURE__*/function () {
93145
93956
  sprite.setDepthWrite(depthWrite);
93146
93957
  }
93147
93958
  }
93959
+ }, {
93960
+ key: "completeSoundCreation",
93961
+ value: function completeSoundCreation(sound, soundData, options) {
93962
+ Importer.completeCommonCreationSteps(sound, soundData, _objectSpread2$1(_objectSpread2$1({}, options), {}, {
93963
+ skipOpacity: true,
93964
+ skipScale: true
93965
+ })); // setting sound-specific properties
93966
+
93967
+ if (soundData.volume !== undefined) {
93968
+ sound.setVolume(soundData.volume);
93969
+ }
93970
+
93971
+ if (soundData.detune !== undefined) {
93972
+ sound.detune(soundData.detune);
93973
+ }
93974
+ }
93148
93975
  }, {
93149
93976
  key: "parseLevelData",
93150
93977
  value: function parseLevelData() {
@@ -93153,7 +93980,13 @@ var Importer = /*#__PURE__*/function () {
93153
93980
  var _data$elements = data.elements,
93154
93981
  elements = _data$elements === void 0 ? [] : _data$elements,
93155
93982
  _data$lights = data.lights,
93156
- lights = _data$lights === void 0 ? [] : _data$lights;
93983
+ lights = _data$lights === void 0 ? [] : _data$lights,
93984
+ _data$audio = data.audio,
93985
+ audio = _data$audio === void 0 ? [] : _data$audio,
93986
+ _data$sounds = data.sounds,
93987
+ sounds = _data$sounds === void 0 ? [] : _data$sounds; // Support both 'audio' and 'sounds' keys for backwards compatibility
93988
+
93989
+ var allSounds = [].concat(_toConsumableArray(audio), _toConsumableArray(sounds));
93157
93990
  elements.forEach(function (data) {
93158
93991
  try {
93159
93992
  if (data.entitySubType === ENTITY_TYPES.MODEL.TYPE) {
@@ -93260,6 +94093,30 @@ var Importer = /*#__PURE__*/function () {
93260
94093
  } catch (error) {
93261
94094
  console.error(IMPORTER_ERROR_LIGHT_CREATION, data.name, data.entitySubType, error.stack);
93262
94095
  }
94096
+ }); // processing sounds
94097
+
94098
+ allSounds.forEach(function (data) {
94099
+ try {
94100
+ switch (data.entitySubType) {
94101
+ case ENTITY_TYPES.AUDIO.SUBTYPES.DEFAULT:
94102
+ Importer.completeSoundCreation(Sound$1.create(data), data, options);
94103
+ break;
94104
+
94105
+ case ENTITY_TYPES.AUDIO.SUBTYPES.AMBIENT:
94106
+ Importer.completeSoundCreation(AmbientSound$1.create(data), data, options);
94107
+ break;
94108
+
94109
+ case ENTITY_TYPES.AUDIO.SUBTYPES.DIRECTIONAL:
94110
+ Importer.completeSoundCreation(DirectionalSound$1.create(data), data, options);
94111
+ break;
94112
+
94113
+ default:
94114
+ // Try to create as basic Sound if entitySubType not recognized
94115
+ Importer.completeSoundCreation(Sound$1.create(data), data, options);
94116
+ }
94117
+ } catch (error) {
94118
+ console.error(IMPORTER_ERROR_SOUND_CREATION, data.name, data.entitySubType, error.stack);
94119
+ }
93263
94120
  });
93264
94121
  }
93265
94122
  }]);
@@ -93895,407 +94752,7 @@ var Cone = /*#__PURE__*/function (_Element) {
93895
94752
  }]);
93896
94753
 
93897
94754
  return Cone;
93898
- }(Element$1);var DEFAULT_SETUP_CONFIG$1 = {
93899
- deferred: false
93900
- };
93901
-
93902
- var Sound$1 = /*#__PURE__*/function (_Entity) {
93903
- _inherits(Sound, _Entity);
93904
-
93905
- var _super = _createSuper(Sound);
93906
-
93907
- function Sound() {
93908
- var _this;
93909
-
93910
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
93911
-
93912
- _classCallCheck(this, Sound);
93913
-
93914
- var source = options.source,
93915
- _options$loop = options.loop,
93916
- loop = _options$loop === void 0 ? false : _options$loop,
93917
- loopStart = options.loopStart,
93918
- loopEnd = options.loopEnd,
93919
- autoplay = options.autoplay,
93920
- reconnectOnReset = options.reconnectOnReset,
93921
- _options$setupConfig = options.setupConfig,
93922
- setupConfig = _options$setupConfig === void 0 ? DEFAULT_SETUP_CONFIG$1 : _options$setupConfig,
93923
- _options$name = options.name,
93924
- name = _options$name === void 0 ? generateRandomName("sound") : _options$name;
93925
- _this = _super.call(this, _objectSpread2$1(_objectSpread2$1({}, options), {}, {
93926
- source: source,
93927
- loop: loop,
93928
- loopStart: loopStart,
93929
- loopEnd: loopEnd,
93930
- autoplay: autoplay,
93931
- reconnectOnReset: reconnectOnReset,
93932
- name: name
93933
- }));
93934
-
93935
- _defineProperty$1(_assertThisInitialized(_this), "reset", function () {
93936
- _this.playing = false;
93937
-
93938
- _this.disconnect();
93939
-
93940
- _this.setupAudio();
93941
-
93942
- _this.connect();
93943
- });
93944
-
93945
- _this.setupConfig = setupConfig;
93946
- _this.source = source;
93947
- _this.loop = loop;
93948
- _this.loopStart = loopStart;
93949
- _this.loopEnd = loopEnd;
93950
- _this.autoplay = autoplay;
93951
- _this.reconnectOnReset = reconnectOnReset;
93952
- _this.name = name;
93953
- _this.connected = false;
93954
- _this.playing = false;
93955
- _this.setupCompleted = false;
93956
- _this.hasPlayed = false;
93957
- _this.buffer = null;
93958
- _this.audioNode = null;
93959
- _this.volumeNode = null;
93960
- _this.detuneValue = 0;
93961
-
93962
- if (!_this.setupConfig.deferred) {
93963
- _this.setupAudio();
93964
- }
93965
-
93966
- _this.setName(name);
93967
-
93968
- _this.setBody({
93969
- body: new Object3D()
93970
- });
93971
-
93972
- _this.setEntityType(ENTITY_TYPES.AUDIO.DEFAULT);
93973
-
93974
- Scene$1.add(_this.getBody(), _assertThisInitialized(_this));
93975
- Audio$1.add(_assertThisInitialized(_this));
93976
-
93977
- if (_this.isSetupCompleted()) {
93978
- _this.connect();
93979
- }
93980
-
93981
- return _this;
93982
- }
93983
-
93984
- _createClass(Sound, [{
93985
- key: "addHelpers",
93986
- value: function addHelpers() {
93987
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
93988
- _ref$holderName = _ref.holderName,
93989
- holderName = _ref$holderName === void 0 ? "soundholder" : _ref$holderName,
93990
- _ref$holderSize = _ref.holderSize,
93991
- holderSize = _ref$holderSize === void 0 ? 0.05 : _ref$holderSize;
93992
-
93993
- var holderSprite = new HelperSprite(holderSize, holderSize, holderName, {
93994
- name: holderName
93995
- });
93996
-
93997
- if (holderSprite) {
93998
- holderSprite.setSizeAttenuation(false);
93999
- holderSprite.setDepthTest(false);
94000
- holderSprite.setDepthWrite(false);
94001
- holderSprite.setSerializable(false);
94002
- holderSprite.setPosition(this.getPosition());
94003
- holderSprite.addTags([TAGS.HELPER, TAGS.SOUNDS.HELPER, TAGS.SOUNDS.HOLDER, name]);
94004
- holderSprite.setHelperTarget(this);
94005
- this.holder = holderSprite;
94006
- return true;
94007
- } else {
94008
- console.warn(LIGHT_HOLDER_MODEL_NOT_FOUND);
94009
- return false;
94010
- }
94011
- }
94012
- }, {
94013
- key: "isPlaying",
94014
- value: function isPlaying() {
94015
- return this.playing;
94016
- }
94017
- }, {
94018
- key: "isSetupCompleted",
94019
- value: function isSetupCompleted() {
94020
- return this.setupCompleted;
94021
- }
94022
- }, {
94023
- key: "isConnected",
94024
- value: function isConnected() {
94025
- return this.connected;
94026
- }
94027
- }, {
94028
- key: "setupAudio",
94029
- value: function setupAudio() {
94030
- this.createAudioNode();
94031
- this.createVolumeNode();
94032
- this.setBuffer();
94033
- this.setupAudioNodeLoop();
94034
- this.audioNode.removeEventListener(ENTITY_EVENTS.AUDIO.ENDED, this.onSoundEnded.bind(this));
94035
- this.audioNode.addEventListener(ENTITY_EVENTS.AUDIO.ENDED, this.onSoundEnded.bind(this));
94036
- this.setupCompleted = true;
94037
- }
94038
- }, {
94039
- key: "setSource",
94040
- value: function setSource(source) {
94041
- this.source = source;
94042
- }
94043
- }, {
94044
- key: "getSource",
94045
- value: function getSource() {
94046
- return this.source;
94047
- }
94048
- }, {
94049
- key: "createAudioNode",
94050
- value: function createAudioNode() {
94051
- this.audioNode = Audio$1.context.createBufferSource();
94052
- }
94053
- }, {
94054
- key: "setupAudioNodeLoop",
94055
- value: function setupAudioNodeLoop() {
94056
- this.audioNode.loop = this.loop;
94057
- this.audioNode.loopEnd = this.loopEnd === undefined ? this.duration : this.loopEnd;
94058
- this.audioNode.loopStart = this.loopStart === undefined ? this.duration : this.loopStart;
94059
- }
94060
- }, {
94061
- key: "createVolumeNode",
94062
- value: function createVolumeNode() {
94063
- this.volumeNode = Audio$1.context.createGain();
94064
- this.volumeNode.gain.value = DEFAULT_AUDIO_NODE_VOLUME;
94065
- }
94066
- }, {
94067
- key: "tryAutoplay",
94068
- value: function tryAutoplay() {
94069
- if (this.autoplay && !this.hasPlayed && !this.setupConfig.deferred) {
94070
- this.play();
94071
- }
94072
- }
94073
- }, {
94074
- key: "connect",
94075
- value: function connect() {
94076
- if (this.isConnected()) {
94077
- this.disconnect();
94078
- }
94079
-
94080
- this.volumeNode.connect(Audio$1.getMasterVolumeNode());
94081
- this.audioNode.connect(this.volumeNode);
94082
- this.connected = true;
94083
- this.tryAutoplay();
94084
- }
94085
- }, {
94086
- key: "disconnect",
94087
- value: function disconnect() {
94088
- if (this.isConnected()) {
94089
- this.volumeNode.disconnect();
94090
- this.audioNode.disconnect();
94091
- this.connected = false;
94092
- }
94093
- }
94094
- }, {
94095
- key: "dispose",
94096
- value: function dispose() {
94097
- _get(_getPrototypeOf(Sound.prototype), "dispose", this).call(this);
94098
-
94099
- this.stop();
94100
- this.disconnect();
94101
- }
94102
- }, {
94103
- key: "getVolume",
94104
- value: function getVolume() {
94105
- return this.volumeNode ? this.volumeNode.gain.value : Audio$1.getVolume();
94106
- }
94107
- }, {
94108
- key: "setVolume",
94109
- value: function setVolume() {
94110
- var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_AUDIO_NODE_VOLUME;
94111
- this.volumeNode.gain.setValueAtTime(value, Audio$1.context.currentTime);
94112
- }
94113
- }, {
94114
- key: "hasBuffer",
94115
- value: function hasBuffer() {
94116
- return !!this.buffer;
94117
- }
94118
- }, {
94119
- key: "setBuffer",
94120
- value: function setBuffer() {
94121
- if (!this.getSource()) {
94122
- console.error(AUDIO_SOURCE_NOT_DEFINED);
94123
- return false;
94124
- }
94125
-
94126
- var buffer = Audio$1.get(this.source);
94127
-
94128
- if (!buffer) {
94129
- console.error(AUDIO_UNABLE_TO_LOAD_SOUND);
94130
- return false;
94131
- }
94132
-
94133
- this.buffer = buffer;
94134
- this.audioNode.buffer = buffer;
94135
- return true;
94136
- }
94137
- }, {
94138
- key: "play",
94139
- value: function play() {
94140
- var volume = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getVolume();
94141
- var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_AUDIO_NODE_RAMP_TIME;
94142
- var ramp = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : AUDIO_RAMPS.LINEAR;
94143
- if (this.isPlaying()) return this;
94144
- if (!this.isSetupCompleted()) this.setupAudio();
94145
- if (!this.isConnected()) this.connect();
94146
- this.setVolume(0);
94147
- this.audioNode.start();
94148
- this.hasPlayed = true;
94149
- this.playing = true;
94150
- var audioDelay = delay / 1000; // linearRampToValueAtTime/exponentialRampToValueAtTime requires time to be expressed in seconds
94151
-
94152
- if (ramp === AUDIO_RAMPS.LINEAR) {
94153
- this.volumeNode.gain.linearRampToValueAtTime(volume, Audio$1.context.currentTime + audioDelay);
94154
- } else {
94155
- this.volumeNode.gain.exponentialRampToValueAtTime(volume, Audio$1.context.currentTime + audioDelay);
94156
- }
94157
-
94158
- return this;
94159
- }
94160
- }, {
94161
- key: "onSoundEnded",
94162
- value: function onSoundEnded() {
94163
- this.reset();
94164
- this.dispatchEvent({
94165
- type: ENTITY_EVENTS.AUDIO.ENDED
94166
- });
94167
- }
94168
- }, {
94169
- key: "stop",
94170
- value: function stop() {
94171
- var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_AUDIO_NODE_RAMP_TIME;
94172
- var ramp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : AUDIO_RAMPS.LINEAR;
94173
- var audioDelay = delay / 1000; // linearRampToValueAtTime/exponentialRampToValueAtTime requires time to be expressed in seconds
94174
-
94175
- if (ramp === AUDIO_RAMPS.LINEAR) {
94176
- this.volumeNode.gain.linearRampToValueAtTime(ALMOST_ZERO, Audio$1.context.currentTime + audioDelay);
94177
- } else {
94178
- this.volumeNode.gain.exponentialRampToValueAtTime(ALMOST_ZERO, Audio$1.context.currentTime + audioDelay);
94179
- }
94180
-
94181
- setTimeout(this.reset, delay);
94182
- return this;
94183
- }
94184
- }, {
94185
- key: "detune",
94186
- value: function detune(value) {
94187
- if (this.audioNode) {
94188
- this.detuneValue = value;
94189
- this.audioNode.detune.value = this.detuneValue;
94190
- }
94191
- }
94192
- }, {
94193
- key: "getDetune",
94194
- value: function getDetune() {
94195
- return this.detuneValue;
94196
- }
94197
- }, {
94198
- key: "addEffect",
94199
- value: function addEffect(effect) {
94200
- if (!this.hasEffect() && effect) {
94201
- this.convolverNode = Audio$1.context.createConvolver();
94202
- this.mixerNode = Audio$1.createGain();
94203
-
94204
- if (this.hasPannerNode()) {
94205
- this.pannerNode.disconnect();
94206
- this.pannerNode.connect(this.mixerNode);
94207
- } else {
94208
- this.volumeNode.disconnect();
94209
- this.volumeNode.connect(this.mixerNode);
94210
- } //creating gains
94211
-
94212
-
94213
- this.plainGainNode = Audio$1.context.createGain();
94214
- this.convolverGainNode = Audio$1.context.createGain(); //connect mixer to new gains
94215
-
94216
- this.mixerNode.connect(this.plainGainNode);
94217
- this.mixerNode.connect(this.convolverGainNode);
94218
- this.plainGainNode.connect(Audio$1.getMasterVolumeNode());
94219
- this.convolverGainNode.connect(Audio$1.getMasterVolumeNode());
94220
- this.convolverNode.buffer = Audio$1.get(effect);
94221
- this.convolverGainNode.gain.setValueAtTime(0.7, Audio$1.context.currentTime);
94222
- this.plainGainNode.gain.setValueAtTime(0.3, Audio$1.context.currentTime);
94223
- }
94224
- }
94225
- }, {
94226
- key: "setPosition",
94227
- value: function setPosition(where) {
94228
- var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
94229
- _ref2$updateHolder = _ref2.updateHolder,
94230
- updateHolder = _ref2$updateHolder === void 0 ? true : _ref2$updateHolder;
94231
-
94232
- var position = _objectSpread2$1(_objectSpread2$1({}, this.getPosition()), where);
94233
-
94234
- var x = position.x,
94235
- y = position.y,
94236
- z = position.z;
94237
-
94238
- if (this.hasBody()) {
94239
- this.body.position.set(x, y, z);
94240
- }
94241
-
94242
- if (this.hasHolder() && updateHolder) {
94243
- this.holder.setPosition({
94244
- x: x,
94245
- y: y,
94246
- z: z
94247
- });
94248
- }
94249
- }
94250
- }, {
94251
- key: "usingHelper",
94252
- value: function usingHelper() {
94253
- return !!this.isUsingHelper;
94254
- }
94255
- }, {
94256
- key: "hasHolder",
94257
- value: function hasHolder() {
94258
- return !!this.holder;
94259
- }
94260
- }, {
94261
- key: "toJSON",
94262
- value: function toJSON() {
94263
- var parseJSON = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
94264
- return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(Sound.prototype), "toJSON", this).call(this, parseJSON)), {}, {
94265
- source: this.source,
94266
- loop: this.loop,
94267
- loopStart: this.loopStart,
94268
- loopEnd: this.loopEnd,
94269
- autoplay: this.autoplay,
94270
- volume: this.getVolume(),
94271
- detune: this.getDetune(),
94272
- hasPlayed: this.hasPlayed,
94273
- playing: this.isPlaying(),
94274
- connected: this.isConnected(),
94275
- duration: this.hasBuffer() ? this.duration : 0,
94276
- sampleRate: this.hasBuffer() ? this.sampleRate : 0,
94277
- numberOfChannels: this.hasBuffer() ? this.numberOfChannels : 0
94278
- });
94279
- }
94280
- }, {
94281
- key: "sampleRate",
94282
- get: function get() {
94283
- return this.buffer.sampleRate;
94284
- }
94285
- }, {
94286
- key: "duration",
94287
- get: function get() {
94288
- return this.buffer.duration * 1000;
94289
- }
94290
- }, {
94291
- key: "numberOfChannels",
94292
- get: function get() {
94293
- return this.buffer.numberOfChannels;
94294
- }
94295
- }]);
94296
-
94297
- return Sound;
94298
- }(Entity);var _excluded$2 = ["name"];
94755
+ }(Element$1);var _excluded$2 = ["name"];
94299
94756
 
94300
94757
  var AmbientSound = /*#__PURE__*/function (_Sound) {
94301
94758
  _inherits(AmbientSound, _Sound);
@@ -94317,11 +94774,37 @@ var AmbientSound = /*#__PURE__*/function (_Sound) {
94317
94774
  name: name
94318
94775
  }, options));
94319
94776
 
94320
- _this.setEntityType(ENTITY_TYPES.AUDIO.AMBIENT);
94777
+ _this.setEntityType(ENTITY_TYPES.AUDIO.TYPE);
94778
+
94779
+ _this.setEntitySubtype(ENTITY_TYPES.AUDIO.SUBTYPES.AMBIENT);
94321
94780
 
94322
94781
  return _this;
94323
94782
  }
94324
94783
 
94784
+ _createClass(AmbientSound, null, [{
94785
+ key: "create",
94786
+ value: function create() {
94787
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
94788
+ var source = data.source,
94789
+ loop = data.loop,
94790
+ loopStart = data.loopStart,
94791
+ loopEnd = data.loopEnd,
94792
+ autoplay = data.autoplay,
94793
+ reconnectOnReset = data.reconnectOnReset,
94794
+ name = data.name,
94795
+ _data$options = data.options,
94796
+ options = _data$options === void 0 ? {} : _data$options;
94797
+ return new AmbientSound(source, _objectSpread2$1({
94798
+ loop: loop,
94799
+ loopStart: loopStart,
94800
+ loopEnd: loopEnd,
94801
+ autoplay: autoplay,
94802
+ reconnectOnReset: reconnectOnReset,
94803
+ name: name
94804
+ }, options));
94805
+ }
94806
+ }]);
94807
+
94325
94808
  return AmbientSound;
94326
94809
  }(Sound$1);var _excluded$1 = ["name"];
94327
94810
 
@@ -94345,7 +94828,9 @@ var DirectionalSound = /*#__PURE__*/function (_Sound) {
94345
94828
  name: name
94346
94829
  }, options));
94347
94830
 
94348
- _this.setEntityType(ENTITY_TYPES.AUDIO.DIRECTIONAL);
94831
+ _this.setEntityType(ENTITY_TYPES.AUDIO.TYPE);
94832
+
94833
+ _this.setEntitySubtype(ENTITY_TYPES.AUDIO.SUBTYPES.DIRECTIONAL);
94349
94834
 
94350
94835
  return _this;
94351
94836
  }
@@ -94449,6 +94934,28 @@ var DirectionalSound = /*#__PURE__*/function (_Sound) {
94449
94934
  this.updatePannerPosition();
94450
94935
  }
94451
94936
  }
94937
+ }], [{
94938
+ key: "create",
94939
+ value: function create() {
94940
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
94941
+ var source = data.source,
94942
+ loop = data.loop,
94943
+ loopStart = data.loopStart,
94944
+ loopEnd = data.loopEnd,
94945
+ autoplay = data.autoplay,
94946
+ reconnectOnReset = data.reconnectOnReset,
94947
+ name = data.name,
94948
+ _data$options = data.options,
94949
+ options = _data$options === void 0 ? {} : _data$options;
94950
+ return new DirectionalSound(source, _objectSpread2$1({
94951
+ loop: loop,
94952
+ loopStart: loopStart,
94953
+ loopEnd: loopEnd,
94954
+ autoplay: autoplay,
94955
+ reconnectOnReset: reconnectOnReset,
94956
+ name: name
94957
+ }, options));
94958
+ }
94452
94959
  }]);
94453
94960
 
94454
94961
  return DirectionalSound;
@@ -94526,7 +95033,9 @@ var Sound = /*#__PURE__*/function (_Entity) {
94526
95033
  body: new Object3D()
94527
95034
  });
94528
95035
 
94529
- _this.setEntityType(ENTITY_TYPES.AUDIO.DEFAULT);
95036
+ _this.setEntityType(ENTITY_TYPES.AUDIO.TYPE);
95037
+
95038
+ _this.setEntitySubtype(ENTITY_TYPES.AUDIO.SUBTYPES.DEFAULT);
94530
95039
 
94531
95040
  Scene$1.add(_this.getBody(), _assertThisInitialized(_this));
94532
95041
  Audio$1.add(_assertThisInitialized(_this));
@@ -94557,12 +95066,12 @@ var Sound = /*#__PURE__*/function (_Entity) {
94557
95066
  holderSprite.setDepthWrite(false);
94558
95067
  holderSprite.setSerializable(false);
94559
95068
  holderSprite.setPosition(this.getPosition());
94560
- holderSprite.addTags([TAGS.HELPER, TAGS.SOUNDS.HELPER, TAGS.SOUNDS.HOLDER, name]);
95069
+ holderSprite.addTags([TAGS.HELPER, TAGS.SOUNDS.HELPER, TAGS.SOUNDS.HOLDER, holderName]);
94561
95070
  holderSprite.setHelperTarget(this);
94562
95071
  this.holder = holderSprite;
94563
95072
  return true;
94564
95073
  } else {
94565
- console.warn(LIGHT_HOLDER_MODEL_NOT_FOUND);
95074
+ console.warn(SOUND_HOLDER_MODEL_NOT_FOUND);
94566
95075
  return false;
94567
95076
  }
94568
95077
  }
@@ -94824,6 +95333,7 @@ var Sound = /*#__PURE__*/function (_Entity) {
94824
95333
  loopStart: this.loopStart,
94825
95334
  loopEnd: this.loopEnd,
94826
95335
  autoplay: this.autoplay,
95336
+ reconnectOnReset: this.reconnectOnReset,
94827
95337
  volume: this.getVolume(),
94828
95338
  detune: this.getDetune(),
94829
95339
  hasPlayed: this.hasPlayed,
@@ -94849,6 +95359,27 @@ var Sound = /*#__PURE__*/function (_Entity) {
94849
95359
  get: function get() {
94850
95360
  return this.buffer.numberOfChannels;
94851
95361
  }
95362
+ }], [{
95363
+ key: "create",
95364
+ value: function create() {
95365
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
95366
+ var source = data.source,
95367
+ loop = data.loop,
95368
+ loopStart = data.loopStart,
95369
+ loopEnd = data.loopEnd,
95370
+ autoplay = data.autoplay,
95371
+ reconnectOnReset = data.reconnectOnReset,
95372
+ _data$options = data.options,
95373
+ options = _data$options === void 0 ? {} : _data$options;
95374
+ return new Sound(_objectSpread2$1({
95375
+ source: source,
95376
+ loop: loop,
95377
+ loopStart: loopStart,
95378
+ loopEnd: loopEnd,
95379
+ autoplay: autoplay,
95380
+ reconnectOnReset: reconnectOnReset
95381
+ }, options));
95382
+ }
94852
95383
  }]);
94853
95384
 
94854
95385
  return Sound;
@@ -95119,7 +95650,16 @@ var AmbientLight = /*#__PURE__*/function (_Light) {
95119
95650
  key: "create",
95120
95651
  value: function create() {
95121
95652
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
95122
- return new AmbientLight(data.options);
95653
+ var color = data.color,
95654
+ intensity = data.intensity,
95655
+ name = data.name,
95656
+ position = data.position;
95657
+ return new AmbientLight({
95658
+ color: color,
95659
+ intensity: intensity,
95660
+ name: name,
95661
+ position: position
95662
+ });
95123
95663
  }
95124
95664
  }]);
95125
95665
 
@@ -95367,7 +95907,30 @@ var SunLight = /*#__PURE__*/function (_Light) {
95367
95907
  key: "create",
95368
95908
  value: function create() {
95369
95909
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
95370
- return new SunLight(data.options);
95910
+ var color = data.color,
95911
+ intensity = data.intensity,
95912
+ name = data.name,
95913
+ position = data.position,
95914
+ bias = data.bias,
95915
+ mapSize = data.mapSize,
95916
+ shadowCamera = data.shadowCamera;
95917
+
95918
+ var _ref3 = shadowCamera || {},
95919
+ near = _ref3.near,
95920
+ far = _ref3.far,
95921
+ fov = _ref3.fov;
95922
+
95923
+ return new SunLight({
95924
+ color: color,
95925
+ intensity: intensity,
95926
+ name: name,
95927
+ position: position,
95928
+ near: near,
95929
+ far: far,
95930
+ mapSize: mapSize,
95931
+ bias: bias,
95932
+ fov: fov
95933
+ });
95371
95934
  }
95372
95935
  }]);
95373
95936
 
@@ -95602,6 +96165,37 @@ var PointLight = /*#__PURE__*/function (_Light) {
95602
96165
  shadowCamera: this.getShadowCameraNearFar()
95603
96166
  });
95604
96167
  }
96168
+ }], [{
96169
+ key: "create",
96170
+ value: function create() {
96171
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
96172
+ var color = data.color,
96173
+ intensity = data.intensity,
96174
+ name = data.name,
96175
+ position = data.position,
96176
+ distance = data.distance,
96177
+ decay = data.decay,
96178
+ bias = data.bias,
96179
+ mapSize = data.mapSize,
96180
+ shadowCamera = data.shadowCamera;
96181
+
96182
+ var _ref3 = shadowCamera || {},
96183
+ near = _ref3.near,
96184
+ far = _ref3.far;
96185
+
96186
+ return new PointLight({
96187
+ color: color,
96188
+ intensity: intensity,
96189
+ name: name,
96190
+ position: position,
96191
+ distance: distance,
96192
+ decay: decay,
96193
+ near: near,
96194
+ far: far,
96195
+ mapSize: mapSize,
96196
+ bias: bias
96197
+ });
96198
+ }
95605
96199
  }]);
95606
96200
 
95607
96201
  return PointLight;
@@ -95906,6 +96500,41 @@ var SpotLight = /*#__PURE__*/function (_Light) {
95906
96500
  angle: this.getAngle()
95907
96501
  });
95908
96502
  }
96503
+ }], [{
96504
+ key: "create",
96505
+ value: function create() {
96506
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
96507
+ var color = data.color,
96508
+ intensity = data.intensity,
96509
+ name = data.name,
96510
+ position = data.position,
96511
+ distance = data.distance,
96512
+ angle = data.angle,
96513
+ penumbra = data.penumbra,
96514
+ decay = data.decay,
96515
+ bias = data.bias,
96516
+ mapSize = data.mapSize,
96517
+ shadowCamera = data.shadowCamera;
96518
+
96519
+ var _ref3 = shadowCamera || {},
96520
+ near = _ref3.near,
96521
+ far = _ref3.far;
96522
+
96523
+ return new SpotLight({
96524
+ color: color,
96525
+ intensity: intensity,
96526
+ name: name,
96527
+ position: position,
96528
+ distance: distance,
96529
+ angle: angle,
96530
+ penumbra: penumbra,
96531
+ decay: decay,
96532
+ near: near,
96533
+ far: far,
96534
+ mapSize: mapSize,
96535
+ bias: bias
96536
+ });
96537
+ }
95909
96538
  }]);
95910
96539
 
95911
96540
  return SpotLight;
@@ -95946,9 +96575,20 @@ var HemisphereLight = /*#__PURE__*/function (_Light) {
95946
96575
  sky = _ref.sky,
95947
96576
  ground = _ref.ground;
95948
96577
 
95949
- if (sky && ground) {
95950
- _this.getBody().color = sky;
95951
- _this.getBody().groundColor = ground;
96578
+ if (sky !== undefined) {
96579
+ if (_typeof(sky) === 'object' && 'r' in sky && 'g' in sky && 'b' in sky) {
96580
+ _this.getBody().color.setRGB(sky.r, sky.g, sky.b);
96581
+ } else {
96582
+ _this.getBody().color.set(sky);
96583
+ }
96584
+ }
96585
+
96586
+ if (ground !== undefined) {
96587
+ if (_typeof(ground) === 'object' && 'r' in ground && 'g' in ground && 'b' in ground) {
96588
+ _this.getBody().groundColor.setRGB(ground.r, ground.g, ground.b);
96589
+ } else {
96590
+ _this.getBody().groundColor.set(ground);
96591
+ }
95952
96592
  }
95953
96593
  });
95954
96594
 
@@ -96042,6 +96682,21 @@ var HemisphereLight = /*#__PURE__*/function (_Light) {
96042
96682
  } : color
96043
96683
  });
96044
96684
  }
96685
+ }], [{
96686
+ key: "create",
96687
+ value: function create() {
96688
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
96689
+ var color = data.color,
96690
+ intensity = data.intensity,
96691
+ name = data.name,
96692
+ position = data.position;
96693
+ return new HemisphereLight({
96694
+ color: color,
96695
+ intensity: intensity,
96696
+ name: name,
96697
+ position: position
96698
+ });
96699
+ }
96045
96700
  }]);
96046
96701
 
96047
96702
  return HemisphereLight;