babylon.videoTexture.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var __extends = this.__extends || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var VideoTexture = (function (_super) {
  10. __extends(VideoTexture, _super);
  11. function VideoTexture(name, urls, size, scene, generateMipMaps, invertY, samplingMode) {
  12. if (typeof samplingMode === "undefined") { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
  13. var _this = this;
  14. _super.call(this, null, scene, !generateMipMaps, invertY);
  15. this._autoLaunch = true;
  16. this.name = name;
  17. this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  18. this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  19. var requiredWidth = size.width || size;
  20. var requiredHeight = size.height || size;
  21. this._texture = scene.getEngine().createDynamicTexture(requiredWidth, requiredHeight, generateMipMaps, samplingMode);
  22. var textureSize = this.getSize();
  23. this.video = document.createElement("video");
  24. this.video.width = textureSize.width;
  25. this.video.height = textureSize.height;
  26. this.video.autoplay = false;
  27. this.video.loop = true;
  28. this.video.addEventListener("canplaythrough", function () {
  29. if (_this._texture) {
  30. _this._texture.isReady = true;
  31. }
  32. });
  33. urls.forEach(function (url) {
  34. var source = document.createElement("source");
  35. source.src = url;
  36. _this.video.appendChild(source);
  37. });
  38. this._lastUpdate = BABYLON.Tools.Now;
  39. }
  40. VideoTexture.prototype.update = function () {
  41. if (this._autoLaunch) {
  42. this._autoLaunch = false;
  43. this.video.play();
  44. }
  45. var now = BABYLON.Tools.Now;
  46. if (now - this._lastUpdate < 15) {
  47. return false;
  48. }
  49. this._lastUpdate = now;
  50. this.getScene().getEngine().updateVideoTexture(this._texture, this.video, this._invertY);
  51. return true;
  52. };
  53. return VideoTexture;
  54. })(BABYLON.Texture);
  55. BABYLON.VideoTexture = VideoTexture;
  56. })(BABYLON || (BABYLON = {}));
  57. //# sourceMappingURL=babylon.videoTexture.js.map