瀏覽代碼

More complete (but unfinished) options and documentation.

David 7 年之前
父節點
當前提交
4cf3990c3a
共有 1 個文件被更改,包括 19 次插入5 次删除
  1. 19 5
      src/Helpers/babylon.videoDome.ts

+ 19 - 5
src/Helpers/babylon.videoDome.ts

@@ -15,15 +15,27 @@ module BABYLON {
         /**
          * The skybox material
          */
-        private _material: StandardMaterial;
+        private _material: BackgroundMaterial;
 
         /**
          * The surface used for the skybox
          */
         private _mesh: Mesh;
 
+        /**
+         * Create an instance of this class and pass through the parameters to the relevant classes, VideoTexture, StandardMaterial, and Mesh.
+         * @param name Element's name, child elements will append suffixes for their own names.
+         * @param urlsOrVideo -
+         * @param options An object containing optional or exposed sub element properties:
+         * @param options **clickToPlay=false** Add a click to play listener to the video, does not prevent autoplay.
+         * @param options **autoPlay=true** Automatically attempt to being playing the video.
+         * @param options **loop=true** Automatically loop video on end.
+         * @param options **size=1000** Physical size to create the dome at, defaults to half the far clip plane.
+         */
         constructor(name: string, urlsOrVideo: string[] | HTMLVideoElement, options: {
             clickToPlay?: boolean,
+            autoPlay?: boolean,
+            loop?: boolean,
             size?: number
         }, scene: Scene) {
             super(name, scene);
@@ -31,17 +43,19 @@ module BABYLON {
             // set defaults and manage values
             name = name || "videoDome";
             options.clickToPlay = Boolean(options.clickToPlay);
-            options.size = Math.abs(options.size as any) || 1000;
+            options.autoPlay = options.autoPlay === undefined ? true : Boolean(options.autoPlay);
+            options.loop = options.loop === undefined ? true : Boolean(options.loop);
+            options.size = Math.abs(options.size as any) || (scene.activeCamera ? scene.activeCamera.maxZ * 0.48 : 1000);
 
             // create
-            let material = this._material = new BABYLON.StandardMaterial(name+"_material", scene);
-            this._videoTexture = new BABYLON.VideoTexture(name+"_texture", urlsOrVideo, scene);
+            let tempOptions:VideoTextureSettings = {loop: options.loop, autoPlay: options.autoPlay, autoUpdateTexture: true};
+            let material = this._material = new BABYLON.BackgroundMaterial(name+"_material", scene);
+            this._videoTexture = new BABYLON.VideoTexture(name+"_texture", urlsOrVideo, scene, false, false, Texture.TRILINEAR_SAMPLINGMODE, tempOptions);
             this._mesh = BABYLON.MeshBuilder.CreateBox(name+"_mesh", {size:-options.size}, scene); // needs to be inside out
 
             // configure material
             material.reflectionTexture = this._videoTexture;
             material.reflectionTexture.coordinatesMode = BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE; // matches src
-            material.diffuseColor = material.specularColor = new BABYLON.Color3(0, 0, 0);
 
             // configure mesh
             this._mesh.material = material;