# all files / src/light/ Tube.js

33.33% Statements 3/9
100% Branches 0/0
20% Functions 1/5
33.33% Lines 3/9

    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

    1×

    1×
    1×

     import Light from '../Light';
    import Vector3 from '../math/Vector3';

    /**
     * @constructor clay.light.Tube
     * @extends {clay.Light}
     */
    var TubeLight = Light.extend(
    /** @lends clay.light.Tube# */
    {
        /**
         * @type {number}
         */
        range: 100,

        /**
         * @type {number}
         */
        length: 10
    }, {

        type: 'TUBE_LIGHT',

        uniformTemplates: {
            tubeLightPosition: {
                type: '3f',
                value: function(instance) {
                    return instance.getWorldPosition().array;
                }
            },

            tubeLightExtend: {
                type: '3f',
                value: (function() {
                    var x = new Vector3();
                    return function(instance) {
                        // Extend in x axis
                        return x.copy(instance.worldTransform.x)
                            .normalize().scale(instance.length / 2).array;
                    };
                })()
            },

            tubeLightRange: {
                type: '1f',
                value: function(instance) {
                    return instance.range;
                }
            },

            tubeLightColor: {
                type: '3f',
                value: function(instance) {
                    var color = instance.color;
                    var intensity = instance.intensity;
                    return [color[0]*intensity, color[1]*intensity, color[2]*intensity];
                }
            }
        }
    });

    export default TubeLight;