Ver código fonte

Breaking change: VideoTexture does not require a size parameter anymore.
The new constructor is: constructor(name: string, urls: string[], scene: Scene, generateMipMaps = false, invertY = true, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE)

David Catuhe 10 anos atrás
pai
commit
298e9369be

+ 13 - 11
Babylon/Materials/Textures/babylon.videoTexture.js

@@ -8,27 +8,29 @@ var BABYLON;
 (function (BABYLON) {
     var VideoTexture = (function (_super) {
         __extends(VideoTexture, _super);
-        function VideoTexture(name, urls, size, scene, generateMipMaps, invertY, samplingMode) {
+        function VideoTexture(name, urls, scene, generateMipMaps, invertY, samplingMode) {
             var _this = this;
+            if (generateMipMaps === void 0) { generateMipMaps = false; }
+            if (invertY === void 0) { invertY = true; }
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             _super.call(this, null, scene, !generateMipMaps, invertY);
             this._autoLaunch = true;
             this.name = name;
-            this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
-            this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
-            var requiredWidth = size.width || size;
-            var requiredHeight = size.height || size;
-            this._texture = scene.getEngine().createDynamicTexture(requiredWidth, requiredHeight, generateMipMaps, samplingMode);
-            var textureSize = this.getSize();
             this.video = document.createElement("video");
-            this.video.width = textureSize.width;
-            this.video.height = textureSize.height;
             this.video.autoplay = false;
             this.video.loop = true;
             this.video.addEventListener("canplaythrough", function () {
-                if (_this._texture) {
-                    _this._texture.isReady = true;
+                if (BABYLON.Tools.IsExponantOfTwo(_this.video.videoWidth) && BABYLON.Tools.IsExponantOfTwo(_this.video.videoHeight)) {
+                    _this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
+                    _this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
                 }
+                else {
+                    _this.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
+                    _this.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
+                    generateMipMaps = false;
+                }
+                _this._texture = scene.getEngine().createDynamicTexture(_this.video.videoWidth, _this.video.videoHeight, generateMipMaps, samplingMode, false);
+                _this._texture.isReady = true;
             });
             urls.forEach(function (url) {
                 //Backwards-compatibility for typescript 1. from 1.3 it should say "SOURCE". see here - https://github.com/Microsoft/TypeScript/issues/1850

+ 11 - 14
Babylon/Materials/Textures/babylon.videoTexture.ts

@@ -5,30 +5,27 @@
         private _autoLaunch = true;
         private _lastUpdate: number;
 
-        constructor(name: string, urls: string[], size: any, scene: Scene, generateMipMaps: boolean, invertY: boolean, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
+        constructor(name: string, urls: string[], scene: Scene, generateMipMaps = false, invertY = true, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
             super(null, scene, !generateMipMaps, invertY);
 
             this.name = name;
 
-            this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
-            this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
-
-            var requiredWidth = size.width || size;
-            var requiredHeight = size.height || size;
-
-            this._texture = scene.getEngine().createDynamicTexture(requiredWidth, requiredHeight, generateMipMaps, samplingMode);
-            var textureSize = this.getSize();
-
             this.video = document.createElement("video");
-            this.video.width = textureSize.width;
-            this.video.height = textureSize.height;
             this.video.autoplay = false;
             this.video.loop = true;
 
             this.video.addEventListener("canplaythrough", () => {
-                if (this._texture) {
-                    this._texture.isReady = true;
+                if (Tools.IsExponantOfTwo(this.video.videoWidth) && Tools.IsExponantOfTwo(this.video.videoHeight)) {
+                    this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
+                    this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
+                } else {
+                    this.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
+                    this.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
+                    generateMipMaps = false;
                 }
+
+                this._texture = scene.getEngine().createDynamicTexture(this.video.videoWidth, this.video.videoHeight, generateMipMaps, samplingMode, false);
+                this._texture.isReady = true;
             });
 
             urls.forEach(url => {

+ 18 - 9
Babylon/Tools/babylon.tools.js

@@ -27,6 +27,24 @@ var BABYLON;
                 setTimeout(action, 1);
             }
         };
+        Tools.IsExponantOfTwo = function (value) {
+            var count = 1;
+            do {
+                count *= 2;
+            } while (count < value);
+            return count === value;
+        };
+        ;
+        Tools.GetExponantOfTwo = function (value, max) {
+            var count = 1;
+            do {
+                count *= 2;
+            } while (count < value);
+            if (count > max)
+                count = max;
+            return count;
+        };
+        ;
         Tools.GetFilename = function (path) {
             var index = path.lastIndexOf("/");
             if (index < 0)
@@ -698,15 +716,6 @@ var BABYLON;
             return 0;
         };
         Tools.BaseUrl = "";
-        Tools.GetExponantOfTwo = function (value, max) {
-            var count = 1;
-            do {
-                count *= 2;
-            } while (count < value);
-            if (count > max)
-                count = max;
-            return count;
-        };
         // Logs
         Tools._NoneLogLevel = 0;
         Tools._MessageLogLevel = 1;

+ 11 - 1
Babylon/Tools/babylon.tools.ts

@@ -38,7 +38,17 @@
             }
         }
 
-        public static GetExponantOfTwo = (value: number, max: number): number => {
+        public static IsExponantOfTwo(value: number): boolean {
+            var count = 1;
+
+            do {
+                count *= 2;
+            } while (count < value);
+
+            return count === value;
+        };
+
+        public static GetExponantOfTwo(value: number, max: number): number {
             var count = 1;
 
             do {

+ 7 - 4
Babylon/babylon.engine.js

@@ -1394,13 +1394,16 @@ var BABYLON;
             this._loadedTexturesCache.push(texture);
             return texture;
         };
-        Engine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode) {
+        Engine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode, forceExponantOfTwo) {
+            if (forceExponantOfTwo === void 0) { forceExponantOfTwo = true; }
             var texture = this._gl.createTexture();
-            width = BABYLON.Tools.GetExponantOfTwo(width, this._caps.maxTextureSize);
-            height = BABYLON.Tools.GetExponantOfTwo(height, this._caps.maxTextureSize);
-            this._activeTexturesCache = [];
             texture._baseWidth = width;
             texture._baseHeight = height;
+            if (forceExponantOfTwo) {
+                width = BABYLON.Tools.GetExponantOfTwo(width, this._caps.maxTextureSize);
+                height = BABYLON.Tools.GetExponantOfTwo(height, this._caps.maxTextureSize);
+            }
+            this._activeTexturesCache = [];
             texture._width = width;
             texture._height = height;
             texture.isReady = false;

+ 7 - 5
Babylon/babylon.engine.ts

@@ -1673,15 +1673,17 @@
             return texture;
         }
 
-        public createDynamicTexture(width: number, height: number, generateMipMaps: boolean, samplingMode: number): WebGLTexture {
+        public createDynamicTexture(width: number, height: number, generateMipMaps: boolean, samplingMode: number, forceExponantOfTwo = true): WebGLTexture {
             var texture = this._gl.createTexture();
+            texture._baseWidth = width;
+            texture._baseHeight = height;
 
-            width = Tools.GetExponantOfTwo(width, this._caps.maxTextureSize);
-            height = Tools.GetExponantOfTwo(height, this._caps.maxTextureSize);
+            if (forceExponantOfTwo) {
+                width = Tools.GetExponantOfTwo(width, this._caps.maxTextureSize);
+                height = Tools.GetExponantOfTwo(height, this._caps.maxTextureSize);
+            }
 
             this._activeTexturesCache = [];
-            texture._baseWidth = width;
-            texture._baseHeight = height;
             texture._width = width;
             texture._height = height;
             texture.isReady = false;

+ 38 - 24
babylon.2.1-beta.debug.js

@@ -4151,6 +4151,24 @@ var BABYLON;
                 setTimeout(action, 1);
             }
         };
+        Tools.IsExponantOfTwo = function (value) {
+            var count = 1;
+            do {
+                count *= 2;
+            } while (count < value);
+            return count === value;
+        };
+        ;
+        Tools.GetExponantOfTwo = function (value, max) {
+            var count = 1;
+            do {
+                count *= 2;
+            } while (count < value);
+            if (count > max)
+                count = max;
+            return count;
+        };
+        ;
         Tools.GetFilename = function (path) {
             var index = path.lastIndexOf("/");
             if (index < 0)
@@ -4822,15 +4840,6 @@ var BABYLON;
             return 0;
         };
         Tools.BaseUrl = "";
-        Tools.GetExponantOfTwo = function (value, max) {
-            var count = 1;
-            do {
-                count *= 2;
-            } while (count < value);
-            if (count > max)
-                count = max;
-            return count;
-        };
         // Logs
         Tools._NoneLogLevel = 0;
         Tools._MessageLogLevel = 1;
@@ -6332,13 +6341,16 @@ var BABYLON;
             this._loadedTexturesCache.push(texture);
             return texture;
         };
-        Engine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode) {
+        Engine.prototype.createDynamicTexture = function (width, height, generateMipMaps, samplingMode, forceExponantOfTwo) {
+            if (forceExponantOfTwo === void 0) { forceExponantOfTwo = true; }
             var texture = this._gl.createTexture();
-            width = BABYLON.Tools.GetExponantOfTwo(width, this._caps.maxTextureSize);
-            height = BABYLON.Tools.GetExponantOfTwo(height, this._caps.maxTextureSize);
-            this._activeTexturesCache = [];
             texture._baseWidth = width;
             texture._baseHeight = height;
+            if (forceExponantOfTwo) {
+                width = BABYLON.Tools.GetExponantOfTwo(width, this._caps.maxTextureSize);
+                height = BABYLON.Tools.GetExponantOfTwo(height, this._caps.maxTextureSize);
+            }
+            this._activeTexturesCache = [];
             texture._width = width;
             texture._height = height;
             texture.isReady = false;
@@ -16840,27 +16852,29 @@ var BABYLON;
 (function (BABYLON) {
     var VideoTexture = (function (_super) {
         __extends(VideoTexture, _super);
-        function VideoTexture(name, urls, size, scene, generateMipMaps, invertY, samplingMode) {
+        function VideoTexture(name, urls, scene, generateMipMaps, invertY, samplingMode) {
             var _this = this;
+            if (generateMipMaps === void 0) { generateMipMaps = false; }
+            if (invertY === void 0) { invertY = true; }
             if (samplingMode === void 0) { samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE; }
             _super.call(this, null, scene, !generateMipMaps, invertY);
             this._autoLaunch = true;
             this.name = name;
-            this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
-            this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
-            var requiredWidth = size.width || size;
-            var requiredHeight = size.height || size;
-            this._texture = scene.getEngine().createDynamicTexture(requiredWidth, requiredHeight, generateMipMaps, samplingMode);
-            var textureSize = this.getSize();
             this.video = document.createElement("video");
-            this.video.width = textureSize.width;
-            this.video.height = textureSize.height;
             this.video.autoplay = false;
             this.video.loop = true;
             this.video.addEventListener("canplaythrough", function () {
-                if (_this._texture) {
-                    _this._texture.isReady = true;
+                if (BABYLON.Tools.IsExponantOfTwo(_this.video.videoWidth) && BABYLON.Tools.IsExponantOfTwo(_this.video.videoHeight)) {
+                    _this.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
+                    _this.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
+                }
+                else {
+                    _this.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
+                    _this.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
+                    generateMipMaps = false;
                 }
+                _this._texture = scene.getEngine().createDynamicTexture(_this.video.videoWidth, _this.video.videoHeight, generateMipMaps, samplingMode, false);
+                _this._texture.isReady = true;
             });
             urls.forEach(function (url) {
                 //Backwards-compatibility for typescript 1. from 1.3 it should say "SOURCE". see here - https://github.com/Microsoft/TypeScript/issues/1850

Diferenças do arquivo suprimidas por serem muito extensas
+ 15 - 13
babylon.2.1-beta.js


Diferenças do arquivo suprimidas por serem muito extensas
+ 15 - 13
babylon.2.1-beta.noworker.js


+ 1 - 0
what's new - 2.1 - proposal.md

@@ -64,3 +64,4 @@
  - OculusCamera was removed ([deltakosh](http://www.github.com/deltakosh))
  - VRDeviceOrientationCamera was renamed to VRDeviceOrientationFreeCamera ([deltakosh](http://www.github.com/deltakosh))
  - WebVRCamera was renamed to WebVRFreeCamera ([deltakosh](http://www.github.com/deltakosh))
+ - VideoTexture does not require a size parameter anymore. The new constructor is: ```constructor(name: string, urls: string[], scene: Scene, generateMipMaps = false, invertY = true, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE)```  ([deltakosh](http://www.github.com/deltakosh))