mage-engine 3.22.4 → 3.22.6
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.
- package/.vscode/settings.json +1 -0
- package/dist/mage.js +580 -56
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/dist/mage.js
CHANGED
|
@@ -53962,11 +53962,13 @@ var KEYBOARD_COMBO_ALREADY_REGISTERED = "".concat(PREFIX, " Keyboard combo alrea
|
|
|
53962
53962
|
var PHYSICS_ELEMENT_CANT_BE_REMOVED = "".concat(PREFIX, " This element can't be removed from physics world.");
|
|
53963
53963
|
var PHYSICS_ELEMENT_ALREADY_STORED = "".concat(PREFIX, " This element has already been added to the world.");
|
|
53964
53964
|
var ASSETS_AUDIO_LOAD_FAIL = "".concat(PREFIX, " Could not load audio.");
|
|
53965
|
+
var ASSETS_AUDIO_FILE_LOAD_FAIL = "".concat(PREFIX, " Could not load desired audio file.");
|
|
53965
53966
|
var ASSETS_MODEL_LOAD_FAIL = "".concat(PREFIX, " Could not load model.");
|
|
53966
53967
|
var AUDIO_CONTEXT_NOT_AVAILABLE = "".concat(PREFIX, " No Audio Context available, sorry.");
|
|
53967
53968
|
var AUDIO_UNABLE_TO_LOAD_SOUND = "".concat(PREFIX, " Unable to load sound, sorry.");
|
|
53969
|
+
var AUDIO_SOURCE_NOT_DEFINED = "".concat(PREFIX, " No audio source defined. Set a source for this sound.");
|
|
53968
53970
|
var LIGHT_NOT_FOUND = "".concat(PREFIX, " This light was not created properly.");
|
|
53969
|
-
var LIGHT_HOLDER_MODEL_NOT_FOUND = "".concat(PREFIX, " This light holder model can't be found.");
|
|
53971
|
+
var LIGHT_HOLDER_MODEL_NOT_FOUND$1 = "".concat(PREFIX, " This light holder model can't be found.");
|
|
53970
53972
|
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?");var BaseScript = /*#__PURE__*/function () {
|
|
53971
53973
|
_createClass(BaseScript, [{
|
|
53972
53974
|
key: "__check",
|
|
@@ -55223,6 +55225,9 @@ var TAGS = {
|
|
|
55223
55225
|
HOLDER: "TAGS.LIGHTS.HOLDER",
|
|
55224
55226
|
HELPER: "TAGS.LIGHTS.HELPER",
|
|
55225
55227
|
TARGET: "TAGS.LIGHTS.TARGET"
|
|
55228
|
+
},
|
|
55229
|
+
SOUNDS: {
|
|
55230
|
+
HOLDER: "TAGS.SOUNDS.HOLDER"
|
|
55226
55231
|
}
|
|
55227
55232
|
};var lib_constants=/*#__PURE__*/Object.freeze({__proto__:null,ALMOST_ZERO:ALMOST_ZERO,UP:UP$1,DOWN:DOWN$1,LEFT:LEFT,RIGHT:RIGHT,FRONT:FRONT,BACK:BACK,VECTOR_UP:VECTOR_UP,VECTOR_DOWN:VECTOR_DOWN,VECTOR_LEFT:VECTOR_LEFT,VECTOR_RIGHT:VECTOR_RIGHT,VECTOR_FRONT:VECTOR_FRONT,VECTOR_BACK:VECTOR_BACK,ORIGIN:ORIGIN,ZERO_QUATERNION:ZERO_QUATERNION,MATERIALS:MATERIALS,TEXTURES:TEXTURES,EFFECTS:EFFECTS,COLLISION_EVENT:COLLISION_EVENT,COLORS:COLORS,ASSETS_TYPES:ASSETS_TYPES,OUTPUT_ENCODINGS:OUTPUT_ENCODINGS,DEFAULT_OUTPUT_ENCODING:DEFAULT_OUTPUT_ENCODING,ROOT:ROOT,DIVIDER:DIVIDER,HASH:HASH,EMPTY:EMPTY$2,QUERY_START:QUERY_START,DEFAULT_SELECTOR:DEFAULT_SELECTOR,BEFORE_UNLOAD:BEFORE_UNLOAD,HASH_CHANGE:HASH_CHANGE,TAGS:TAGS});var buildAssetId = function buildAssetId(name, level) {
|
|
55228
55233
|
return level ? "".concat(level, "_").concat(name) : name;
|
|
@@ -57762,8 +57767,8 @@ function applyMiddleware() {
|
|
|
57762
57767
|
}
|
|
57763
57768
|
|
|
57764
57769
|
var thunk = createThunkMiddleware();
|
|
57765
|
-
thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
|
|
57766
|
-
var version$1 = "3.22.
|
|
57770
|
+
thunk.withExtraArgument = createThunkMiddleware;var name$1 = "mage-engine";
|
|
57771
|
+
var version$1 = "3.22.6";
|
|
57767
57772
|
var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
|
|
57768
57773
|
var main = "dist/mage.js";
|
|
57769
57774
|
var author$1 = {
|
|
@@ -57846,7 +57851,7 @@ var devDependencies = {
|
|
|
57846
57851
|
"rollup-plugin-web-worker-loader": "1.6.1"
|
|
57847
57852
|
};
|
|
57848
57853
|
var packageJSON = {
|
|
57849
|
-
name: name,
|
|
57854
|
+
name: name$1,
|
|
57850
57855
|
version: version$1,
|
|
57851
57856
|
description: description,
|
|
57852
57857
|
main: main,
|
|
@@ -68761,8 +68766,8 @@ var DEFAULT_AUDIO_NODE_VOLUME = 5;
|
|
|
68761
68766
|
var DEFAULT_AUDIO_NODE_RAMP_TIME = 100; // value in ms
|
|
68762
68767
|
|
|
68763
68768
|
var AUDIO_RAMPS = {
|
|
68764
|
-
LINEAR:
|
|
68765
|
-
EXPONENTIAL:
|
|
68769
|
+
LINEAR: "LINEAR",
|
|
68770
|
+
EXPONENTIAL: "EXPONENTIAL"
|
|
68766
68771
|
};
|
|
68767
68772
|
var Audio = /*#__PURE__*/function () {
|
|
68768
68773
|
function Audio() {
|
|
@@ -68775,29 +68780,33 @@ var Audio = /*#__PURE__*/function () {
|
|
|
68775
68780
|
});
|
|
68776
68781
|
|
|
68777
68782
|
_defineProperty$1(this, "load", function () {
|
|
68778
|
-
var
|
|
68783
|
+
var audioAssets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
68779
68784
|
var level = arguments.length > 1 ? arguments[1] : undefined;
|
|
68780
|
-
_this.
|
|
68785
|
+
_this.audioAssets = audioAssets;
|
|
68781
68786
|
|
|
68782
68787
|
_this.createAudioContext();
|
|
68783
68788
|
|
|
68784
|
-
if (Object.keys(_this.
|
|
68789
|
+
if (Object.keys(_this.audioAssets).length === 0) {
|
|
68785
68790
|
return Promise.resolve();
|
|
68786
68791
|
}
|
|
68787
68792
|
|
|
68788
|
-
return Promise.all(Object.keys(_this.
|
|
68789
|
-
return _this.
|
|
68793
|
+
return Promise.all(Object.keys(_this.audioAssets).map(function (id) {
|
|
68794
|
+
return _this.loadAssetByName(id, level);
|
|
68790
68795
|
})).catch(function (e) {
|
|
68791
|
-
console.
|
|
68796
|
+
console.error(ASSETS_AUDIO_LOAD_FAIL);
|
|
68792
68797
|
console.log(e);
|
|
68793
68798
|
return Promise.resolve();
|
|
68794
68799
|
});
|
|
68795
68800
|
});
|
|
68796
68801
|
|
|
68797
|
-
_defineProperty$1(this, "
|
|
68798
|
-
var path = _this.
|
|
68799
|
-
var request = new XMLHttpRequest();
|
|
68802
|
+
_defineProperty$1(this, "loadAssetByName", function (name, level) {
|
|
68803
|
+
var path = _this.audioAssets[name];
|
|
68800
68804
|
var id = buildAssetId(name, level);
|
|
68805
|
+
return _this.loadAsset(path, id);
|
|
68806
|
+
});
|
|
68807
|
+
|
|
68808
|
+
_defineProperty$1(this, "loadAsset", function (path, id) {
|
|
68809
|
+
var request = new XMLHttpRequest();
|
|
68801
68810
|
return new Promise(function (resolve) {
|
|
68802
68811
|
request.open("GET", path, true);
|
|
68803
68812
|
request.responseType = "arraybuffer";
|
|
@@ -68805,10 +68814,11 @@ var Audio = /*#__PURE__*/function () {
|
|
|
68805
68814
|
request.onreadystatechange = function (e) {
|
|
68806
68815
|
if (request.readyState === 4 && request.status === 200) {
|
|
68807
68816
|
_this.context.decodeAudioData(request.response, function (buffer) {
|
|
68808
|
-
_this.
|
|
68817
|
+
_this.buffersMap[id] = buffer;
|
|
68809
68818
|
resolve();
|
|
68810
68819
|
}, function () {
|
|
68811
|
-
_this.
|
|
68820
|
+
_this.buffersMap[id] = null;
|
|
68821
|
+
console.error(ASSETS_AUDIO_FILE_LOAD_FAIL);
|
|
68812
68822
|
resolve();
|
|
68813
68823
|
});
|
|
68814
68824
|
}
|
|
@@ -68820,15 +68830,16 @@ var Audio = /*#__PURE__*/function () {
|
|
|
68820
68830
|
|
|
68821
68831
|
this.masterVolumeNode = null;
|
|
68822
68832
|
this.context = null;
|
|
68823
|
-
this.
|
|
68824
|
-
this.
|
|
68833
|
+
this.levelSounds = [];
|
|
68834
|
+
this.buffersMap = {};
|
|
68835
|
+
this.audioAssets = {};
|
|
68825
68836
|
this.currentLevel = ROOT;
|
|
68826
68837
|
}
|
|
68827
68838
|
|
|
68828
68839
|
_createClass(Audio, [{
|
|
68829
68840
|
key: "reset",
|
|
68830
68841
|
value: function reset() {
|
|
68831
|
-
this.
|
|
68842
|
+
this.levelSounds = [];
|
|
68832
68843
|
}
|
|
68833
68844
|
}, {
|
|
68834
68845
|
key: "hasContext",
|
|
@@ -68838,7 +68849,7 @@ var Audio = /*#__PURE__*/function () {
|
|
|
68838
68849
|
}, {
|
|
68839
68850
|
key: "hasSounds",
|
|
68840
68851
|
value: function hasSounds() {
|
|
68841
|
-
return this.
|
|
68852
|
+
return this.levelSounds.length > 0;
|
|
68842
68853
|
}
|
|
68843
68854
|
}, {
|
|
68844
68855
|
key: "createAudioContext",
|
|
@@ -68892,12 +68903,12 @@ var Audio = /*#__PURE__*/function () {
|
|
|
68892
68903
|
}, {
|
|
68893
68904
|
key: "get",
|
|
68894
68905
|
value: function get(id) {
|
|
68895
|
-
return this.
|
|
68906
|
+
return this.buffersMap[id] || this.buffersMap[buildAssetId(id, this.currentLevel)] || false;
|
|
68896
68907
|
}
|
|
68897
68908
|
}, {
|
|
68898
68909
|
key: "add",
|
|
68899
68910
|
value: function add(sound) {
|
|
68900
|
-
this.
|
|
68911
|
+
this.levelSounds.push(sound);
|
|
68901
68912
|
}
|
|
68902
68913
|
}, {
|
|
68903
68914
|
key: "updateListenerPosition",
|
|
@@ -68936,8 +68947,8 @@ var Audio = /*#__PURE__*/function () {
|
|
|
68936
68947
|
}, {
|
|
68937
68948
|
key: "dispose",
|
|
68938
68949
|
value: function dispose() {
|
|
68939
|
-
for (var index in this.
|
|
68940
|
-
var sound = this.
|
|
68950
|
+
for (var index in this.levelSounds) {
|
|
68951
|
+
var sound = this.levelSounds[index];
|
|
68941
68952
|
sound.dispose();
|
|
68942
68953
|
}
|
|
68943
68954
|
|
|
@@ -68955,8 +68966,8 @@ var Audio = /*#__PURE__*/function () {
|
|
|
68955
68966
|
|
|
68956
68967
|
var start = new Date();
|
|
68957
68968
|
|
|
68958
|
-
for (var index in this.
|
|
68959
|
-
var sound = this.
|
|
68969
|
+
for (var index in this.levelSounds) {
|
|
68970
|
+
var sound = this.levelSounds[index];
|
|
68960
68971
|
sound.update(dt);
|
|
68961
68972
|
if (+new Date() - start > TIME_FOR_UPDATE) break;
|
|
68962
68973
|
}
|
|
@@ -82981,7 +82992,7 @@ var MeshLoader$1 = new MeshLoader();var Light = /*#__PURE__*/function (_Entity)
|
|
|
82981
82992
|
_this.holder = holderSprite;
|
|
82982
82993
|
return true;
|
|
82983
82994
|
} else {
|
|
82984
|
-
console.warn(LIGHT_HOLDER_MODEL_NOT_FOUND);
|
|
82995
|
+
console.warn(LIGHT_HOLDER_MODEL_NOT_FOUND$1);
|
|
82985
82996
|
return false;
|
|
82986
82997
|
}
|
|
82987
82998
|
});
|
|
@@ -83072,7 +83083,7 @@ var MeshLoader$1 = new MeshLoader();var Light = /*#__PURE__*/function (_Entity)
|
|
|
83072
83083
|
this.body.position.set(x, y, z);
|
|
83073
83084
|
}
|
|
83074
83085
|
|
|
83075
|
-
if (this.hasHolder()
|
|
83086
|
+
if (this.hasHolder() && updateHolder) {
|
|
83076
83087
|
this.holder.setPosition({
|
|
83077
83088
|
x: x,
|
|
83078
83089
|
y: y,
|
|
@@ -83416,15 +83427,11 @@ var SunLight = /*#__PURE__*/function (_Light) {
|
|
|
83416
83427
|
value: function toJSON() {
|
|
83417
83428
|
return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(SunLight.prototype), "toJSON", this).call(this)), {}, {
|
|
83418
83429
|
target: this.getTarget(),
|
|
83419
|
-
distance: this.getDistance(),
|
|
83420
|
-
decay: this.getDecay(),
|
|
83421
83430
|
bias: this.getBias(),
|
|
83422
83431
|
mapSize: this.getMapSize(),
|
|
83423
83432
|
shadowCamera: _objectSpread2$1(_objectSpread2$1({}, this.getShadowCameraNearFar()), {}, {
|
|
83424
83433
|
fov: this.setShadowCameraFov()
|
|
83425
|
-
})
|
|
83426
|
-
penumbra: this.getPenumbra(),
|
|
83427
|
-
angle: this.getAngle()
|
|
83434
|
+
})
|
|
83428
83435
|
});
|
|
83429
83436
|
}
|
|
83430
83437
|
}]);
|
|
@@ -91044,7 +91051,11 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91044
91051
|
}
|
|
91045
91052
|
|
|
91046
91053
|
return Cone;
|
|
91047
|
-
}(Element$1);var
|
|
91054
|
+
}(Element$1);var DEFAULT_SETUP_CONFIG$1 = {
|
|
91055
|
+
deferred: false
|
|
91056
|
+
};
|
|
91057
|
+
|
|
91058
|
+
var Sound$1 = /*#__PURE__*/function (_Entity) {
|
|
91048
91059
|
_inherits(Sound, _Entity);
|
|
91049
91060
|
|
|
91050
91061
|
var _super = _createSuper(Sound);
|
|
@@ -91063,8 +91074,10 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91063
91074
|
loopEnd = options.loopEnd,
|
|
91064
91075
|
autoplay = options.autoplay,
|
|
91065
91076
|
reconnectOnReset = options.reconnectOnReset,
|
|
91077
|
+
_options$setupConfig = options.setupConfig,
|
|
91078
|
+
setupConfig = _options$setupConfig === void 0 ? DEFAULT_SETUP_CONFIG$1 : _options$setupConfig,
|
|
91066
91079
|
_options$name = options.name,
|
|
91067
|
-
name = _options$name === void 0 ? generateRandomName(
|
|
91080
|
+
name = _options$name === void 0 ? generateRandomName("sound") : _options$name;
|
|
91068
91081
|
_this = _super.call(this, _objectSpread2$1(_objectSpread2$1({}, options), {}, {
|
|
91069
91082
|
source: source,
|
|
91070
91083
|
loop: loop,
|
|
@@ -91085,6 +91098,7 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91085
91098
|
_this.connect();
|
|
91086
91099
|
});
|
|
91087
91100
|
|
|
91101
|
+
_this.setupConfig = setupConfig;
|
|
91088
91102
|
_this.source = source;
|
|
91089
91103
|
_this.loop = loop;
|
|
91090
91104
|
_this.loopStart = loopStart;
|
|
@@ -91094,12 +91108,15 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91094
91108
|
_this.name = name;
|
|
91095
91109
|
_this.connected = false;
|
|
91096
91110
|
_this.playing = false;
|
|
91111
|
+
_this.setupCompleted = false;
|
|
91097
91112
|
_this.hasPlayed = false;
|
|
91098
91113
|
_this.buffer = null;
|
|
91099
91114
|
_this.audioNode = null;
|
|
91100
91115
|
_this.volumeNode = null;
|
|
91101
91116
|
|
|
91102
|
-
_this.
|
|
91117
|
+
if (!_this.setupConfig.deferred) {
|
|
91118
|
+
_this.setupAudio();
|
|
91119
|
+
}
|
|
91103
91120
|
|
|
91104
91121
|
_this.setName(name);
|
|
91105
91122
|
|
|
@@ -91110,10 +91127,58 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91110
91127
|
_this.setEntityType(ENTITY_TYPES.AUDIO.DEFAULT);
|
|
91111
91128
|
|
|
91112
91129
|
Audio$1.add(_assertThisInitialized(_this));
|
|
91130
|
+
|
|
91131
|
+
if (_this.isSetupCompleted()) {
|
|
91132
|
+
_this.connect();
|
|
91133
|
+
}
|
|
91134
|
+
|
|
91113
91135
|
return _this;
|
|
91114
91136
|
}
|
|
91115
91137
|
|
|
91116
91138
|
_createClass(Sound, [{
|
|
91139
|
+
key: "addHelpers",
|
|
91140
|
+
value: function addHelpers() {
|
|
91141
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
91142
|
+
_ref$holderName = _ref.holderName,
|
|
91143
|
+
holderName = _ref$holderName === void 0 ? "soundholder" : _ref$holderName,
|
|
91144
|
+
_ref$holderSize = _ref.holderSize,
|
|
91145
|
+
holderSize = _ref$holderSize === void 0 ? 0.05 : _ref$holderSize;
|
|
91146
|
+
|
|
91147
|
+
var holderSprite = new HelperSprite(holderSize, holderSize, holderName, {
|
|
91148
|
+
name: holderName
|
|
91149
|
+
});
|
|
91150
|
+
|
|
91151
|
+
if (holderSprite) {
|
|
91152
|
+
holderSprite.setSizeAttenuation(false);
|
|
91153
|
+
holderSprite.setDepthTest(false);
|
|
91154
|
+
holderSprite.setDepthWrite(false);
|
|
91155
|
+
holderSprite.setSerializable(false);
|
|
91156
|
+
holderSprite.setPosition(this.getPosition());
|
|
91157
|
+
holderSprite.addTags([TAGS.LIGHTS.HELPER, TAGS.LIGHTS.HOLDER, name]);
|
|
91158
|
+
holderSprite.setHelperTarget(this);
|
|
91159
|
+
this.holder = holderSprite;
|
|
91160
|
+
return true;
|
|
91161
|
+
} else {
|
|
91162
|
+
console.warn(LIGHT_HOLDER_MODEL_NOT_FOUND);
|
|
91163
|
+
return false;
|
|
91164
|
+
}
|
|
91165
|
+
}
|
|
91166
|
+
}, {
|
|
91167
|
+
key: "isPlaying",
|
|
91168
|
+
value: function isPlaying() {
|
|
91169
|
+
return this.playing;
|
|
91170
|
+
}
|
|
91171
|
+
}, {
|
|
91172
|
+
key: "isSetupCompleted",
|
|
91173
|
+
value: function isSetupCompleted() {
|
|
91174
|
+
return this.setupCompleted;
|
|
91175
|
+
}
|
|
91176
|
+
}, {
|
|
91177
|
+
key: "isConnected",
|
|
91178
|
+
value: function isConnected() {
|
|
91179
|
+
return this.connected;
|
|
91180
|
+
}
|
|
91181
|
+
}, {
|
|
91117
91182
|
key: "setupAudio",
|
|
91118
91183
|
value: function setupAudio() {
|
|
91119
91184
|
this.createAudioNode();
|
|
@@ -91122,6 +91187,17 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91122
91187
|
this.setupAudioNodeLoop();
|
|
91123
91188
|
this.audioNode.removeEventListener(ENTITY_EVENTS.AUDIO.ENDED, this.onSoundEnded.bind(this));
|
|
91124
91189
|
this.audioNode.addEventListener(ENTITY_EVENTS.AUDIO.ENDED, this.onSoundEnded.bind(this));
|
|
91190
|
+
this.setupCompleted = true;
|
|
91191
|
+
}
|
|
91192
|
+
}, {
|
|
91193
|
+
key: "setSource",
|
|
91194
|
+
value: function setSource(source) {
|
|
91195
|
+
this.source = source;
|
|
91196
|
+
}
|
|
91197
|
+
}, {
|
|
91198
|
+
key: "getSource",
|
|
91199
|
+
value: function getSource() {
|
|
91200
|
+
return this.source;
|
|
91125
91201
|
}
|
|
91126
91202
|
}, {
|
|
91127
91203
|
key: "createAudioNode",
|
|
@@ -91144,14 +91220,14 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91144
91220
|
}, {
|
|
91145
91221
|
key: "tryAutoplay",
|
|
91146
91222
|
value: function tryAutoplay() {
|
|
91147
|
-
if (this.autoplay && !this.hasPlayed) {
|
|
91223
|
+
if (this.autoplay && !this.hasPlayed && !this.setupConfig.deferred) {
|
|
91148
91224
|
this.play();
|
|
91149
91225
|
}
|
|
91150
91226
|
}
|
|
91151
91227
|
}, {
|
|
91152
91228
|
key: "connect",
|
|
91153
91229
|
value: function connect() {
|
|
91154
|
-
if (this.
|
|
91230
|
+
if (this.isConnected()) {
|
|
91155
91231
|
this.disconnect();
|
|
91156
91232
|
}
|
|
91157
91233
|
|
|
@@ -91163,7 +91239,7 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91163
91239
|
}, {
|
|
91164
91240
|
key: "disconnect",
|
|
91165
91241
|
value: function disconnect() {
|
|
91166
|
-
if (this.
|
|
91242
|
+
if (this.isConnected()) {
|
|
91167
91243
|
this.volumeNode.disconnect();
|
|
91168
91244
|
this.audioNode.disconnect();
|
|
91169
91245
|
this.connected = false;
|
|
@@ -91180,7 +91256,7 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91180
91256
|
}, {
|
|
91181
91257
|
key: "getVolume",
|
|
91182
91258
|
value: function getVolume() {
|
|
91183
|
-
return this.volumeNode.gain.value;
|
|
91259
|
+
return this.volumeNode ? this.volumeNode.gain.value : Audio$1.getVolume();
|
|
91184
91260
|
}
|
|
91185
91261
|
}, {
|
|
91186
91262
|
key: "setVolume",
|
|
@@ -91196,15 +91272,21 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91196
91272
|
}, {
|
|
91197
91273
|
key: "setBuffer",
|
|
91198
91274
|
value: function setBuffer() {
|
|
91275
|
+
if (!this.getSource()) {
|
|
91276
|
+
console.error(AUDIO_SOURCE_NOT_DEFINED);
|
|
91277
|
+
return false;
|
|
91278
|
+
}
|
|
91279
|
+
|
|
91199
91280
|
var buffer = Audio$1.get(this.source);
|
|
91200
91281
|
|
|
91201
91282
|
if (!buffer) {
|
|
91202
91283
|
console.error(AUDIO_UNABLE_TO_LOAD_SOUND);
|
|
91203
|
-
return;
|
|
91284
|
+
return false;
|
|
91204
91285
|
}
|
|
91205
91286
|
|
|
91206
91287
|
this.buffer = buffer;
|
|
91207
91288
|
this.audioNode.buffer = buffer;
|
|
91289
|
+
return true;
|
|
91208
91290
|
}
|
|
91209
91291
|
}, {
|
|
91210
91292
|
key: "play",
|
|
@@ -91212,7 +91294,10 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91212
91294
|
var volume = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getVolume();
|
|
91213
91295
|
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_AUDIO_NODE_RAMP_TIME;
|
|
91214
91296
|
var ramp = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : AUDIO_RAMPS.LINEAR;
|
|
91215
|
-
if (this.
|
|
91297
|
+
if (this.isPlaying()) return this;
|
|
91298
|
+
if (!this.isSetupCompleted()) this.setupAudio();
|
|
91299
|
+
if (!this.isConnected()) this.connect();
|
|
91300
|
+
console.log("goin to start playing at volume", volume, this.source);
|
|
91216
91301
|
this.setVolume(0);
|
|
91217
91302
|
this.audioNode.start();
|
|
91218
91303
|
this.hasPlayed = true;
|
|
@@ -91255,9 +91340,15 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91255
91340
|
key: "detune",
|
|
91256
91341
|
value: function detune(value) {
|
|
91257
91342
|
if (this.audioNode) {
|
|
91258
|
-
this.
|
|
91343
|
+
this.detune = value;
|
|
91344
|
+
this.audioNode.detune.value = this.detune;
|
|
91259
91345
|
}
|
|
91260
91346
|
}
|
|
91347
|
+
}, {
|
|
91348
|
+
key: "getDetune",
|
|
91349
|
+
value: function getDetune() {
|
|
91350
|
+
return this.detune;
|
|
91351
|
+
}
|
|
91261
91352
|
}, {
|
|
91262
91353
|
key: "addEffect",
|
|
91263
91354
|
value: function addEffect(effect) {
|
|
@@ -91286,6 +91377,50 @@ var Cone = /*#__PURE__*/function (_Element) {
|
|
|
91286
91377
|
this.plainGainNode.gain.setValueAtTime(0.3, Audio$1.context.currentTime);
|
|
91287
91378
|
}
|
|
91288
91379
|
}
|
|
91380
|
+
}, {
|
|
91381
|
+
key: "setPosition",
|
|
91382
|
+
value: function setPosition(where) {
|
|
91383
|
+
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
91384
|
+
_ref2$updateHolder = _ref2.updateHolder,
|
|
91385
|
+
updateHolder = _ref2$updateHolder === void 0 ? true : _ref2$updateHolder;
|
|
91386
|
+
|
|
91387
|
+
var position = _objectSpread2$1(_objectSpread2$1({}, this.getPosition()), where);
|
|
91388
|
+
|
|
91389
|
+
var x = position.x,
|
|
91390
|
+
y = position.y,
|
|
91391
|
+
z = position.z;
|
|
91392
|
+
|
|
91393
|
+
if (this.hasBody()) {
|
|
91394
|
+
this.body.position.set(x, y, z);
|
|
91395
|
+
}
|
|
91396
|
+
|
|
91397
|
+
if (this.hasHolder() && updateHolder) {
|
|
91398
|
+
this.holder.setPosition({
|
|
91399
|
+
x: x,
|
|
91400
|
+
y: y,
|
|
91401
|
+
z: z
|
|
91402
|
+
});
|
|
91403
|
+
}
|
|
91404
|
+
}
|
|
91405
|
+
}, {
|
|
91406
|
+
key: "toJSON",
|
|
91407
|
+
value: function toJSON() {
|
|
91408
|
+
return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(Sound.prototype), "toJSON", this).call(this)), {}, {
|
|
91409
|
+
source: this.source,
|
|
91410
|
+
loop: this.loop,
|
|
91411
|
+
loopStart: this.loopStart,
|
|
91412
|
+
loopEnd: this.loopEnd,
|
|
91413
|
+
autoplay: this.autoplay,
|
|
91414
|
+
volume: this.getVolume(),
|
|
91415
|
+
detune: this.getDetune(),
|
|
91416
|
+
hasPlayed: this.hasPlayed,
|
|
91417
|
+
playing: this.isPlaying(),
|
|
91418
|
+
connected: this.isConnected(),
|
|
91419
|
+
duration: this.duration,
|
|
91420
|
+
sampleRate: this.sampleRate,
|
|
91421
|
+
numberOfChannels: this.numberOfChannels
|
|
91422
|
+
});
|
|
91423
|
+
}
|
|
91289
91424
|
}, {
|
|
91290
91425
|
key: "sampleRate",
|
|
91291
91426
|
get: function get() {
|
|
@@ -91316,7 +91451,7 @@ var AmbientSound = /*#__PURE__*/function (_Sound) {
|
|
|
91316
91451
|
|
|
91317
91452
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
91318
91453
|
_ref$name = _ref.name,
|
|
91319
|
-
name = _ref$name === void 0 ? generateRandomName(
|
|
91454
|
+
name = _ref$name === void 0 ? generateRandomName("AmbientSound") : _ref$name,
|
|
91320
91455
|
options = _objectWithoutProperties(_ref, _excluded$2);
|
|
91321
91456
|
|
|
91322
91457
|
_classCallCheck(this, AmbientSound);
|
|
@@ -91328,13 +91463,11 @@ var AmbientSound = /*#__PURE__*/function (_Sound) {
|
|
|
91328
91463
|
|
|
91329
91464
|
_this.setEntityType(ENTITY_TYPES.AUDIO.AMBIENT);
|
|
91330
91465
|
|
|
91331
|
-
_this.connect();
|
|
91332
|
-
|
|
91333
91466
|
return _this;
|
|
91334
91467
|
}
|
|
91335
91468
|
|
|
91336
91469
|
return AmbientSound;
|
|
91337
|
-
}(Sound);var _excluded$1 = ["name"];
|
|
91470
|
+
}(Sound$1);var _excluded$1 = ["name"];
|
|
91338
91471
|
|
|
91339
91472
|
var DirectionalSound = /*#__PURE__*/function (_Sound) {
|
|
91340
91473
|
_inherits(DirectionalSound, _Sound);
|
|
@@ -91346,7 +91479,7 @@ var DirectionalSound = /*#__PURE__*/function (_Sound) {
|
|
|
91346
91479
|
|
|
91347
91480
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
91348
91481
|
_ref$name = _ref.name,
|
|
91349
|
-
name = _ref$name === void 0 ? generateRandomName(
|
|
91482
|
+
name = _ref$name === void 0 ? generateRandomName("DirectionalSound") : _ref$name,
|
|
91350
91483
|
options = _objectWithoutProperties(_ref, _excluded$1);
|
|
91351
91484
|
|
|
91352
91485
|
_classCallCheck(this, DirectionalSound);
|
|
@@ -91358,14 +91491,17 @@ var DirectionalSound = /*#__PURE__*/function (_Sound) {
|
|
|
91358
91491
|
|
|
91359
91492
|
_this.setEntityType(ENTITY_TYPES.AUDIO.DIRECTIONAL);
|
|
91360
91493
|
|
|
91361
|
-
_this.createPannerNode(options);
|
|
91362
|
-
|
|
91363
|
-
_this.connect();
|
|
91364
|
-
|
|
91365
91494
|
return _this;
|
|
91366
91495
|
}
|
|
91367
91496
|
|
|
91368
91497
|
_createClass(DirectionalSound, [{
|
|
91498
|
+
key: "setupAudio",
|
|
91499
|
+
value: function setupAudio() {
|
|
91500
|
+
_get(_getPrototypeOf(DirectionalSound.prototype), "setupAudio", this).call(this);
|
|
91501
|
+
|
|
91502
|
+
this.createPannerNode(this.options);
|
|
91503
|
+
}
|
|
91504
|
+
}, {
|
|
91369
91505
|
key: "hasPannerNode",
|
|
91370
91506
|
value: function hasPannerNode() {
|
|
91371
91507
|
return !!this.pannerNode;
|
|
@@ -91387,8 +91523,8 @@ var DirectionalSound = /*#__PURE__*/function (_Sound) {
|
|
|
91387
91523
|
_options$refDistance = options.refDistance,
|
|
91388
91524
|
refDistance = _options$refDistance === void 0 ? 1 : _options$refDistance;
|
|
91389
91525
|
this.pannerNode = Audio$1.context.createPanner();
|
|
91390
|
-
this.pannerNode.panningModel =
|
|
91391
|
-
this.pannerNode.distanceModel =
|
|
91526
|
+
this.pannerNode.panningModel = "HRTF";
|
|
91527
|
+
this.pannerNode.distanceModel = "inverse";
|
|
91392
91528
|
this.pannerNode.refDistance = refDistance;
|
|
91393
91529
|
this.pannerNode.maxDistance = maxDistance;
|
|
91394
91530
|
this.pannerNode.rolloffFactor = rolloffFactor;
|
|
@@ -91460,7 +91596,395 @@ var DirectionalSound = /*#__PURE__*/function (_Sound) {
|
|
|
91460
91596
|
}]);
|
|
91461
91597
|
|
|
91462
91598
|
return DirectionalSound;
|
|
91463
|
-
}(Sound);var
|
|
91599
|
+
}(Sound$1);var DEFAULT_SETUP_CONFIG = {
|
|
91600
|
+
deferred: false
|
|
91601
|
+
};
|
|
91602
|
+
|
|
91603
|
+
var Sound = /*#__PURE__*/function (_Entity) {
|
|
91604
|
+
_inherits(Sound, _Entity);
|
|
91605
|
+
|
|
91606
|
+
var _super = _createSuper(Sound);
|
|
91607
|
+
|
|
91608
|
+
function Sound() {
|
|
91609
|
+
var _this;
|
|
91610
|
+
|
|
91611
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
91612
|
+
|
|
91613
|
+
_classCallCheck(this, Sound);
|
|
91614
|
+
|
|
91615
|
+
var source = options.source,
|
|
91616
|
+
_options$loop = options.loop,
|
|
91617
|
+
loop = _options$loop === void 0 ? false : _options$loop,
|
|
91618
|
+
loopStart = options.loopStart,
|
|
91619
|
+
loopEnd = options.loopEnd,
|
|
91620
|
+
autoplay = options.autoplay,
|
|
91621
|
+
reconnectOnReset = options.reconnectOnReset,
|
|
91622
|
+
_options$setupConfig = options.setupConfig,
|
|
91623
|
+
setupConfig = _options$setupConfig === void 0 ? DEFAULT_SETUP_CONFIG : _options$setupConfig,
|
|
91624
|
+
_options$name = options.name,
|
|
91625
|
+
name = _options$name === void 0 ? generateRandomName("sound") : _options$name;
|
|
91626
|
+
_this = _super.call(this, _objectSpread2$1(_objectSpread2$1({}, options), {}, {
|
|
91627
|
+
source: source,
|
|
91628
|
+
loop: loop,
|
|
91629
|
+
loopStart: loopStart,
|
|
91630
|
+
loopEnd: loopEnd,
|
|
91631
|
+
autoplay: autoplay,
|
|
91632
|
+
reconnectOnReset: reconnectOnReset,
|
|
91633
|
+
name: name
|
|
91634
|
+
}));
|
|
91635
|
+
|
|
91636
|
+
_defineProperty$1(_assertThisInitialized(_this), "reset", function () {
|
|
91637
|
+
_this.playing = false;
|
|
91638
|
+
|
|
91639
|
+
_this.disconnect();
|
|
91640
|
+
|
|
91641
|
+
_this.setupAudio();
|
|
91642
|
+
|
|
91643
|
+
_this.connect();
|
|
91644
|
+
});
|
|
91645
|
+
|
|
91646
|
+
_this.setupConfig = setupConfig;
|
|
91647
|
+
_this.source = source;
|
|
91648
|
+
_this.loop = loop;
|
|
91649
|
+
_this.loopStart = loopStart;
|
|
91650
|
+
_this.loopEnd = loopEnd;
|
|
91651
|
+
_this.autoplay = autoplay;
|
|
91652
|
+
_this.reconnectOnReset = reconnectOnReset;
|
|
91653
|
+
_this.name = name;
|
|
91654
|
+
_this.connected = false;
|
|
91655
|
+
_this.playing = false;
|
|
91656
|
+
_this.setupCompleted = false;
|
|
91657
|
+
_this.hasPlayed = false;
|
|
91658
|
+
_this.buffer = null;
|
|
91659
|
+
_this.audioNode = null;
|
|
91660
|
+
_this.volumeNode = null;
|
|
91661
|
+
|
|
91662
|
+
if (!_this.setupConfig.deferred) {
|
|
91663
|
+
_this.setupAudio();
|
|
91664
|
+
}
|
|
91665
|
+
|
|
91666
|
+
_this.setName(name);
|
|
91667
|
+
|
|
91668
|
+
_this.setBody({
|
|
91669
|
+
body: new Object3D()
|
|
91670
|
+
});
|
|
91671
|
+
|
|
91672
|
+
_this.setEntityType(ENTITY_TYPES.AUDIO.DEFAULT);
|
|
91673
|
+
|
|
91674
|
+
Audio$1.add(_assertThisInitialized(_this));
|
|
91675
|
+
|
|
91676
|
+
if (_this.isSetupCompleted()) {
|
|
91677
|
+
_this.connect();
|
|
91678
|
+
}
|
|
91679
|
+
|
|
91680
|
+
return _this;
|
|
91681
|
+
}
|
|
91682
|
+
|
|
91683
|
+
_createClass(Sound, [{
|
|
91684
|
+
key: "addHelpers",
|
|
91685
|
+
value: function addHelpers() {
|
|
91686
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
91687
|
+
_ref$holderName = _ref.holderName,
|
|
91688
|
+
holderName = _ref$holderName === void 0 ? "soundholder" : _ref$holderName,
|
|
91689
|
+
_ref$holderSize = _ref.holderSize,
|
|
91690
|
+
holderSize = _ref$holderSize === void 0 ? 0.05 : _ref$holderSize;
|
|
91691
|
+
|
|
91692
|
+
var holderSprite = new HelperSprite(holderSize, holderSize, holderName, {
|
|
91693
|
+
name: holderName
|
|
91694
|
+
});
|
|
91695
|
+
|
|
91696
|
+
if (holderSprite) {
|
|
91697
|
+
holderSprite.setSizeAttenuation(false);
|
|
91698
|
+
holderSprite.setDepthTest(false);
|
|
91699
|
+
holderSprite.setDepthWrite(false);
|
|
91700
|
+
holderSprite.setSerializable(false);
|
|
91701
|
+
holderSprite.setPosition(this.getPosition());
|
|
91702
|
+
holderSprite.addTags([TAGS.LIGHTS.HELPER, TAGS.LIGHTS.HOLDER, name]);
|
|
91703
|
+
holderSprite.setHelperTarget(this);
|
|
91704
|
+
this.holder = holderSprite;
|
|
91705
|
+
return true;
|
|
91706
|
+
} else {
|
|
91707
|
+
console.warn(LIGHT_HOLDER_MODEL_NOT_FOUND);
|
|
91708
|
+
return false;
|
|
91709
|
+
}
|
|
91710
|
+
}
|
|
91711
|
+
}, {
|
|
91712
|
+
key: "isPlaying",
|
|
91713
|
+
value: function isPlaying() {
|
|
91714
|
+
return this.playing;
|
|
91715
|
+
}
|
|
91716
|
+
}, {
|
|
91717
|
+
key: "isSetupCompleted",
|
|
91718
|
+
value: function isSetupCompleted() {
|
|
91719
|
+
return this.setupCompleted;
|
|
91720
|
+
}
|
|
91721
|
+
}, {
|
|
91722
|
+
key: "isConnected",
|
|
91723
|
+
value: function isConnected() {
|
|
91724
|
+
return this.connected;
|
|
91725
|
+
}
|
|
91726
|
+
}, {
|
|
91727
|
+
key: "setupAudio",
|
|
91728
|
+
value: function setupAudio() {
|
|
91729
|
+
this.createAudioNode();
|
|
91730
|
+
this.createVolumeNode();
|
|
91731
|
+
this.setBuffer();
|
|
91732
|
+
this.setupAudioNodeLoop();
|
|
91733
|
+
this.audioNode.removeEventListener(ENTITY_EVENTS.AUDIO.ENDED, this.onSoundEnded.bind(this));
|
|
91734
|
+
this.audioNode.addEventListener(ENTITY_EVENTS.AUDIO.ENDED, this.onSoundEnded.bind(this));
|
|
91735
|
+
this.setupCompleted = true;
|
|
91736
|
+
}
|
|
91737
|
+
}, {
|
|
91738
|
+
key: "setSource",
|
|
91739
|
+
value: function setSource(source) {
|
|
91740
|
+
this.source = source;
|
|
91741
|
+
}
|
|
91742
|
+
}, {
|
|
91743
|
+
key: "getSource",
|
|
91744
|
+
value: function getSource() {
|
|
91745
|
+
return this.source;
|
|
91746
|
+
}
|
|
91747
|
+
}, {
|
|
91748
|
+
key: "createAudioNode",
|
|
91749
|
+
value: function createAudioNode() {
|
|
91750
|
+
this.audioNode = Audio$1.context.createBufferSource();
|
|
91751
|
+
}
|
|
91752
|
+
}, {
|
|
91753
|
+
key: "setupAudioNodeLoop",
|
|
91754
|
+
value: function setupAudioNodeLoop() {
|
|
91755
|
+
this.audioNode.loop = this.loop;
|
|
91756
|
+
this.audioNode.loopEnd = this.loopEnd === undefined ? this.duration : this.loopEnd;
|
|
91757
|
+
this.audioNode.loopStart = this.loopStart === undefined ? this.duration : this.loopStart;
|
|
91758
|
+
}
|
|
91759
|
+
}, {
|
|
91760
|
+
key: "createVolumeNode",
|
|
91761
|
+
value: function createVolumeNode() {
|
|
91762
|
+
this.volumeNode = Audio$1.context.createGain();
|
|
91763
|
+
this.volumeNode.gain.value = DEFAULT_AUDIO_NODE_VOLUME;
|
|
91764
|
+
}
|
|
91765
|
+
}, {
|
|
91766
|
+
key: "tryAutoplay",
|
|
91767
|
+
value: function tryAutoplay() {
|
|
91768
|
+
if (this.autoplay && !this.hasPlayed && !this.setupConfig.deferred) {
|
|
91769
|
+
this.play();
|
|
91770
|
+
}
|
|
91771
|
+
}
|
|
91772
|
+
}, {
|
|
91773
|
+
key: "connect",
|
|
91774
|
+
value: function connect() {
|
|
91775
|
+
if (this.isConnected()) {
|
|
91776
|
+
this.disconnect();
|
|
91777
|
+
}
|
|
91778
|
+
|
|
91779
|
+
this.volumeNode.connect(Audio$1.getMasterVolumeNode());
|
|
91780
|
+
this.audioNode.connect(this.volumeNode);
|
|
91781
|
+
this.connected = true;
|
|
91782
|
+
this.tryAutoplay();
|
|
91783
|
+
}
|
|
91784
|
+
}, {
|
|
91785
|
+
key: "disconnect",
|
|
91786
|
+
value: function disconnect() {
|
|
91787
|
+
if (this.isConnected()) {
|
|
91788
|
+
this.volumeNode.disconnect();
|
|
91789
|
+
this.audioNode.disconnect();
|
|
91790
|
+
this.connected = false;
|
|
91791
|
+
}
|
|
91792
|
+
}
|
|
91793
|
+
}, {
|
|
91794
|
+
key: "dispose",
|
|
91795
|
+
value: function dispose() {
|
|
91796
|
+
_get(_getPrototypeOf(Sound.prototype), "dispose", this).call(this);
|
|
91797
|
+
|
|
91798
|
+
this.stop();
|
|
91799
|
+
this.disconnect();
|
|
91800
|
+
}
|
|
91801
|
+
}, {
|
|
91802
|
+
key: "getVolume",
|
|
91803
|
+
value: function getVolume() {
|
|
91804
|
+
return this.volumeNode ? this.volumeNode.gain.value : Audio$1.getVolume();
|
|
91805
|
+
}
|
|
91806
|
+
}, {
|
|
91807
|
+
key: "setVolume",
|
|
91808
|
+
value: function setVolume() {
|
|
91809
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_AUDIO_NODE_VOLUME;
|
|
91810
|
+
this.volumeNode.gain.setValueAtTime(value, Audio$1.context.currentTime);
|
|
91811
|
+
}
|
|
91812
|
+
}, {
|
|
91813
|
+
key: "hasBuffer",
|
|
91814
|
+
value: function hasBuffer() {
|
|
91815
|
+
return !!this.buffer;
|
|
91816
|
+
}
|
|
91817
|
+
}, {
|
|
91818
|
+
key: "setBuffer",
|
|
91819
|
+
value: function setBuffer() {
|
|
91820
|
+
if (!this.getSource()) {
|
|
91821
|
+
console.error(AUDIO_SOURCE_NOT_DEFINED);
|
|
91822
|
+
return false;
|
|
91823
|
+
}
|
|
91824
|
+
|
|
91825
|
+
var buffer = Audio$1.get(this.source);
|
|
91826
|
+
|
|
91827
|
+
if (!buffer) {
|
|
91828
|
+
console.error(AUDIO_UNABLE_TO_LOAD_SOUND);
|
|
91829
|
+
return false;
|
|
91830
|
+
}
|
|
91831
|
+
|
|
91832
|
+
this.buffer = buffer;
|
|
91833
|
+
this.audioNode.buffer = buffer;
|
|
91834
|
+
return true;
|
|
91835
|
+
}
|
|
91836
|
+
}, {
|
|
91837
|
+
key: "play",
|
|
91838
|
+
value: function play() {
|
|
91839
|
+
var volume = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getVolume();
|
|
91840
|
+
var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_AUDIO_NODE_RAMP_TIME;
|
|
91841
|
+
var ramp = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : AUDIO_RAMPS.LINEAR;
|
|
91842
|
+
if (this.isPlaying()) return this;
|
|
91843
|
+
if (!this.isSetupCompleted()) this.setupAudio();
|
|
91844
|
+
if (!this.isConnected()) this.connect();
|
|
91845
|
+
console.log("goin to start playing at volume", volume, this.source);
|
|
91846
|
+
this.setVolume(0);
|
|
91847
|
+
this.audioNode.start();
|
|
91848
|
+
this.hasPlayed = true;
|
|
91849
|
+
this.playing = true;
|
|
91850
|
+
var audioDelay = delay / 1000; // linearRampToValueAtTime/exponentialRampToValueAtTime requires time to be expressed in seconds
|
|
91851
|
+
|
|
91852
|
+
if (ramp === AUDIO_RAMPS.LINEAR) {
|
|
91853
|
+
this.volumeNode.gain.linearRampToValueAtTime(volume, Audio$1.context.currentTime + audioDelay);
|
|
91854
|
+
} else {
|
|
91855
|
+
this.volumeNode.gain.exponentialRampToValueAtTime(volume, Audio$1.context.currentTime + audioDelay);
|
|
91856
|
+
}
|
|
91857
|
+
|
|
91858
|
+
return this;
|
|
91859
|
+
}
|
|
91860
|
+
}, {
|
|
91861
|
+
key: "onSoundEnded",
|
|
91862
|
+
value: function onSoundEnded() {
|
|
91863
|
+
this.reset();
|
|
91864
|
+
this.dispatchEvent({
|
|
91865
|
+
type: ENTITY_EVENTS.AUDIO.ENDED
|
|
91866
|
+
});
|
|
91867
|
+
}
|
|
91868
|
+
}, {
|
|
91869
|
+
key: "stop",
|
|
91870
|
+
value: function stop() {
|
|
91871
|
+
var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_AUDIO_NODE_RAMP_TIME;
|
|
91872
|
+
var ramp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : AUDIO_RAMPS.LINEAR;
|
|
91873
|
+
var audioDelay = delay / 1000; // linearRampToValueAtTime/exponentialRampToValueAtTime requires time to be expressed in seconds
|
|
91874
|
+
|
|
91875
|
+
if (ramp === AUDIO_RAMPS.LINEAR) {
|
|
91876
|
+
this.volumeNode.gain.linearRampToValueAtTime(ALMOST_ZERO, Audio$1.context.currentTime + audioDelay);
|
|
91877
|
+
} else {
|
|
91878
|
+
this.volumeNode.gain.exponentialRampToValueAtTime(ALMOST_ZERO, Audio$1.context.currentTime + audioDelay);
|
|
91879
|
+
}
|
|
91880
|
+
|
|
91881
|
+
setTimeout(this.reset, delay);
|
|
91882
|
+
return this;
|
|
91883
|
+
}
|
|
91884
|
+
}, {
|
|
91885
|
+
key: "detune",
|
|
91886
|
+
value: function detune(value) {
|
|
91887
|
+
if (this.audioNode) {
|
|
91888
|
+
this.detune = value;
|
|
91889
|
+
this.audioNode.detune.value = this.detune;
|
|
91890
|
+
}
|
|
91891
|
+
}
|
|
91892
|
+
}, {
|
|
91893
|
+
key: "getDetune",
|
|
91894
|
+
value: function getDetune() {
|
|
91895
|
+
return this.detune;
|
|
91896
|
+
}
|
|
91897
|
+
}, {
|
|
91898
|
+
key: "addEffect",
|
|
91899
|
+
value: function addEffect(effect) {
|
|
91900
|
+
if (!this.hasEffect() && effect) {
|
|
91901
|
+
this.convolverNode = Audio$1.context.createConvolver();
|
|
91902
|
+
this.mixerNode = Audio$1.createGain();
|
|
91903
|
+
|
|
91904
|
+
if (this.hasPannerNode()) {
|
|
91905
|
+
this.pannerNode.disconnect();
|
|
91906
|
+
this.pannerNode.connect(this.mixerNode);
|
|
91907
|
+
} else {
|
|
91908
|
+
this.volumeNode.disconnect();
|
|
91909
|
+
this.volumeNode.connect(this.mixerNode);
|
|
91910
|
+
} //creating gains
|
|
91911
|
+
|
|
91912
|
+
|
|
91913
|
+
this.plainGainNode = Audio$1.context.createGain();
|
|
91914
|
+
this.convolverGainNode = Audio$1.context.createGain(); //connect mixer to new gains
|
|
91915
|
+
|
|
91916
|
+
this.mixerNode.connect(this.plainGainNode);
|
|
91917
|
+
this.mixerNode.connect(this.convolverGainNode);
|
|
91918
|
+
this.plainGainNode.connect(Audio$1.getMasterVolumeNode());
|
|
91919
|
+
this.convolverGainNode.connect(Audio$1.getMasterVolumeNode());
|
|
91920
|
+
this.convolverNode.buffer = Audio$1.get(effect);
|
|
91921
|
+
this.convolverGainNode.gain.setValueAtTime(0.7, Audio$1.context.currentTime);
|
|
91922
|
+
this.plainGainNode.gain.setValueAtTime(0.3, Audio$1.context.currentTime);
|
|
91923
|
+
}
|
|
91924
|
+
}
|
|
91925
|
+
}, {
|
|
91926
|
+
key: "setPosition",
|
|
91927
|
+
value: function setPosition(where) {
|
|
91928
|
+
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
91929
|
+
_ref2$updateHolder = _ref2.updateHolder,
|
|
91930
|
+
updateHolder = _ref2$updateHolder === void 0 ? true : _ref2$updateHolder;
|
|
91931
|
+
|
|
91932
|
+
var position = _objectSpread2$1(_objectSpread2$1({}, this.getPosition()), where);
|
|
91933
|
+
|
|
91934
|
+
var x = position.x,
|
|
91935
|
+
y = position.y,
|
|
91936
|
+
z = position.z;
|
|
91937
|
+
|
|
91938
|
+
if (this.hasBody()) {
|
|
91939
|
+
this.body.position.set(x, y, z);
|
|
91940
|
+
}
|
|
91941
|
+
|
|
91942
|
+
if (this.hasHolder() && updateHolder) {
|
|
91943
|
+
this.holder.setPosition({
|
|
91944
|
+
x: x,
|
|
91945
|
+
y: y,
|
|
91946
|
+
z: z
|
|
91947
|
+
});
|
|
91948
|
+
}
|
|
91949
|
+
}
|
|
91950
|
+
}, {
|
|
91951
|
+
key: "toJSON",
|
|
91952
|
+
value: function toJSON() {
|
|
91953
|
+
return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(Sound.prototype), "toJSON", this).call(this)), {}, {
|
|
91954
|
+
source: this.source,
|
|
91955
|
+
loop: this.loop,
|
|
91956
|
+
loopStart: this.loopStart,
|
|
91957
|
+
loopEnd: this.loopEnd,
|
|
91958
|
+
autoplay: this.autoplay,
|
|
91959
|
+
volume: this.getVolume(),
|
|
91960
|
+
detune: this.getDetune(),
|
|
91961
|
+
hasPlayed: this.hasPlayed,
|
|
91962
|
+
playing: this.isPlaying(),
|
|
91963
|
+
connected: this.isConnected(),
|
|
91964
|
+
duration: this.duration,
|
|
91965
|
+
sampleRate: this.sampleRate,
|
|
91966
|
+
numberOfChannels: this.numberOfChannels
|
|
91967
|
+
});
|
|
91968
|
+
}
|
|
91969
|
+
}, {
|
|
91970
|
+
key: "sampleRate",
|
|
91971
|
+
get: function get() {
|
|
91972
|
+
return this.buffer.sampleRate;
|
|
91973
|
+
}
|
|
91974
|
+
}, {
|
|
91975
|
+
key: "duration",
|
|
91976
|
+
get: function get() {
|
|
91977
|
+
return this.buffer.duration * 1000;
|
|
91978
|
+
}
|
|
91979
|
+
}, {
|
|
91980
|
+
key: "numberOfChannels",
|
|
91981
|
+
get: function get() {
|
|
91982
|
+
return this.buffer.numberOfChannels;
|
|
91983
|
+
}
|
|
91984
|
+
}]);
|
|
91985
|
+
|
|
91986
|
+
return Sound;
|
|
91987
|
+
}(Entity);var BLOB_TYPE = 'application/javascript';
|
|
91464
91988
|
var createBlob = function createBlob(task) {
|
|
91465
91989
|
return new Blob(['(', task.toString(), ')()'], {
|
|
91466
91990
|
type: BLOB_TYPE
|