<commit_before>/*global define*/
define([
        './DynamicProperty',
        './CzmlString',
        '../Scene/DiffuseMapMaterial',
        '../Renderer/PixelFormat'
    ], function(
         DynamicProperty,
         CzmlString,
         DiffuseMapMaterial,
         PixelFormat) {
    "use strict";

    function DynamicImageMaterial(id) {
        this.image = undefined;
        this._textures = {};
    }

    DynamicImageMaterial.isMaterial = function(czmlInterval) {
        return typeof czmlInterval.image !== 'undefined';
    };

    DynamicImageMaterial.processCzmlPacket = function(czmlInterval, existingMaterial, constrainedInterval) {
        var materialData = czmlInterval.image;
        if (typeof materialData !== 'undefined') {
            if (typeof existingMaterial === 'undefined') {
                existingMaterial = new DynamicImageMaterial();
            }
            DynamicProperty.processCzmlPacket(existingMaterial, 'image', CzmlString, materialData.image);
        }
        return existingMaterial;
    };

    //CZML_TODO There is a race condition here if an image loads after it is no longer needed.
    DynamicImageMaterial.prototype.applyToMaterial = function(time, scene, existingMaterial) {
        if (typeof existingMaterial === 'undefined' || !(existingMaterial instanceof DiffuseMapMaterial)) {
            existingMaterial = new DiffuseMapMaterial();
        }
        var url = this.image.getValue(time);
        var textures = this._textures;
        var texture = textures[url];
        if (!texture) {
            var image = new Image();
            image.onload = function() {
                var innerTexture = textures[url];
                if (typeof innerTexture === 'undefined') {
                    textures[url] = innerTexture = scene.getContext().createTexture2D({
                        source : image,
                        pixelFormat : PixelFormat.RGB
                    });
                }
                existingMaterial.texture = innerTexture;
            };
            image.src = url;
        } else if (existingMaterial.texture !== texture) {
            existingMaterial.texture = texture;
        }

        return existingMaterial;
    };

    return DynamicImageMaterial;
});<commit_msg>Make DynamicImageMaterial work, though there still lots of room for improvement.<commit_after>/*global define*/
define([
        './DynamicProperty',
        './CzmlString',
        './CzmlNumber',
        '../Scene/DiffuseMapMaterial',
        '../Renderer/PixelFormat',
    ], function(
         DynamicProperty,
         CzmlString,
         CzmlNumber,
         DiffuseMapMaterial,
         PixelFormat) {
    "use strict";

    //This is a black on white ? to be used as a "default" texture.
    var dataUri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAIAAABvFaqvAAAAAXNSR0I";
    dataUri += "Ars4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsIAAA7CARUoSoAAAAAadEVYdFNvZnR3YXJl";
    dataUri += "AFBhaW50Lk5FVCB2My41LjEwMPRyoQAAATVJREFUOE/Nk78OREAQxnWeQFRehE4jarUX0Kg0PIJK7";
    dataUri += "QW8gUQhOolCL5FIVBqFWnE3uUkmd7vWuj/FTcXu57efb2aV249KEXHatvU8T9M05VHwAK9N04j0B6";
    dataUri += "B1XR3Hwe/5Mk0TBDyOBe37btu2iILrhmHwLBaUZRlR4jie5xkPn6YpiiLaCsOQMfUCAju6rqO6LEv";
    dataUri += "ef57nxFqW5VnwAuq6DnWu64pChS3U1HUtBNGBRVGIQKQ5A10ZqSRJ0BHYFzqSgoZhUFUVKBAlBPoh";
    dataUri += "CCjQeLTD/7twshl3fd+jFyi+9yC+BKqqiigwTYcJyEHQHZqdNE3fuGvP0m3bKBdo/Ek3JI4gVLTj+";
    dataUri += "/55TyWgIAgO51h++xmFZVkIGsfxK0cEgrC+AklnnQTy9l9knYEgF5ogKe7/QHfMiZTut7WfQwAAAABJRU5ErkJggg==";

    var defaultImage = new Image();
    defaultImage.src = dataUri;

    function DynamicImageMaterial(id) {
        this.image = undefined;
        this.verticalRepeat = undefined;
        this.horizontalRepeat = undefined;
    }

    DynamicImageMaterial.isMaterial = function(czmlInterval) {
        return typeof czmlInterval.image !== 'undefined';
    };

    DynamicImageMaterial.processCzmlPacket = function(czmlInterval, existingMaterial, constrainedInterval) {
        var materialData = czmlInterval.image;
        if (typeof materialData !== 'undefined') {
            if (typeof existingMaterial === 'undefined') {
                existingMaterial = new DynamicImageMaterial();
            }
            DynamicProperty.processCzmlPacket(existingMaterial, 'image', CzmlString, materialData.image);
            DynamicProperty.processCzmlPacket(existingMaterial, 'verticalRepeat', CzmlNumber, materialData.verticalRepeat);
            DynamicProperty.processCzmlPacket(existingMaterial, 'horizontalRepeat', CzmlNumber, materialData.horizontalRepeat);
        }
        return existingMaterial;
    };

    DynamicImageMaterial.prototype.applyToMaterial = function(time, scene, existingMaterial) {
        if (typeof existingMaterial === 'undefined' || !(existingMaterial instanceof DiffuseMapMaterial)) {
            existingMaterial = new DiffuseMapMaterial();
        }

        var tRepeat;
        var property = this.verticalRepeat;
        if (typeof property !== 'undefined') {
            tRepeat = property.getValue(time);
            if (typeof tRepeat !== 'undefined') {
                existingMaterial.tRepeat = tRepeat;
            }
        }

        var sRepeat;
        property = this.horizontalRepeat;
        if (typeof property !== 'undefined') {
            sRepeat = property.getValue(time);
            if (typeof value !== 'undefined') {
                existingMaterial.sRepeat = sRepeat;
            }
        }

        property = this.image;
        if (typeof property !== 'undefined') {
            var url = this.image.getValue(time);
            if (typeof url !== 'undefined' && existingMaterial.currentUrl !== url) {
                existingMaterial.currentUrl = url;
                var image = new Image();
                image.onload = function() {
                    if (existingMaterial.currentUrl === url) {
                        existingMaterial.texture = scene.getContext().createTexture2D({
                            source : image
                        });
                    }
                };
                image.src = url;
            }
        }
        if (!existingMaterial.texture) {
            existingMaterial.texture = scene.getContext().createTexture2D({
                source : defaultImage
            });
        }
        return existingMaterial;
    };

    return DynamicImageMaterial;
});
{'fraction_non_alphanumeric': 0.0968895800933126, 'fraction_numerical': 0.013530326594090203, 'mean_word_length': 2.330398757120663, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '663197', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1835, 'n_words': 322}