@needle-tools/engine 3.27.4-beta → 3.28.0-beta
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/CHANGELOG.md +11 -0
- package/dist/needle-engine.js +7402 -7411
- package/dist/needle-engine.light.js +7117 -7126
- package/dist/needle-engine.light.min.js +254 -247
- package/dist/needle-engine.light.umd.cjs +336 -329
- package/dist/needle-engine.min.js +255 -248
- package/dist/needle-engine.umd.cjs +298 -291
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_shims.d.ts +3 -0
- package/lib/engine/engine_shims.js +23 -0
- package/lib/engine/engine_shims.js.map +1 -0
- package/lib/engine-components/Renderer.js +12 -0
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +16 -8
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +27 -15
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.d.ts +1 -0
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js +14 -6
- package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.js +7 -1
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine.ts +1 -2
- package/src/engine/engine_context.ts +3 -2
- package/src/engine/engine_setup.ts +1 -1
- package/src/engine/engine_shims.ts +29 -0
- package/src/engine-components/Renderer.ts +13 -0
- package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +39 -31
- package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +21 -7
- package/src/engine-components/ui/EventSystem.ts +9 -1
- package/src/engine/dist/api.js +0 -73
- package/src/engine/dist/api.js.meta +0 -7
- package/src/engine/dist/engine_networking_streams.js +0 -474
- package/src/engine/dist/engine_networking_streams.js.meta +0 -7
- package/src/engine-components/dist/AudioSource.js +0 -513
- package/src/engine-components/dist/AudioSource.js.meta +0 -7
- package/src/engine-components/dist/ScreenCapture.js +0 -490
- package/src/engine-components/dist/ScreenCapture.js.meta +0 -7
- package/src/engine-components/dist/VideoPlayer.js +0 -888
- package/src/engine-components/dist/VideoPlayer.js.meta +0 -7
- package/src/engine-components/dist/Voip2.js +0 -46
- package/src/engine-components/dist/Voip2.js.meta +0 -7
- package/src/engine-schemes/dist/api.js +0 -17
- package/src/engine-schemes/dist/api.js.meta +0 -7
- package/src/engine-schemes/dist/schemes.js +0 -25
- package/src/engine-schemes/dist/schemes.js.meta +0 -7
- package/src/engine-schemes/dist/synced-camera-model.js +0 -74
- package/src/engine-schemes/dist/synced-camera-model.js.meta +0 -7
- package/src/engine-schemes/dist/synced-transform-model.js +0 -73
- package/src/engine-schemes/dist/synced-transform-model.js.meta +0 -7
- package/src/engine-schemes/dist/transform.js +0 -46
- package/src/engine-schemes/dist/transform.js.meta +0 -7
- package/src/engine-schemes/dist/vec2.js +0 -32
- package/src/engine-schemes/dist/vec2.js.meta +0 -7
- package/src/engine-schemes/dist/vec3.js +0 -36
- package/src/engine-schemes/dist/vec3.js.meta +0 -7
- package/src/engine-schemes/dist/vec4.js +0 -40
- package/src/engine-schemes/dist/vec4.js.meta +0 -7
- package/src/engine-schemes/dist/vr-user-state-buffer.js +0 -110
- package/src/engine-schemes/dist/vr-user-state-buffer.js.meta +0 -7
|
@@ -1,513 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
16
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
17
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
18
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
19
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
20
|
-
};
|
|
21
|
-
exports.__esModule = true;
|
|
22
|
-
exports.AudioSource = exports.AudioRolloffMode = void 0;
|
|
23
|
-
var Component_js_1 = require("./Component.js");
|
|
24
|
-
var PositionalAudioHelper_js_1 = require("three/examples/jsm/helpers/PositionalAudioHelper.js");
|
|
25
|
-
var AudioListener_js_1 = require("./AudioListener.js");
|
|
26
|
-
var utils = require("../engine/engine_utils.js");
|
|
27
|
-
var engine_serialization_decorator_js_1 = require("../engine/engine_serialization_decorator.js");
|
|
28
|
-
var engine_application_js_1 = require("../engine/engine_application.js");
|
|
29
|
-
var three_1 = require("three");
|
|
30
|
-
var debug = utils.getParam("debugaudio");
|
|
31
|
-
var AudioRolloffMode;
|
|
32
|
-
(function (AudioRolloffMode) {
|
|
33
|
-
/// <summary>
|
|
34
|
-
/// <para>Use this mode when you want a real-world rolloff.</para>
|
|
35
|
-
/// </summary>
|
|
36
|
-
AudioRolloffMode[AudioRolloffMode["Logarithmic"] = 0] = "Logarithmic";
|
|
37
|
-
/// <summary>
|
|
38
|
-
/// <para>Use this mode when you want to lower the volume of your sound over the distance.</para>
|
|
39
|
-
/// </summary>
|
|
40
|
-
AudioRolloffMode[AudioRolloffMode["Linear"] = 1] = "Linear";
|
|
41
|
-
/// <summary>
|
|
42
|
-
/// <para>Use this when you want to use a custom rolloff.</para>
|
|
43
|
-
/// </summary>
|
|
44
|
-
AudioRolloffMode[AudioRolloffMode["Custom"] = 2] = "Custom";
|
|
45
|
-
})(AudioRolloffMode = exports.AudioRolloffMode || (exports.AudioRolloffMode = {}));
|
|
46
|
-
var AudioSource = /** @class */ (function (_super) {
|
|
47
|
-
__extends(AudioSource, _super);
|
|
48
|
-
function AudioSource() {
|
|
49
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
50
|
-
_this.clip = "";
|
|
51
|
-
_this.playOnAwake = false;
|
|
52
|
-
_this._spatialBlend = 0;
|
|
53
|
-
_this._minDistance = 1;
|
|
54
|
-
_this._maxDistance = 100;
|
|
55
|
-
_this._volume = 1;
|
|
56
|
-
_this.rollOffMode = 0;
|
|
57
|
-
_this.playInBackground = true;
|
|
58
|
-
_this._loop = false;
|
|
59
|
-
_this.sound = null;
|
|
60
|
-
_this.helper = null;
|
|
61
|
-
_this.wasPlaying = false;
|
|
62
|
-
_this.audioLoader = null;
|
|
63
|
-
_this.shouldPlay = false;
|
|
64
|
-
// set this from audio context time, used to set clip offset when setting "time" property
|
|
65
|
-
// there is maybe a better way to set a audio clip current time?!
|
|
66
|
-
_this._lastClipStartedLoading = null;
|
|
67
|
-
_this._audioElement = null;
|
|
68
|
-
_this.onVisibilityChanged = function () {
|
|
69
|
-
switch (document.visibilityState) {
|
|
70
|
-
case "hidden":
|
|
71
|
-
if (_this.playInBackground === false || utils.isMobileDevice()) {
|
|
72
|
-
_this.wasPlaying = _this.isPlaying;
|
|
73
|
-
if (_this.isPlaying) {
|
|
74
|
-
_this.pause();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
case "visible":
|
|
79
|
-
if (debug)
|
|
80
|
-
console.log("visible", _this.enabled, _this.playOnAwake, !_this.isPlaying, AudioSource._userInteractionRegistered, _this.wasPlaying);
|
|
81
|
-
if (_this.enabled && _this.playOnAwake && !_this.isPlaying && AudioSource._userInteractionRegistered && _this.wasPlaying) {
|
|
82
|
-
_this.play();
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
_this.onApplicationMuteChanged = function () {
|
|
88
|
-
var _a, _b;
|
|
89
|
-
if (_this.context.application.muted)
|
|
90
|
-
(_a = _this.sound) === null || _a === void 0 ? void 0 : _a.setVolume(0);
|
|
91
|
-
else
|
|
92
|
-
(_b = _this.sound) === null || _b === void 0 ? void 0 : _b.setVolume(_this.volume);
|
|
93
|
-
};
|
|
94
|
-
_this.lerp = function (x, y, a) { return x * (1 - a) + y * a; };
|
|
95
|
-
_this.createAudio = function (buffer) {
|
|
96
|
-
if (debug)
|
|
97
|
-
console.log("audio buffer loaded");
|
|
98
|
-
AudioSource.registerWaitForAllowAudio(function () {
|
|
99
|
-
if (debug)
|
|
100
|
-
console.log("finished loading", buffer);
|
|
101
|
-
var sound = _this.Sound;
|
|
102
|
-
if (!sound) {
|
|
103
|
-
console.warn("Failed getting sound", _this.name);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (sound.isPlaying)
|
|
107
|
-
sound.stop();
|
|
108
|
-
if (buffer)
|
|
109
|
-
sound.setBuffer(buffer);
|
|
110
|
-
sound.loop = _this._loop;
|
|
111
|
-
if (_this.context.application.muted)
|
|
112
|
-
sound.setVolume(0);
|
|
113
|
-
else
|
|
114
|
-
sound.setVolume(_this.volume);
|
|
115
|
-
sound.autoplay = _this.shouldPlay;
|
|
116
|
-
// sound.setDistanceModel('linear');
|
|
117
|
-
// sound.setRolloffFactor(1);
|
|
118
|
-
_this.applySpatialDistanceSettings();
|
|
119
|
-
// sound.setDirectionalCone(180, 360, 0.1);
|
|
120
|
-
if (sound.isPlaying)
|
|
121
|
-
sound.stop();
|
|
122
|
-
if (debug)
|
|
123
|
-
console.log(_this.name, _this.shouldPlay, AudioSource.userInteractionRegistered, _this);
|
|
124
|
-
if (_this.shouldPlay && AudioSource._userInteractionRegistered)
|
|
125
|
-
_this.play();
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
_this._lastContextTime = 0;
|
|
129
|
-
_this._hasEnded = true;
|
|
130
|
-
_this._needUpdateSpatialDistanceSettings = false;
|
|
131
|
-
return _this;
|
|
132
|
-
}
|
|
133
|
-
Object.defineProperty(AudioSource, "userInteractionRegistered", {
|
|
134
|
-
get: function () {
|
|
135
|
-
if (!AudioSource._didCallBeginWaitForUserInteraction) {
|
|
136
|
-
AudioSource._didCallBeginWaitForUserInteraction = true;
|
|
137
|
-
AudioSource._beginWaitForUserInteraction();
|
|
138
|
-
}
|
|
139
|
-
return AudioSource._userInteractionRegistered;
|
|
140
|
-
},
|
|
141
|
-
enumerable: false,
|
|
142
|
-
configurable: true
|
|
143
|
-
});
|
|
144
|
-
AudioSource.registerWaitForAllowAudio = function (cb) {
|
|
145
|
-
if (cb !== null) {
|
|
146
|
-
if (this._userInteractionRegistered) {
|
|
147
|
-
cb();
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (this.callbacks.indexOf(cb) === -1)
|
|
151
|
-
this.callbacks.push(cb);
|
|
152
|
-
if (!AudioSource._didCallBeginWaitForUserInteraction) {
|
|
153
|
-
AudioSource._didCallBeginWaitForUserInteraction = true;
|
|
154
|
-
AudioSource._beginWaitForUserInteraction();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
AudioSource._beginWaitForUserInteraction = function (cb) {
|
|
159
|
-
var _this = this;
|
|
160
|
-
if (cb === void 0) { cb = null; }
|
|
161
|
-
if (this._userInteractionRegistered) {
|
|
162
|
-
if (cb)
|
|
163
|
-
cb();
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (cb !== null)
|
|
167
|
-
this.registerWaitForAllowAudio(cb);
|
|
168
|
-
var callback = function () {
|
|
169
|
-
if (fn == undefined)
|
|
170
|
-
return;
|
|
171
|
-
if (AudioSource._userInteractionRegistered)
|
|
172
|
-
return;
|
|
173
|
-
AudioSource._userInteractionRegistered = true;
|
|
174
|
-
if (debug)
|
|
175
|
-
console.log("🔊 registered interaction, can play audio now");
|
|
176
|
-
document.removeEventListener('pointerdown', fn);
|
|
177
|
-
document.removeEventListener('click', fn);
|
|
178
|
-
document.removeEventListener('dragstart', fn);
|
|
179
|
-
document.removeEventListener('touchstart', fn);
|
|
180
|
-
for (var _i = 0, _a = _this.callbacks; _i < _a.length; _i++) {
|
|
181
|
-
var cb_1 = _a[_i];
|
|
182
|
-
cb_1();
|
|
183
|
-
}
|
|
184
|
-
_this.callbacks.length = 0;
|
|
185
|
-
};
|
|
186
|
-
var fn = callback.bind(this);
|
|
187
|
-
document.addEventListener('pointerdown', fn);
|
|
188
|
-
document.addEventListener('click', fn);
|
|
189
|
-
document.addEventListener('dragstart', fn);
|
|
190
|
-
document.addEventListener('touchstart', fn);
|
|
191
|
-
};
|
|
192
|
-
Object.defineProperty(AudioSource.prototype, "loop", {
|
|
193
|
-
get: function () {
|
|
194
|
-
if (this.sound)
|
|
195
|
-
this._loop = this.sound.getLoop();
|
|
196
|
-
return this._loop;
|
|
197
|
-
},
|
|
198
|
-
set: function (val) {
|
|
199
|
-
this._loop = val;
|
|
200
|
-
if (this.sound)
|
|
201
|
-
this.sound.setLoop(val);
|
|
202
|
-
},
|
|
203
|
-
enumerable: false,
|
|
204
|
-
configurable: true
|
|
205
|
-
});
|
|
206
|
-
Object.defineProperty(AudioSource.prototype, "spatialBlend", {
|
|
207
|
-
/** 0 = 2D, 1 = 3D */
|
|
208
|
-
get: function () {
|
|
209
|
-
return this._spatialBlend;
|
|
210
|
-
},
|
|
211
|
-
set: function (val) {
|
|
212
|
-
if (val === this._spatialBlend)
|
|
213
|
-
return;
|
|
214
|
-
this._spatialBlend = val;
|
|
215
|
-
this._needUpdateSpatialDistanceSettings = true;
|
|
216
|
-
},
|
|
217
|
-
enumerable: false,
|
|
218
|
-
configurable: true
|
|
219
|
-
});
|
|
220
|
-
Object.defineProperty(AudioSource.prototype, "minDistance", {
|
|
221
|
-
get: function () {
|
|
222
|
-
return this._minDistance;
|
|
223
|
-
},
|
|
224
|
-
set: function (val) {
|
|
225
|
-
if (this._minDistance === val)
|
|
226
|
-
return;
|
|
227
|
-
this._minDistance = val;
|
|
228
|
-
this._needUpdateSpatialDistanceSettings = true;
|
|
229
|
-
},
|
|
230
|
-
enumerable: false,
|
|
231
|
-
configurable: true
|
|
232
|
-
});
|
|
233
|
-
Object.defineProperty(AudioSource.prototype, "maxDistance", {
|
|
234
|
-
get: function () {
|
|
235
|
-
return this._maxDistance;
|
|
236
|
-
},
|
|
237
|
-
set: function (val) {
|
|
238
|
-
if (this._maxDistance === val)
|
|
239
|
-
return;
|
|
240
|
-
this._maxDistance = val;
|
|
241
|
-
this._needUpdateSpatialDistanceSettings = true;
|
|
242
|
-
},
|
|
243
|
-
enumerable: false,
|
|
244
|
-
configurable: true
|
|
245
|
-
});
|
|
246
|
-
Object.defineProperty(AudioSource.prototype, "volume", {
|
|
247
|
-
get: function () { return this._volume; },
|
|
248
|
-
set: function (val) {
|
|
249
|
-
this._volume = val;
|
|
250
|
-
if (this.sound && !this.context.application.muted) {
|
|
251
|
-
if (debug)
|
|
252
|
-
console.log(this.name, "audio set volume", val);
|
|
253
|
-
this.sound.setVolume(val);
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
enumerable: false,
|
|
257
|
-
configurable: true
|
|
258
|
-
});
|
|
259
|
-
Object.defineProperty(AudioSource.prototype, "Sound", {
|
|
260
|
-
get: function () {
|
|
261
|
-
var _a;
|
|
262
|
-
if (!this.sound && AudioSource._userInteractionRegistered) {
|
|
263
|
-
var listener = (_a = Component_js_1.GameObject.getComponent(this.context.mainCamera, AudioListener_js_1.AudioListener)) !== null && _a !== void 0 ? _a : Component_js_1.GameObject.findObjectOfType(AudioListener_js_1.AudioListener, this.context);
|
|
264
|
-
if (!listener && this.context.mainCamera)
|
|
265
|
-
listener = Component_js_1.GameObject.addNewComponent(this.context.mainCamera, AudioListener_js_1.AudioListener);
|
|
266
|
-
if (listener === null || listener === void 0 ? void 0 : listener.listener) {
|
|
267
|
-
this.sound = new three_1.PositionalAudio(listener.listener);
|
|
268
|
-
this.gameObject.add(this.sound);
|
|
269
|
-
}
|
|
270
|
-
else if (debug)
|
|
271
|
-
console.warn("No audio listener found in scene - can not play audio");
|
|
272
|
-
}
|
|
273
|
-
return this.sound;
|
|
274
|
-
},
|
|
275
|
-
enumerable: false,
|
|
276
|
-
configurable: true
|
|
277
|
-
});
|
|
278
|
-
Object.defineProperty(AudioSource.prototype, "ShouldPlay", {
|
|
279
|
-
get: function () { return this.shouldPlay; },
|
|
280
|
-
enumerable: false,
|
|
281
|
-
configurable: true
|
|
282
|
-
});
|
|
283
|
-
AudioSource.prototype.awake = function () {
|
|
284
|
-
this.audioLoader = new three_1.AudioLoader();
|
|
285
|
-
if (this.playOnAwake)
|
|
286
|
-
this.shouldPlay = true;
|
|
287
|
-
};
|
|
288
|
-
AudioSource.prototype.onEnable = function () {
|
|
289
|
-
var _this = this;
|
|
290
|
-
if (!AudioSource._userInteractionRegistered) {
|
|
291
|
-
AudioSource._beginWaitForUserInteraction(function () {
|
|
292
|
-
if (_this.enabled && !_this.destroyed && _this.shouldPlay)
|
|
293
|
-
_this.onNewClip(_this.clip);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
else if (this.playOnAwake && this.context.application.isVisible) {
|
|
297
|
-
this.play();
|
|
298
|
-
}
|
|
299
|
-
globalThis.addEventListener('visibilitychange', this.onVisibilityChanged);
|
|
300
|
-
this.context.application.addEventListener(engine_application_js_1.ApplicationEvents.MuteChanged, this.onApplicationMuteChanged);
|
|
301
|
-
};
|
|
302
|
-
AudioSource.prototype.onDisable = function () {
|
|
303
|
-
globalThis.removeEventListener('visibilitychange', this.onVisibilityChanged);
|
|
304
|
-
this.context.application.removeEventListener(engine_application_js_1.ApplicationEvents.MuteChanged, this.onApplicationMuteChanged);
|
|
305
|
-
this.stop();
|
|
306
|
-
};
|
|
307
|
-
AudioSource.prototype.applySpatialDistanceSettings = function () {
|
|
308
|
-
var sound = this.sound;
|
|
309
|
-
if (!sound)
|
|
310
|
-
return;
|
|
311
|
-
this._needUpdateSpatialDistanceSettings = false;
|
|
312
|
-
var dist = this.lerp(10 * this._maxDistance / Math.max(0.0001, this.spatialBlend), this._minDistance, this.spatialBlend);
|
|
313
|
-
if (debug)
|
|
314
|
-
console.log(this.name, this._minDistance, this._maxDistance, this.spatialBlend, "Ref distance=" + dist);
|
|
315
|
-
sound.setRefDistance(dist);
|
|
316
|
-
sound.setMaxDistance(Math.max(0.01, this._maxDistance));
|
|
317
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/PannerNode/distanceModel
|
|
318
|
-
switch (this.rollOffMode) {
|
|
319
|
-
case AudioRolloffMode.Logarithmic:
|
|
320
|
-
sound.setDistanceModel('exponential');
|
|
321
|
-
break;
|
|
322
|
-
case AudioRolloffMode.Linear:
|
|
323
|
-
sound.setDistanceModel('linear');
|
|
324
|
-
break;
|
|
325
|
-
case AudioRolloffMode.Custom:
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
if (this.spatialBlend > 0) {
|
|
329
|
-
if (debug && !this.helper) {
|
|
330
|
-
this.helper = new PositionalAudioHelper_js_1.PositionalAudioHelper(sound, sound.getRefDistance());
|
|
331
|
-
sound.add(this.helper);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
else if (this.helper && this.helper.parent) {
|
|
335
|
-
this.helper.removeFromParent();
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
AudioSource.prototype.onNewClip = function (clip) {
|
|
339
|
-
if (clip)
|
|
340
|
-
this.clip = clip;
|
|
341
|
-
if (typeof clip === "string") {
|
|
342
|
-
if (debug)
|
|
343
|
-
console.log(clip);
|
|
344
|
-
if (clip.endsWith(".mp3") || clip.endsWith(".wav")) {
|
|
345
|
-
if (!this.audioLoader)
|
|
346
|
-
this.audioLoader = new three_1.AudioLoader();
|
|
347
|
-
this.shouldPlay = true;
|
|
348
|
-
if (this._lastClipStartedLoading === clip) {
|
|
349
|
-
if (debug)
|
|
350
|
-
console.log("Is currently loading:", this._lastClipStartedLoading, this);
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
this._lastClipStartedLoading = clip;
|
|
354
|
-
if (debug)
|
|
355
|
-
console.log("load audio", clip);
|
|
356
|
-
this.audioLoader.load(clip, this.createAudio, function () { }, console.error);
|
|
357
|
-
}
|
|
358
|
-
else
|
|
359
|
-
console.warn("Unsupported audio clip type", clip);
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
this.shouldPlay = true;
|
|
363
|
-
this.createAudio();
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
/** Play a mediastream */
|
|
367
|
-
AudioSource.prototype.play = function (clip) {
|
|
368
|
-
var _a, _b;
|
|
369
|
-
if (clip === void 0) { clip = undefined; }
|
|
370
|
-
// We only support strings and media stream
|
|
371
|
-
// TODO: maybe we should return here if an invalid value is passed in
|
|
372
|
-
if (clip !== undefined && typeof clip !== "string" && !(clip instanceof MediaStream)) {
|
|
373
|
-
console.warn("Called play on AudioSource with unknown argument type", clip);
|
|
374
|
-
clip = undefined;
|
|
375
|
-
}
|
|
376
|
-
// Check if we need to call load first
|
|
377
|
-
var needsLoading = !this.sound || (clip && clip !== this.clip);
|
|
378
|
-
if (typeof clip === "string" && !this.audioLoader)
|
|
379
|
-
needsLoading = true;
|
|
380
|
-
if (clip instanceof MediaStream || typeof clip === "string")
|
|
381
|
-
this.clip = clip;
|
|
382
|
-
if (needsLoading) {
|
|
383
|
-
this.shouldPlay = true;
|
|
384
|
-
this.onNewClip(clip);
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
this.shouldPlay = true;
|
|
388
|
-
this._hasEnded = false;
|
|
389
|
-
if (debug)
|
|
390
|
-
console.log("play", (_a = this.sound) === null || _a === void 0 ? void 0 : _a.getVolume(), this.sound);
|
|
391
|
-
if (this.sound && !this.sound.isPlaying) {
|
|
392
|
-
var muted = this.context.application.muted;
|
|
393
|
-
if (muted)
|
|
394
|
-
this.sound.setVolume(0);
|
|
395
|
-
if (this.clip instanceof MediaStream) {
|
|
396
|
-
// We have to set the audio element source to the mediastream as well
|
|
397
|
-
// otherwise it will not play for some reason...
|
|
398
|
-
this.sound.setMediaStreamSource(this.clip);
|
|
399
|
-
if (!this._audioElement) {
|
|
400
|
-
this._audioElement = document.createElement('audio');
|
|
401
|
-
this._audioElement.style.display = "none";
|
|
402
|
-
}
|
|
403
|
-
if (!this._audioElement.parentNode)
|
|
404
|
-
(_b = this.context.domElement.shadowRoot) === null || _b === void 0 ? void 0 : _b.append(this._audioElement);
|
|
405
|
-
this._audioElement.srcObject = this.clip;
|
|
406
|
-
this._audioElement.autoplay = false;
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
if (this._audioElement)
|
|
410
|
-
this._audioElement.remove();
|
|
411
|
-
this.sound.play(muted ? .1 : 0);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
AudioSource.prototype.pause = function () {
|
|
416
|
-
var _a, _b;
|
|
417
|
-
if (debug)
|
|
418
|
-
console.log("Pause", this);
|
|
419
|
-
this._hasEnded = true;
|
|
420
|
-
this.shouldPlay = false;
|
|
421
|
-
if (this.sound && this.sound.isPlaying && this.sound.source) {
|
|
422
|
-
this._lastContextTime = (_a = this.sound) === null || _a === void 0 ? void 0 : _a.context.currentTime;
|
|
423
|
-
this.sound.pause();
|
|
424
|
-
}
|
|
425
|
-
(_b = this._audioElement) === null || _b === void 0 ? void 0 : _b.remove();
|
|
426
|
-
};
|
|
427
|
-
AudioSource.prototype.stop = function () {
|
|
428
|
-
var _a, _b;
|
|
429
|
-
if (debug)
|
|
430
|
-
console.log("Pause", this);
|
|
431
|
-
this._hasEnded = true;
|
|
432
|
-
this.shouldPlay = false;
|
|
433
|
-
if (this.sound && this.sound.source) {
|
|
434
|
-
this._lastContextTime = (_a = this.sound) === null || _a === void 0 ? void 0 : _a.context.currentTime;
|
|
435
|
-
if (debug)
|
|
436
|
-
console.log(this._lastContextTime);
|
|
437
|
-
this.sound.stop();
|
|
438
|
-
}
|
|
439
|
-
(_b = this._audioElement) === null || _b === void 0 ? void 0 : _b.remove();
|
|
440
|
-
};
|
|
441
|
-
Object.defineProperty(AudioSource.prototype, "isPlaying", {
|
|
442
|
-
get: function () { var _a, _b; return (_b = (_a = this.sound) === null || _a === void 0 ? void 0 : _a.isPlaying) !== null && _b !== void 0 ? _b : false; },
|
|
443
|
-
set: function (_) { },
|
|
444
|
-
enumerable: false,
|
|
445
|
-
configurable: true
|
|
446
|
-
});
|
|
447
|
-
Object.defineProperty(AudioSource.prototype, "time", {
|
|
448
|
-
get: function () { var _a, _b; return ((_a = this.sound) === null || _a === void 0 ? void 0 : _a.source) ? (((_b = this.sound.source) === null || _b === void 0 ? void 0 : _b.context.currentTime) - this._lastContextTime + this.sound.offset) : 0; },
|
|
449
|
-
set: function (val) {
|
|
450
|
-
if (this.sound) {
|
|
451
|
-
if (val === this.sound.offset)
|
|
452
|
-
return;
|
|
453
|
-
var wasPlaying = this.isPlaying;
|
|
454
|
-
this.stop();
|
|
455
|
-
this.sound.offset = val;
|
|
456
|
-
if (wasPlaying)
|
|
457
|
-
this.play();
|
|
458
|
-
}
|
|
459
|
-
},
|
|
460
|
-
enumerable: false,
|
|
461
|
-
configurable: true
|
|
462
|
-
});
|
|
463
|
-
AudioSource.prototype.update = function () {
|
|
464
|
-
if (this.helper) {
|
|
465
|
-
if (this.isPlaying)
|
|
466
|
-
this.helper.update();
|
|
467
|
-
this.helper.visible = this.isPlaying;
|
|
468
|
-
}
|
|
469
|
-
if (this._needUpdateSpatialDistanceSettings) {
|
|
470
|
-
this.applySpatialDistanceSettings();
|
|
471
|
-
}
|
|
472
|
-
if (this.sound && !this.sound.isPlaying && this.shouldPlay && !this._hasEnded) {
|
|
473
|
-
this._hasEnded = true;
|
|
474
|
-
if (debug)
|
|
475
|
-
console.log("Audio clip ended", this.clip);
|
|
476
|
-
this.sound.dispatchEvent({ type: 'ended', target: this });
|
|
477
|
-
}
|
|
478
|
-
// this.gameObject.position.x = Math.sin(time.time) * 2;
|
|
479
|
-
// this.gameObject.position.z = Math.cos(time.time * .5) * 2;
|
|
480
|
-
};
|
|
481
|
-
AudioSource._didCallBeginWaitForUserInteraction = false;
|
|
482
|
-
AudioSource.callbacks = [];
|
|
483
|
-
AudioSource._userInteractionRegistered = false;
|
|
484
|
-
__decorate([
|
|
485
|
-
engine_serialization_decorator_js_1.serializable(URL)
|
|
486
|
-
], AudioSource.prototype, "clip");
|
|
487
|
-
__decorate([
|
|
488
|
-
engine_serialization_decorator_js_1.serializable()
|
|
489
|
-
], AudioSource.prototype, "playOnAwake");
|
|
490
|
-
__decorate([
|
|
491
|
-
engine_serialization_decorator_js_1.serializable()
|
|
492
|
-
], AudioSource.prototype, "loop");
|
|
493
|
-
__decorate([
|
|
494
|
-
engine_serialization_decorator_js_1.serializable()
|
|
495
|
-
], AudioSource.prototype, "spatialBlend");
|
|
496
|
-
__decorate([
|
|
497
|
-
engine_serialization_decorator_js_1.serializable()
|
|
498
|
-
], AudioSource.prototype, "minDistance");
|
|
499
|
-
__decorate([
|
|
500
|
-
engine_serialization_decorator_js_1.serializable()
|
|
501
|
-
], AudioSource.prototype, "maxDistance");
|
|
502
|
-
__decorate([
|
|
503
|
-
engine_serialization_decorator_js_1.serializable()
|
|
504
|
-
], AudioSource.prototype, "volume");
|
|
505
|
-
__decorate([
|
|
506
|
-
engine_serialization_decorator_js_1.serializable()
|
|
507
|
-
], AudioSource.prototype, "rollOffMode");
|
|
508
|
-
__decorate([
|
|
509
|
-
engine_serialization_decorator_js_1.serializable()
|
|
510
|
-
], AudioSource.prototype, "playInBackground");
|
|
511
|
-
return AudioSource;
|
|
512
|
-
}(Component_js_1.Behaviour));
|
|
513
|
-
exports.AudioSource = AudioSource;
|