<commit_before>﻿module BABYLON {
    export class VideoTexture extends Texture {
        public video: HTMLVideoElement;

        private _autoLaunch = true;
        private _lastUpdate: number;

        /**
        * Creates a video texture.  
        * Sample : https://doc.babylonjs.com/tutorials/01._Advanced_Texturing  
        * @param {Array} urlsOrVideo can be used to provide an array of urls or an already setup HTML video element.
        * @param {BABYLON.Scene} scene is obviously the current scene.   
        * @param {boolean} generateMipMaps can be used to turn on mipmaps (Can be expensive for videoTextures because they are often updated).
        * @param {boolean} invertY is false by default but can be used to invert video on Y axis
        * @param {number} samplingMode controls the sampling method and is set to TRILINEAR_SAMPLINGMODE by default
        */
        constructor(name: string, urlsOrVideo: string[] | HTMLVideoElement, scene: Scene, generateMipMaps = false, invertY = false, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
            super(null, scene, !generateMipMaps, invertY);

            var urls: string[];
            this.name = name;

            if (urlsOrVideo instanceof HTMLVideoElement) {
                this.video = <any>urlsOrVideo;
            } else {
                urls = <any>urlsOrVideo;

                this.video = document.createElement("video");
                this.video.autoplay = false;
                this.video.loop = true;
            }

            this.video.addEventListener("canplaythrough", () => {
                if (Tools.IsExponentOfTwo(this.video.videoWidth) && Tools.IsExponentOfTwo(this.video.videoHeight)) {
                    this.wrapU = Texture.WRAP_ADDRESSMODE;
                    this.wrapV = Texture.WRAP_ADDRESSMODE;
                } else {
                    this.wrapU = Texture.CLAMP_ADDRESSMODE;
                    this.wrapV = Texture.CLAMP_ADDRESSMODE;
                    generateMipMaps = false;
                }

                this._texture = scene.getEngine().createDynamicTexture(this.video.videoWidth, this.video.videoHeight, generateMipMaps, samplingMode, false);
                this._texture.isReady = true;
            });

            if (urls) {
                urls.forEach(url => {
                    var source = document.createElement("source");
                    source.src = url;
                    this.video.appendChild(source);
                });
            }

            this._lastUpdate = Tools.Now;
        }

        public update(): boolean {
            if (this._autoLaunch) {
                this._autoLaunch = false;
                this.video.play();
            }

            var now = Tools.Now;

            if (now - this._lastUpdate < 15 || this.video.readyState !== this.video.HAVE_ENOUGH_DATA) {
               return false;
            }

            this._lastUpdate = now;
            this.getScene().getEngine().updateVideoTexture(this._texture, this.video, this._invertY);
            return true;
        }
    }
} <commit_msg>Refactored<commit_after>module BABYLON {
    export class VideoTexture extends Texture {
        public video: HTMLVideoElement;

        private _autoLaunch = true;
        private _lastUpdate: number;

        /**
         * Creates a video texture.
         * Sample : https://doc.babylonjs.com/tutorials/01._Advanced_Texturing
         * @param {Array} urlsOrVideo can be used to provide an array of urls or an already setup HTML video element.
         * @param {BABYLON.Scene} scene is obviously the current scene.
         * @param {boolean} generateMipMaps can be used to turn on mipmaps (Can be expensive for videoTextures because they are often updated).
         * @param {boolean} invertY is false by default but can be used to invert video on Y axis
         * @param {number} samplingMode controls the sampling method and is set to TRILINEAR_SAMPLINGMODE by default
         */
        constructor(name: string, urlsOrVideo: string[] | HTMLVideoElement, scene: Scene, generateMipMaps = false, invertY = false, samplingMode: number = Texture.TRILINEAR_SAMPLINGMODE) {
            super(null, scene, !generateMipMaps, invertY);

            var urls: string[];
            this.name = name;

            if (urlsOrVideo instanceof HTMLVideoElement) {
                this.video = <any>urlsOrVideo;
            } else {
                urls = <any>urlsOrVideo;

                this.video = document.createElement("video");
                this.video.autoplay = false;
                this.video.loop = true;
            }

            if (Tools.IsExponentOfTwo(this.video.videoWidth) && Tools.IsExponentOfTwo(this.video.videoHeight)) {
                this.wrapU = Texture.WRAP_ADDRESSMODE;
                this.wrapV = Texture.WRAP_ADDRESSMODE;
            } else {
                this.wrapU = Texture.CLAMP_ADDRESSMODE;
                this.wrapV = Texture.CLAMP_ADDRESSMODE;
                generateMipMaps = false;
            }

            if (urls) {
                this.video.addEventListener("canplaythrough", () => {
                    this._texture = scene.getEngine().createDynamicTexture(this.video.videoWidth, this.video.videoHeight, generateMipMaps, samplingMode, false);
                    this._texture.isReady = true;
                });
                urls.forEach(url => {
                    var source = document.createElement("source");
                    source.src = url;
                    this.video.appendChild(source);
                });
            } else {

                this._texture = scene.getEngine().createDynamicTexture(this.video.videoWidth, this.video.videoHeight, generateMipMaps, samplingMode, false);
                this._texture.isReady = true;
            }

            this._lastUpdate = Tools.Now;

        }

        public update(): boolean {
            if (this._autoLaunch) {
                this._autoLaunch = false;
                this.video.play();
            }

            var now = Tools.Now;

            if (now - this._lastUpdate < 15 || this.video.readyState !== this.video.HAVE_ENOUGH_DATA) {
                return false;
            }

            this._lastUpdate = now;
            this.getScene().getEngine().updateVideoTexture(this._texture, this.video, this._invertY);
            return true;
        }
    }
}
{'fraction_non_alphanumeric': 0.09113607990012484, 'fraction_numerical': 0.0012484394506866417, 'mean_word_length': 1.7901610796691336, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1076872', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1648, 'n_words': 405}