videoDome.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Texture } from "../Materials/Textures/texture.js";
  2. import { VideoTexture } from "../Materials/Textures/videoTexture.js";
  3. import { TextureDome } from "./textureDome.js";
  4. import { PointerEventTypes } from "../Events/pointerEvents.js";
  5. /**
  6. * Display a 360/180 degree video on an approximately spherical surface, useful for VR applications or skyboxes.
  7. * As a subclass of TransformNode, this allow parenting to the camera or multiple videos with different locations in the scene.
  8. * This class achieves its effect with a VideoTexture and a correctly configured BackgroundMaterial on an inverted sphere.
  9. * Potential additions to this helper include zoom and and non-infinite distance rendering effects.
  10. */
  11. export class VideoDome extends TextureDome {
  12. /**
  13. * Get the video texture associated with this video dome
  14. */
  15. get videoTexture() {
  16. return this._texture;
  17. }
  18. /**
  19. * Get the video mode of this dome
  20. */
  21. get videoMode() {
  22. return this.textureMode;
  23. }
  24. /**
  25. * Set the video mode of this dome.
  26. * @see textureMode
  27. */
  28. set videoMode(value) {
  29. this.textureMode = value;
  30. }
  31. _initTexture(urlsOrElement, scene, options) {
  32. const tempOptions = { loop: options.loop, autoPlay: options.autoPlay, autoUpdateTexture: true, poster: options.poster };
  33. const texture = new VideoTexture((this.name || "videoDome") + "_texture", urlsOrElement, scene, options.generateMipMaps, this._useDirectMapping, Texture.TRILINEAR_SAMPLINGMODE, tempOptions);
  34. // optional configuration
  35. if (options.clickToPlay) {
  36. this._pointerObserver = scene.onPointerObservable.add((data) => {
  37. data.pickInfo?.pickedMesh === this.mesh && this._texture.video.play();
  38. }, PointerEventTypes.POINTERDOWN);
  39. }
  40. this._textureObserver = texture.onLoadObservable.add(() => {
  41. this.onLoadObservable.notifyObservers();
  42. });
  43. return texture;
  44. }
  45. /**
  46. * Releases resources associated with this node.
  47. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
  48. * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)
  49. */
  50. dispose(doNotRecurse, disposeMaterialAndTextures = false) {
  51. this._texture.onLoadObservable.remove(this._textureObserver);
  52. this._scene.onPointerObservable.remove(this._pointerObserver);
  53. super.dispose(doNotRecurse, disposeMaterialAndTextures);
  54. }
  55. }
  56. /**
  57. * Define the video source as a Monoscopic panoramic 360 video.
  58. */
  59. VideoDome.MODE_MONOSCOPIC = TextureDome.MODE_MONOSCOPIC;
  60. /**
  61. * Define the video source as a Stereoscopic TopBottom/OverUnder panoramic 360 video.
  62. */
  63. VideoDome.MODE_TOPBOTTOM = TextureDome.MODE_TOPBOTTOM;
  64. /**
  65. * Define the video source as a Stereoscopic Side by Side panoramic 360 video.
  66. */
  67. VideoDome.MODE_SIDEBYSIDE = TextureDome.MODE_SIDEBYSIDE;
  68. //# sourceMappingURL=videoDome.js.map