@needle-tools/engine 3.27.5-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.
Files changed (50) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/needle-engine.js +4692 -4719
  3. package/dist/needle-engine.light.js +4434 -4461
  4. package/dist/needle-engine.light.min.js +226 -219
  5. package/dist/needle-engine.light.umd.cjs +283 -276
  6. package/dist/needle-engine.min.js +228 -221
  7. package/dist/needle-engine.umd.cjs +238 -231
  8. package/lib/engine/engine_shims.js +0 -1
  9. package/lib/engine/engine_shims.js.map +1 -1
  10. package/lib/engine-components/Renderer.js +12 -0
  11. package/lib/engine-components/Renderer.js.map +1 -1
  12. package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +14 -5
  13. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +26 -15
  14. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
  15. package/package.json +1 -1
  16. package/src/engine/codegen/register_types.ts +2 -2
  17. package/src/engine/engine_shims.ts +0 -2
  18. package/src/engine-components/Renderer.ts +13 -0
  19. package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +36 -24
  20. package/src/engine/dist/api.js +0 -73
  21. package/src/engine/dist/api.js.meta +0 -7
  22. package/src/engine/dist/engine_networking_streams.js +0 -474
  23. package/src/engine/dist/engine_networking_streams.js.meta +0 -7
  24. package/src/engine-components/dist/AudioSource.js +0 -513
  25. package/src/engine-components/dist/AudioSource.js.meta +0 -7
  26. package/src/engine-components/dist/ScreenCapture.js +0 -490
  27. package/src/engine-components/dist/ScreenCapture.js.meta +0 -7
  28. package/src/engine-components/dist/VideoPlayer.js +0 -888
  29. package/src/engine-components/dist/VideoPlayer.js.meta +0 -7
  30. package/src/engine-components/dist/Voip2.js +0 -46
  31. package/src/engine-components/dist/Voip2.js.meta +0 -7
  32. package/src/engine-schemes/dist/api.js +0 -17
  33. package/src/engine-schemes/dist/api.js.meta +0 -7
  34. package/src/engine-schemes/dist/schemes.js +0 -25
  35. package/src/engine-schemes/dist/schemes.js.meta +0 -7
  36. package/src/engine-schemes/dist/synced-camera-model.js +0 -74
  37. package/src/engine-schemes/dist/synced-camera-model.js.meta +0 -7
  38. package/src/engine-schemes/dist/synced-transform-model.js +0 -73
  39. package/src/engine-schemes/dist/synced-transform-model.js.meta +0 -7
  40. package/src/engine-schemes/dist/transform.js +0 -46
  41. package/src/engine-schemes/dist/transform.js.meta +0 -7
  42. package/src/engine-schemes/dist/vec2.js +0 -32
  43. package/src/engine-schemes/dist/vec2.js.meta +0 -7
  44. package/src/engine-schemes/dist/vec3.js +0 -36
  45. package/src/engine-schemes/dist/vec3.js.meta +0 -7
  46. package/src/engine-schemes/dist/vec4.js +0 -40
  47. package/src/engine-schemes/dist/vec4.js.meta +0 -7
  48. package/src/engine-schemes/dist/vr-user-state-buffer.js +0 -110
  49. package/src/engine-schemes/dist/vr-user-state-buffer.js.meta +0 -7
  50. package/src/engine-schemes/flatc.exe +0 -0
