# all files / src/loader/ FX.js

12.5% Statements 1/8
0% Branches 0/4
0% Functions 0/4
12.5% Lines 1/8

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66

    1×

     import Base from '../core/Base';
    import request from '../core/request';
    import createCompositor from '../createCompositor';

    /**
     * @constructor clay.loader.FX
     * @extends clay.core.Base
     */
    var FXLoader = Base.extend(/** @lends clay.loader.FX# */ {
        /**
         * @type {string}
         */
        rootPath: '',
        /**
         * @type {string}
         */
        textureRootPath: '',
        /**
         * @type {string}
         */
        shaderRootPath: '',

        /**
         * @type {clay.Scene}
         */
        scene: null,

        /**
         * @type {clay.Camera}
         */
        camera: null
    },
    /** @lends clay.loader.FX.prototype */
    {
        /**
         * @param  {string} url
         */
        load: function(url) {
            var self = this;

            if (!this.rootPath) {
                this.rootPath = url.slice(0, url.lastIndexOf('/'));
            }

            request.get({
                url: url,
                onprogress: function(percent, loaded, total) {
                    self.trigger('progress', percent, loaded, total);
                },
                onerror: function(e) {
                    self.trigger('error', e);
                },
                responseType: 'text',
                onload: function (data) {
                    createCompositor(JSON.parse(data), {
                        textureRootPath: this.textureRootPath || this.rootPath,
                        camera: this.camera,
                        scene: this.scene
                    });
                }
            });
        }
    });

    export default FXLoader;