# Code coverage report for src/plugin/Skydome.js

# all files / src/plugin/ Skydome.js

81.48% Statements 22/27
50% Branches 4/8
62.5% Functions 5/8
81.48% Lines 22/27

    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
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105

    1×

    1×

    1×

    1×

    1×

    1×

    1×
    1×
    1×

    1×

    1×
    1×

    1×

    1×
    1×

    1×
    1×
    1×

    1×

    6×
    6×
    6×

     import Mesh from '../Mesh';
    import SphereGeometry from '../geometry/Sphere';
    import Shader from '../Shader';
    import Material from '../Material';

    import basicEssl from '../shader/source/basic.glsl.js';
    Shader.import(basicEssl);
    /**
     * @constructor clay.plugin.Skydome
     *
     * @example
     *     var skyTex = new clay.Texture2D();
     *     skyTex.load('assets/textures/sky.jpg');
     *     var skydome = new clay.plugin.Skydome({
     *         scene: scene
     *     });
     *     skydome.material.set('diffuseMap', skyTex);
     */
    var Skydome = Mesh.extend(function () {

        var skydomeShader = new Shader(Shader.source('clay.basic.vertex'), Shader.source('clay.basic.fragment'));

        var material = new Material({
            shader: skydomeShader,
            depthMask: false
        });
        material.enableTexture('diffuseMap');

        return {
            /**
             * @type {clay.Scene}
             * @memberOf clay.plugin.Skydome#
             */
            scene: null,

            geometry: new SphereGeometry({
                widthSegments: 30,
                heightSegments: 30,
                // thetaLength: Math.PI / 2
            }),

            material: material,

            environmentMap: null,

            culling: false
        };
    }, function () {
        var scene = this.scene;
        Eif (scene) {
            this.attachScene(scene);
        }

        Iif (this.environmentMap) {
            this.setEnvironmentMap(this.environmentMap);
        }
    }, {
        /**
         * Attach the skybox to the scene
         * @param  {clay.Scene} scene
         * @memberOf clay.plugin.Skydome.prototype
         */
        attachScene: function (scene) {
            Eif (this.scene) {
                this.detachScene();
            }
            scene.skydome = this;

            this.scene = scene;
            scene.on('beforerender', this._beforeRenderScene, this);
        },
        /**
         * Detach from scene
         * @memberOf clay.plugin.Skydome.prototype
         */
        detachScene: function () {
            Eif (this.scene) {
                this.scene.off('beforerender', this._beforeRenderScene);
                this.scene.skydome = null;
            }
            this.scene = null;
        },

        _beforeRenderScene: function (renderer, scene, camera) {
            this.position.copy(camera.getWorldPosition());
            this.update();
            renderer.renderPass([this], camera);
        },

        setEnvironmentMap: function (envMap) {
            this.material.set('diffuseMap', envMap);
        },

        getEnvironmentMap: function () {
            return this.material.get('diffuseMap');
        },

        dispose: function (renderer) {
            this.detachScene();
            this.geometry.dispose(renderer);
        }
    });

    export default Skydome;