@@ -1,888 +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
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- exports.__esModule = true;
49
- exports.VideoPlayer = exports.VideoRenderMode = exports.VideoAudioOutputMode = exports.VideoSource = exports.AspectMode = void 0;
50
- var Component_js_1 = require("./Component.js");
51
- var engine_serialization_decorator_js_1 = require("../engine/engine_serialization_decorator.js");
52
- var three_1 = require("three");
53
- var engine_input_utils_js_1 = require("../engine/engine_input_utils.js");
54
- var engine_utils_js_1 = require("../engine/engine_utils.js");
55
- var Renderer_js_1 = require("./Renderer.js");
56
- var engine_three_utils_js_1 = require("../engine/engine_three_utils.js");
57
- var engine_create_objects_js_1 = require("../engine/engine_create_objects.js");
58
- var index_js_1 = require("../engine/debug/index.js");
59
- var debug = engine_utils_js_1.getParam("debugvideo");
60
- var AspectMode;
61
- (function (AspectMode) {
62
- AspectMode[AspectMode["None"] = 0] = "None";
63
- AspectMode[AspectMode["AdjustHeight"] = 1] = "AdjustHeight";
64
- AspectMode[AspectMode["AdjustWidth"] = 2] = "AdjustWidth";
65
- })(AspectMode = exports.AspectMode || (exports.AspectMode = {}));
66
- var VideoSource;
67
- (function (VideoSource) {
68
- /// <summary>
69
- /// <para>Use the current clip as the video content source.</para>
70
- /// </summary>
71
- VideoSource[VideoSource["VideoClip"] = 0] = "VideoClip";
72
- /// <summary>
73
- /// <para>Use the current URL as the video content source.</para>
74
- /// </summary>
75
- VideoSource[VideoSource["Url"] = 1] = "Url";
76
- })(VideoSource = exports.VideoSource || (exports.VideoSource = {}));
77
- var VideoAudioOutputMode;
78
- (function (VideoAudioOutputMode) {
79
- VideoAudioOutputMode[VideoAudioOutputMode["None"] = 0] = "None";
80
- VideoAudioOutputMode[VideoAudioOutputMode["AudioSource"] = 1] = "AudioSource";
81
- VideoAudioOutputMode[VideoAudioOutputMode["Direct"] = 2] = "Direct";
82
- VideoAudioOutputMode[VideoAudioOutputMode["APIOnly"] = 3] = "APIOnly";
83
- })(VideoAudioOutputMode = exports.VideoAudioOutputMode || (exports.VideoAudioOutputMode = {}));
84
- var VideoRenderMode;
85
- (function (VideoRenderMode) {
86
- VideoRenderMode[VideoRenderMode["CameraFarPlane"] = 0] = "CameraFarPlane";
87
- VideoRenderMode[VideoRenderMode["CameraNearPlane"] = 1] = "CameraNearPlane";
88
- VideoRenderMode[VideoRenderMode["RenderTexture"] = 2] = "RenderTexture";
89
- VideoRenderMode[VideoRenderMode["MaterialOverride"] = 3] = "MaterialOverride";
90
- })(VideoRenderMode = exports.VideoRenderMode || (exports.VideoRenderMode = {}));
91
- var VideoPlayer = /** @class */ (function (_super) {
92
- __extends(VideoPlayer, _super);
93
- function VideoPlayer() {
94
- var _this = _super.call(this) || this;
95
- _this.playOnAwake = true;
96
- _this.aspectMode = AspectMode.None;
97
- _this.clip = null;
98
- _this.time = 0;
99
- _this._playbackSpeed = 1;
100
- _this._isLooping = false;
101
- _this._muted = false;
102
- _this._audioOutputMode = VideoAudioOutputMode.Direct;
103
- /** Set this to false to pause video playback while the tab is not active */
104
- _this.playInBackground = true;
105
- _this._crossOrigin = "anonymous";
106
- // set a default src, this should not be undefined
107
- _this.source = VideoSource.Url;
108
- _this.url = null;
109
- _this._videoElement = null;
110
- _this._videoTexture = null;
111
- _this._videoMaterial = null;
112
- _this._isPlaying = false;
113
- _this.wasPlaying = false;
114
- _this.visibilityChanged = function (_) {
115
- switch (document.visibilityState) {
116
- case "hidden":
117
- if (!_this.playInBackground) {
118
- _this.wasPlaying = _this._isPlaying;
119
- _this.pause();
120
- }
121
- break;
122
- case "visible":
123
- if (_this.wasPlaying && !_this._isPlaying)
124
- _this.play();
125
- break;
126
- }
127
- };
128
- _this._receivedInput = false;
129
- _this._overlay = null;
130
- _this._updateAspectRoutineId = -1;
131
- engine_input_utils_js_1.awaitInput(function () {
132
- _this._receivedInput = true;
133
- _this.updateVideoElementSettings();
134
- });
135
- _this._targetObjects = [];
136
- if (engine_utils_js_1.getParam("videoscreenspace")) {
137
- window.addEventListener("keydown", function (evt) {
138
- if (evt.key === "f") {
139
- _this.screenspace = !_this.screenspace;
140
- }
141
- });
142
- }
143
- return _this;
144
- }
145
- Object.defineProperty(VideoPlayer.prototype, "playbackSpeed", {
146
- get: function () {
147
- var _a, _b;
148
- return (_b = (_a = this._videoElement) === null || _a === void 0 ? void 0 : _a.playbackRate) !== null && _b !== void 0 ? _b : this._playbackSpeed;
149
- },
150
- set: function (val) {
151
- this._playbackSpeed = val;
152
- if (this._videoElement)
153
- this._videoElement.playbackRate = val;
154
- },
155
- enumerable: false,
156
- configurable: true
157
- });
158
- Object.defineProperty(VideoPlayer.prototype, "isLooping", {
159
- get: function () {
160
- var _a, _b;
161
- return (_b = (_a = this._videoElement) === null || _a === void 0 ? void 0 : _a.loop) !== null && _b !== void 0 ? _b : this._isLooping;
162
- },
163
- set: function (val) {
164
- this._isLooping = val;
165
- if (this._videoElement)
166
- this._videoElement.loop = val;
167
- },
168
- enumerable: false,
169
- configurable: true
170
- });
171
- Object.defineProperty(VideoPlayer.prototype, "currentTime", {
172
- get: function () {
173
- var _a, _b;
174
- return (_b = (_a = this._videoElement) === null || _a === void 0 ? void 0 : _a.currentTime) !== null && _b !== void 0 ? _b : this.time;
175
- },
176
- set: function (val) {
177
- if (this._videoElement) {
178
- this._videoElement.currentTime = val;
179
- }
180
- else
181
- this.time = val;
182
- },
183
- enumerable: false,
184
- configurable: true
185
- });
186
- Object.defineProperty(VideoPlayer.prototype, "isPlaying", {
187
- get: function () {
188
- var video = this._videoElement;
189
- if (video) {
190
- if (video.currentTime > 0 && !video.paused && !video.ended
191
- && video.readyState > video.HAVE_CURRENT_DATA)
192
- return true;
193
- else if (video.srcObject) {
194
- var stream = video.srcObject;
195
- if (stream.active)
196
- return true;
197
- }
198
- }
199
- return false;
200
- },
201
- enumerable: false,
202
- configurable: true
203
- });
204
- Object.defineProperty(VideoPlayer.prototype, "crossOrigin", {
205
- get: function () {
206
- var _a, _b;
207
- return (_b = (_a = this._videoElement) === null || _a === void 0 ? void 0 : _a.crossOrigin) !== null && _b !== void 0 ? _b : this._crossOrigin;
208
- },
209
- set: function (val) {
210
- this._crossOrigin = val;
211
- if (this._videoElement) {
212
- if (val !== null)
213
- this._videoElement.setAttribute("crossorigin", val);
214
- else
215
- this._videoElement.removeAttribute("crossorigin");
216
- }
217
- },
218
- enumerable: false,
219
- configurable: true
220
- });
221
- Object.defineProperty(VideoPlayer.prototype, "videoMaterial", {
222
- get: function () {
223
- return this._videoMaterial;
224
- },
225
- enumerable: false,
226
- configurable: true
227
- });
228
- Object.defineProperty(VideoPlayer.prototype, "videoTexture", {
229
- get: function () {
230
- return this._videoTexture;
231
- },
232
- enumerable: false,
233
- configurable: true
234
- });
235
- Object.defineProperty(VideoPlayer.prototype, "videoElement", {
236
- get: function () {
237
- return this._videoElement;
238
- },
239
- enumerable: false,
240
- configurable: true
241
- });
242
- Object.defineProperty(VideoPlayer.prototype, "muted", {
243
- get: function () {
244
- var _a, _b;
245
- return (_b = (_a = this._videoElement) === null || _a === void 0 ? void 0 : _a.muted) !== null && _b !== void 0 ? _b : this._muted;
246
- },
247
- set: function (val) {
248
- this._muted = val;
249
- if (this._videoElement)
250
- this._videoElement.muted = val;
251
- },
252
- enumerable: false,
253
- configurable: true
254
- });
255
- Object.defineProperty(VideoPlayer.prototype, "audioOutputMode", {
256
- get: function () { return this._audioOutputMode; },
257
- set: function (mode) {
258
- if (mode !== this._audioOutputMode) {
259
- if (mode === VideoAudioOutputMode.AudioSource && index_js_1.isDevEnvironment())
260
- console.warn("VideoAudioOutputMode.AudioSource is not yet implemented");
261
- this._audioOutputMode = mode;
262
- this.updateVideoElementSettings();
263
- }
264
- },
265
- enumerable: false,
266
- configurable: true
267
- });
268
- VideoPlayer.prototype.setVideo = function (video) {
269
- this.clip = video;
270
- this.source = VideoSource.VideoClip;
271
- if (!this._videoElement)
272
- this.create(true);
273
- else {
274
- // TODO: how to prevent interruption error when another video is already playing
275
- this._videoElement.srcObject = video;
276
- if (this._isPlaying)
277
- this.play();
278
- this.updateAspect();
279
- }
280
- };
281
- VideoPlayer.prototype.setClipURL = function (url) {
282
- if (this.url === url)
283
- return;
284
- // console.log("SET URL", url);
285
- this.url = url;
286
- this.source = VideoSource.Url;
287
- if (debug)
288
- console.log("set url", url);
289
- if (!this._videoElement)
290
- this.create(true);
291
- else {
292
- this._videoElement.src = url;
293
- if (this._isPlaying) {
294
- this.stop();
295
- this.play();
296
- }
297
- }
298
- };
299
- VideoPlayer.prototype.onEnable = function () {
300
- var _a, _b;
301
- if (debug)
302
- console.log("VideoPlayer.onEnable", this);
303
- window.addEventListener('visibilitychange', this.visibilityChanged);
304
- if (this.playOnAwake === true) {
305
- this.create(true);
306
- }
307
- if (this.screenspace) {
308
- (_a = this._overlay) === null || _a === void 0 ? void 0 : _a.start();
309
- }
310
- else
311
- (_b = this._overlay) === null || _b === void 0 ? void 0 : _b.stop();
312
- };
313
- VideoPlayer.prototype.onDisable = function () {
314
- var _a;
315
- window.removeEventListener('visibilitychange', this.visibilityChanged);
316
- (_a = this._overlay) === null || _a === void 0 ? void 0 : _a.stop();
317
- this.pause();
318
- };
319
- VideoPlayer.prototype.onDestroy = function () {
320
- var _a;
321
- if (this._videoElement) {
322
- (_a = this._videoElement.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(this._videoElement);
323
- this._videoElement = null;
324
- }
325
- if (this._videoTexture) {
326
- this._videoTexture.dispose();
327
- this._videoTexture = null;
328
- }
329
- };
330
- VideoPlayer.prototype.play = function () {
331
- var _this = this;
332
- var _a, _b;
333
- if (!this._videoElement)
334
- this.create(false);
335
- if (!this._videoElement)
336
- return;
337
- if (this._isPlaying && !((_a = this._videoElement) === null || _a === void 0 ? void 0 : _a.ended) && !((_b = this._videoElement) === null || _b === void 0 ? void 0 : _b.paused))
338
- return;
339
- this._isPlaying = true;
340
- if (!this._receivedInput)
341
- this._videoElement.muted = true;
342
- this.updateVideoElementSettings();
343
- this._videoElement.currentTime = this.time;
344
- this._videoElement.play()["catch"](function (err) {
345
- var _a;
346
- console.log(err);
347
- // https://developer.chrome.com/blog/play-request-was-interrupted/
348
- if (debug)
349
- console.error("Error playing video", err, "CODE=" + err.code, (_a = _this.videoElement) === null || _a === void 0 ? void 0 : _a.src, _this);
350
- setTimeout(function () {
351
- if (_this._isPlaying && !_this.destroyed && _this.activeAndEnabled)
352
- _this.play();
353
- }, 1000);
354
- });
355
- if (debug)
356
- console.log("play", this._videoElement, this.time);
357
- };
358
- VideoPlayer.prototype.stop = function () {
359
- this._isPlaying = false;
360
- this.time = 0;
361
- if (!this._videoElement)
362
- return;
363
- this._videoElement.currentTime = 0;
364
- this._videoElement.pause();
365
- if (debug)
366
- console.log("STOP", this);
367
- };
368
- VideoPlayer.prototype.pause = function () {
369
- var _a, _b, _c;
370
- this.time = (_b = (_a = this._videoElement) === null || _a === void 0 ? void 0 : _a.currentTime) !== null && _b !== void 0 ? _b : 0;
371
- this._isPlaying = false;
372
- (_c = this._videoElement) === null || _c === void 0 ? void 0 : _c.pause();
373
- if (debug)
374
- console.log("PAUSE", this, this.currentTime);
375
- };
376
- VideoPlayer.prototype.create = function (playAutomatically) {
377
- var _a;
378
- var src;
379
- switch (this.source) {
380
- case VideoSource.VideoClip:
381
- src = this.clip;
382
- break;
383
- case VideoSource.Url:
384
- src = this.url;
385
- if (!(src === null || src === void 0 ? void 0 : src.length) && typeof this.clip === "string")
386
- src = this.clip;
387
- break;
388
- }
389
- if (!src) {
390
- if (debug)
391
- console.warn("No video source set", this);
392
- return;
393
- }
394
- if (!this._videoElement) {
395
- if (debug)
396
- console.warn("Create VideoElement", this);
397
- this._videoElement = this.createVideoElement();
398
- (_a = this.context.domElement) === null || _a === void 0 ? void 0 : _a.prepend(this._videoElement);
399
- // hide it because otherwise it would overlay the website with default css
400
- this.updateVideoElementStyles();
401
- }
402
- if (typeof src === "string") {
403
- if (debug)
404
- console.log("Set Video src", src);
405
- this._videoElement.src = src;
406
- // Nor sure why we did this here, but with this code the video does not restart when being paused / enable toggled
407
- // const str = this._videoElement["captureStream"]?.call(this._videoElement);
408
- // this.clip = str;
409
- }
410
- else {
411
- if (debug)
412
- console.log("Set Video srcObject", src);
413
- this._videoElement.srcObject = src;
414
- }
415
- if (!this._videoTexture)
416
- this._videoTexture = new three_1.VideoTexture(this._videoElement);
417
- this._videoTexture.flipY = false;
418
- this._videoTexture.colorSpace = three_1.SRGBColorSpace;
419
- this.handleBeginPlaying(playAutomatically);
420
- if (debug)
421
- console.log(this, playAutomatically);
422
- };
423
- VideoPlayer.prototype.updateAspect = function () {
424
- if (this.aspectMode === AspectMode.None)
425
- return;
426
- this.startCoroutine(this.updateAspectImpl());
427
- };
428
- Object.defineProperty(VideoPlayer.prototype, "screenspace", {
429
- get: function () {
430
- var _a, _b;
431
- return (_b = (_a = this._overlay) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false;
432
- },
433
- set: function (val) {
434
- var _a;
435
- if (val) {
436
- if (!this._videoTexture)
437
- return;
438
- if (!this._overlay)
439
- this._overlay = new VideoOverlay(this.context);
440
- this._overlay.add(this._videoTexture);
441
- }
442
- else
443
- (_a = this._overlay) === null || _a === void 0 ? void 0 : _a.remove(this._videoTexture);
444
- if (this._overlay)
445
- this._overlay.enabled = val;
446
- },
447
- enumerable: false,
448
- configurable: true
449
- });
450
- VideoPlayer.prototype.createVideoElement = function () {
451
- var video = document.createElement("video");
452
- if (this._crossOrigin)
453
- video.setAttribute("crossorigin", this._crossOrigin);
454
- if (debug)
455
- console.log("created video element", video);
456
- return video;
457
- };
458
- VideoPlayer.prototype.handleBeginPlaying = function (playAutomatically) {
459
- var _a, _b;
460
- if (!this.enabled)
461
- return;
462
- if (!this._videoElement)
463
- return;
464
- this._targetObjects.length = 0;
465
- var target = this.gameObject;
466
- switch (this.renderMode) {
467
- case VideoRenderMode.MaterialOverride:
468
- target = (_a = this.targetMaterialRenderer) === null || _a === void 0 ? void 0 : _a.gameObject;
469
- if (!target)
470
- target = (_b = Component_js_1.GameObject.getComponent(this.gameObject, Renderer_js_1.Renderer)) === null || _b === void 0 ? void 0 : _b.gameObject;
471
- break;
472
- case VideoRenderMode.RenderTexture:
473
- console.error("VideoPlayer renderTexture not implemented yet. Please use material override instead");
474
- return;
475
- }
476
- if (!target) {
477
- console.error("Missing target for video material renderer", this.name, VideoRenderMode[this.renderMode], this);
478
- return;
479
- }
480
- var mat = target["material"];
481
- if (mat) {
482
- this._targetObjects.push(target);
483
- if (mat !== this._videoMaterial) {
484
- this._videoMaterial = mat.clone();
485
- target["material"] = this._videoMaterial;
486
- }
487
- var fieldName = "map";
488
- var videoMaterial = this._videoMaterial;
489
- if (!this.targetMaterialProperty) {
490
- videoMaterial[fieldName] = this._videoTexture;
491
- }
492
- else {
493
- switch (this.targetMaterialProperty) {
494
- default:
495
- videoMaterial[fieldName] = this._videoTexture;
496
- break;
497
- // doesnt render:
498
- // case "emissiveTexture":
499
- // console.log(this.videoMaterial);
500
- // // (this.videoMaterial as any).map = this.videoTexture;
501
- // (this.videoMaterial as any).emissive?.set(1,1,1);// = this.videoTexture;
502
- // (this.videoMaterial as any).emissiveMap = this.videoTexture;
503
- // break;
504
- }
505
- }
506
- }
507
- else {
508
- console.warn("Can not play video, no material found, this might be a multimaterial case which is not supported yet");
509
- return;
510
- }
511
- this.updateVideoElementSettings();
512
- this.updateVideoElementStyles();
513
- if (playAutomatically)
514
- this.play();
515
- };
516
- VideoPlayer.prototype.updateVideoElementSettings = function () {
517
- if (!this._videoElement)
518
- return;
519
- this._videoElement.loop = this._isLooping;
520
- this._videoElement.currentTime = this.currentTime;
521
- this._videoElement.playbackRate = this._playbackSpeed;
522
- // dont open in fullscreen on ios
523
- this._videoElement.playsInline = true;
524
- var muted = !this._receivedInput || this.audioOutputMode === VideoAudioOutputMode.None;
525
- if (!muted && this._muted)
526
- muted = true;
527
- this._videoElement.muted = muted;
528
- if (this.playOnAwake)
529
- this._videoElement.autoplay = true;
530
- };
531
- VideoPlayer.prototype.updateVideoElementStyles = function () {
532
- if (!this._videoElement)
533
- return;
534
- // set style here so preview frame is rendered
535
- // set display and selectable because otherwise is interfers with input/focus e.g. breaks orbit control
536
- this._videoElement.style.userSelect = "none";
537
- this._videoElement.style.visibility = "hidden";
538
- this._videoElement.style.display = "none";
539
- this.updateAspect();
540
- };
541
- VideoPlayer.prototype.updateAspectImpl = function () {
542
- var id, lastAspect, stream, aspect, _i, _a, track, settings, i, _b, _c, obj, worldAspect, parentScale, i;
543
- return __generator(this, function (_d) {
544
- switch (_d.label) {
545
- case 0:
546
- id = ++this._updateAspectRoutineId;
547
- lastAspect = undefined;
548
- stream = this.clip;
549
- _d.label = 1;
550
- case 1:
551
- if (!(id === this._updateAspectRoutineId && this.aspectMode !== AspectMode.None && this.clip && stream === this.clip && this._isPlaying)) return [3 /*break*/, 13];
552
- if (!stream || typeof stream === "string") {
553
- return [2 /*return*/];
554
- }
555
- aspect = undefined;
556
- for (_i = 0, _a = stream.getVideoTracks(); _i < _a.length; _i++) {
557
- track = _a[_i];
558
- settings = track.getSettings();
559
- if (settings && settings.width && settings.height) {
560
- aspect = settings.width / settings.height;
561
- break;
562
- }
563
- // on firefox capture canvas stream works but looks like
564
- // the canvas stream track doesnt contain settings?!!?
565
- else {
566
- aspect = this.context.renderer.domElement.clientWidth / this.context.renderer.domElement.clientHeight;
567
- }
568
- }
569
- if (!(aspect === undefined)) return [3 /*break*/, 6];
570
- i = 0;
571
- _d.label = 2;
572
- case 2:
573
- if (!(i < 10)) return [3 /*break*/, 5];
574
- return [4 /*yield*/];
575
- case 3:
576
- _d.sent();
577
- _d.label = 4;
578
- case 4:
579
- i++;
580
- return [3 /*break*/, 2];
581
- case 5:
582
- if (!this.isPlaying)
583
- return [3 /*break*/, 13];
584
- return [3 /*break*/, 1];
585
- case 6:
586
- if (!(lastAspect === aspect)) return [3 /*break*/, 8];
587
- return [4 /*yield*/];
588
- case 7:
589
- _d.sent();
590
- return [3 /*break*/, 1];
591
- case 8:
592
- for (_b = 0, _c = this._targetObjects; _b < _c.length; _b++) {
593
- obj = _c[_b];
594
- worldAspect = 1;
595
- if (obj.parent) {
596
- parentScale = engine_three_utils_js_1.getWorldScale(obj.parent);
597
- worldAspect = parentScale.x / parentScale.y;
598
- }
599
- switch (this.aspectMode) {
600
- case AspectMode.AdjustHeight:
601
- obj.scale.y = 1 / aspect * obj.scale.x * worldAspect;
602
- break;
603
- case AspectMode.AdjustWidth:
604
- obj.scale.x = aspect * obj.scale.y * worldAspect;
605
- break;
606
- }
607
- }
608
- i = 0;
609
- _d.label = 9;
610
- case 9:
611
- if (!(i < 3)) return [3 /*break*/, 12];
612
- return [4 /*yield*/];
613
- case 10:
614
- _d.sent();
615
- _d.label = 11;
616
- case 11:
617
- i++;
618
- return [3 /*break*/, 9];
619
- case 12: return [3 /*break*/, 1];
620
- case 13: return [2 /*return*/];
621
- }
622
- });
623
- };
624
- __decorate([
625
- engine_serialization_decorator_js_1.serializable()
626
- ], VideoPlayer.prototype, "playOnAwake");
627
- __decorate([
628
- engine_serialization_decorator_js_1.serializable()
629
- ], VideoPlayer.prototype, "aspectMode");
630
- __decorate([
631
- engine_serialization_decorator_js_1.serializable(URL)
632
- ], VideoPlayer.prototype, "clip");
633
- __decorate([
634
- engine_serialization_decorator_js_1.serializable()
635
- ], VideoPlayer.prototype, "renderMode");
636
- __decorate([
637
- engine_serialization_decorator_js_1.serializable()
638
- ], VideoPlayer.prototype, "targetMaterialProperty");
639
- __decorate([
640
- engine_serialization_decorator_js_1.serializable(Renderer_js_1.Renderer)
641
- ], VideoPlayer.prototype, "targetMaterialRenderer");
642
- __decorate([
643
- engine_serialization_decorator_js_1.serializable(three_1.Texture)
644
- ], VideoPlayer.prototype, "targetTexture");
645
- __decorate([
646
- engine_serialization_decorator_js_1.serializable()
647
- ], VideoPlayer.prototype, "time");
648
- __decorate([
649
- engine_serialization_decorator_js_1.serializable()
650
- ], VideoPlayer.prototype, "playbackSpeed");
651
- __decorate([
652
- engine_serialization_decorator_js_1.serializable()
653
- ], VideoPlayer.prototype, "isLooping");
654
- __decorate([
655
- engine_serialization_decorator_js_1.serializable()
656
- ], VideoPlayer.prototype, "audioOutputMode");
657
- return VideoPlayer;
658
- }(Component_js_1.Behaviour));
659
- exports.VideoPlayer = VideoPlayer;
660
- var VideoOverlay = /** @class */ (function () {
661
- function VideoOverlay(context) {
662
- this._videos = [];
663
- this._isInScreenspaceMode = false;
664
- this.context = context;
665
- this._input = new VideoOverlayInput(this);
666
- }
667
- Object.defineProperty(VideoOverlay.prototype, "enabled", {
668
- get: function () {
669
- return this._isInScreenspaceMode;
670
- },
671
- set: function (val) {
672
- if (val)
673
- this.start();
674
- else
675
- this.stop();
676
- },
677
- enumerable: false,
678
- configurable: true
679
- });
680
- VideoOverlay.prototype.add = function (video) {
681
- if (this._videos.indexOf(video) === -1) {
682
- this._videos.push(video);
683
- }
684
- };
685
- VideoOverlay.prototype.remove = function (video) {
686
- if (!video)
687
- return;
688
- var index = this._videos.indexOf(video);
689
- if (index >= 0) {
690
- this._videos.splice(index, 1);
691
- }
692
- };
693
- VideoOverlay.prototype.start = function () {
694
- var _a;
695
- if (this._isInScreenspaceMode)
696
- return;
697
- if (this._videos.length < 0)
698
- return;
699
- var texture = this._videos[this._videos.length - 1];
700
- if (!texture)
701
- return;
702
- this._isInScreenspaceMode = true;
703
- if (!this._screenspaceModeQuad) {
704
- this._screenspaceModeQuad = engine_create_objects_js_1.ObjectUtils.createPrimitive(engine_create_objects_js_1.PrimitiveType.Quad, {
705
- material: new ScreenspaceTexture(texture)
706
- });
707
- if (!this._screenspaceModeQuad)
708
- return;
709
- this._screenspaceModeQuad.geometry.scale(2, 2, 2);
710
- }
711
- var quad = this._screenspaceModeQuad;
712
- this.context.scene.add(quad);
713
- this.updateScreenspaceMaterialUniforms();
714
- var mat = quad.material;
715
- mat === null || mat === void 0 ? void 0 : mat.reset();
716
- (_a = this._input) === null || _a === void 0 ? void 0 : _a.enable(mat);
717
- };
718
- VideoOverlay.prototype.stop = function () {
719
- var _a;
720
- this._isInScreenspaceMode = false;
721
- if (this._screenspaceModeQuad) {
722
- (_a = this._input) === null || _a === void 0 ? void 0 : _a.disable();
723
- this._screenspaceModeQuad.removeFromParent();
724
- }
725
- };
726
- VideoOverlay.prototype.updateScreenspaceMaterialUniforms = function () {
727
- var _a;
728
- var mat = (_a = this._screenspaceModeQuad) === null || _a === void 0 ? void 0 : _a.material;
729
- if (!mat)
730
- return;
731
- // mat.videoAspect = this.videoTexture?.image?.width / this.videoTexture?.image?.height;
732
- mat.screenAspect = this.context.domElement.clientWidth / this.context.domElement.clientHeight;
733
- };
734
- return VideoOverlay;
735
- }());
736
- var VideoOverlayInput = /** @class */ (function () {
737
- function VideoOverlayInput(overlay) {
738
- this._isPinching = false;
739
- this._lastPinch = 0;
740
- this.overlay = overlay;
741
- this.context = overlay.context;
742
- }
743
- VideoOverlayInput.prototype.enable = function (mat) {
744
- var _this = this;
745
- this._material = mat;
746
- window.addEventListener("resize", this._onResizeScreenFn = function () {
747
- _this.overlay.updateScreenspaceMaterialUniforms();
748
- });
749
- window.addEventListener("keyup", this._onKeyUpFn = function (args) {
750
- if (args.key === "Escape")
751
- _this.overlay.stop();
752
- });
753
- window.addEventListener("wheel", this._onMouseWheelFn = function (args) {
754
- if (_this.overlay.enabled) {
755
- mat.zoom += args.deltaY * .0005;
756
- args.preventDefault();
757
- }
758
- }, { passive: false });
759
- var delta = new three_1.Vector2();
760
- window.addEventListener("mousemove", function (args) {
761
- if (_this.overlay.enabled && _this.context.input.getPointerPressed(0)) {
762
- var normalizedMovement = new three_1.Vector2(args.movementX, args.movementY);
763
- normalizedMovement.x /= _this.context.domElement.clientWidth;
764
- normalizedMovement.y /= _this.context.domElement.clientHeight;
765
- delta.set(normalizedMovement.x, normalizedMovement.y);
766
- delta.multiplyScalar(mat.zoom / -_this.context.time.deltaTime * .01);
767
- mat.offset = mat.offset.add(delta);
768
- }
769
- });
770
- window.addEventListener("pointermove", function (args) {
771
- if (_this.overlay.enabled && _this.context.input.getPointerPressed(0)) {
772
- var count = _this.context.input.getTouchesPressedCount();
773
- if (count === 1) {
774
- delta.set(args.movementX, args.movementY);
775
- delta.multiplyScalar(mat.zoom * -_this.context.time.deltaTime * .05);
776
- mat.offset = mat.offset.add(delta);
777
- }
778
- }
779
- });
780
- var lastTouchStartTime = 0;
781
- window.addEventListener("touchstart", function (e) {
782
- if (e.touches.length < 2) {
783
- if (_this.context.time.time - lastTouchStartTime < .3) {
784
- _this.overlay.stop();
785
- }
786
- lastTouchStartTime = _this.context.time.time;
787
- return;
788
- }
789
- _this._isPinching = true;
790
- _this._lastPinch = 0;
791
- });
792
- window.addEventListener("touchmove", function (e) {
793
- if (!_this._isPinching || !_this._material)
794
- return;
795
- var touch1 = e.touches[0];
796
- var touch2 = e.touches[1];
797
- var dx = touch1.clientX - touch2.clientX;
798
- var dy = touch1.clientY - touch2.clientY;
799
- var distance = Math.sqrt(dx * dx + dy * dy);
800
- if (_this._lastPinch !== 0) {
801
- var delta_1 = distance - _this._lastPinch;
802
- _this._material.zoom -= delta_1 * .004;
803
- }
804
- _this._lastPinch = distance;
805
- });
806
- window.addEventListener("touchend", function () {
807
- _this._isPinching = false;
808
- });
809
- };
810
- VideoOverlayInput.prototype.disable = function () {
811
- if (this._onResizeScreenFn) {
812
- window.removeEventListener("resize", this._onResizeScreenFn);
813
- this._onResizeScreenFn = undefined;
814
- }
815
- if (this._onKeyUpFn) {
816
- window.removeEventListener("keyup", this._onKeyUpFn);
817
- this._onKeyUpFn = undefined;
818
- }
819
- if (this._onMouseWheelFn) {
820
- window.removeEventListener("wheel", this._onMouseWheelFn);
821
- this._onMouseWheelFn = undefined;
822
- }
823
- };
824
- return VideoOverlayInput;
825
- }());
826
- var ScreenspaceTexture = /** @class */ (function (_super) {
827
- __extends(ScreenspaceTexture, _super);
828
- // maxZoom : number = 10
829
- function ScreenspaceTexture(tex) {
830
- var _this = _super.call(this) || this;
831
- _this._offset = new three_1.Vector2();
832
- _this.uniforms = {
833
- map: { value: tex },
834
- screenAspect: { value: 1 },
835
- offsetScale: { value: new three_1.Vector4(0, 0, 1, 1) }
836
- };
837
- _this.vertexShader = "\n uniform sampler2D map;\n uniform float screenAspect;\n uniform vec4 offsetScale;\n varying vec2 vUv;\n\n void main() {\n\n gl_Position = vec4( position , 1.0 );\n vUv = uv;\n vUv.y = 1. - vUv.y;\n\n // fit into screen\n ivec2 res = textureSize(map, 0);\n float videoAspect = float(res.x) / float(res.y);\n float aspect = videoAspect / screenAspect;\n if(aspect >= 1.0) \n {\n vUv.y = vUv.y * aspect;\n float offset = (1. - aspect) * .5;\n vUv.y = vUv.y + offset;\n }\n else\n {\n vUv.x = vUv.x / aspect;\n float offset = (1. - 1. / aspect) * .5;\n vUv.x = vUv.x + offset;\n }\n\n vUv.x -= .5;\n vUv.y -= .5;\n\n vUv.x *= offsetScale.z;\n vUv.y *= offsetScale.z;\n vUv.x += offsetScale.x;\n vUv.y += offsetScale.y;\n\n vUv.x += .5;\n vUv.y += .5;\n }\n\n ";
838
- _this.fragmentShader = "\n uniform sampler2D map;\n varying vec2 vUv;\n void main() {\n if(vUv.x < 0. || vUv.x > 1. || vUv.y < 0. || vUv.y > 1.)\n gl_FragColor = vec4(0., 0., 0., 1.);\n else\n {\n vec4 texcolor = texture2D(map, vUv);\n texcolor = LinearTosRGB(texcolor);\n gl_FragColor = texcolor;\n }\n }\n ";
839
- return _this;
840
- }
841
- Object.defineProperty(ScreenspaceTexture.prototype, "screenAspect", {
842
- set: function (val) {
843
- this.uniforms["screenAspect"].value = val;
844
- this.needsUpdate = true;
845
- },
846
- enumerable: false,
847
- configurable: true
848
- });
849
- Object.defineProperty(ScreenspaceTexture.prototype, "offset", {
850
- get: function () {
851
- var val = this.uniforms["offsetScale"].value;
852
- this._offset.set(val.x, val.y);
853
- return this._offset;
854
- },
855
- set: function (vec) {
856
- var val = this.uniforms["offsetScale"].value;
857
- val.x = vec.x;
858
- val.y = vec.y;
859
- // console.log(val);
860
- this.uniforms["offsetScale"].value = val;
861
- this.needsUpdate = true;
862
- },
863
- enumerable: false,
864
- configurable: true
865
- });
866
- Object.defineProperty(ScreenspaceTexture.prototype, "zoom", {
867
- get: function () {
868
- return this.uniforms["offsetScale"].value.z; // * this.maxZoom;
869
- },
870
- set: function (val) {
871
- var zoom = this.uniforms["offsetScale"].value;
872
- if (val < .001)
873
- val = .001;
874
- zoom.z = val;
875
- // zoom.z = this.maxZoom - val;
876
- // zoom.z /= this.maxZoom;
877
- this.needsUpdate = true;
878
- },
879
- enumerable: false,
880
- configurable: true
881
- });
882
- ScreenspaceTexture.prototype.reset = function () {
883
- this.offset = this.offset.set(0, 0);
884
- this.zoom = 1;
885
- this.needsUpdate = true;
886
- };
887
- return ScreenspaceTexture;
888
- }(three_1.ShaderMaterial));