# all files / src/geometry/ Plane.js

100% Statements 29/29
75% Branches 6/8
100% Functions 2/2
100% Lines 29/29

    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

    1×

    217×

    217×
    217×
    217×
    217×
    217×
    217×
    217×

    217×
    467×
    467×
    982×

    982×
    982×
    982×

    982×
    982×

    982×
    282×
    282×
    282×

    217×
    217×
    217×

    217×

    217×
    217×
    217×

     import Geometry from '../Geometry';
    import BoundingBox from '../math/BoundingBox';

    /**
     * @constructor clay.geometry.Plane
     * @extends clay.Geometry
     * @param {Object} [opt]
     * @param {number} [opt.widthSegments]
     * @param {number} [opt.heightSegments]
     */
    var Plane = Geometry.extend(
    /** @lends clay.geometry.Plane# */
    {
        dynamic: false,
        /**
         * @type {number}
         */
        widthSegments: 1,
        /**
         * @type {number}
         */
        heightSegments: 1
    }, function() {
        this.build();
    },
    /** @lends clay.geometry.Plane.prototype */
    {
        /**
         * Build plane geometry
         */
        build: function() {
            var heightSegments = this.heightSegments;
            var widthSegments = this.widthSegments;
            var attributes = this.attributes;
            var positions = [];
            var texcoords = [];
            var normals = [];
            var faces = [];

            for (var y = 0; y <= heightSegments; y++) {
                var t = y / heightSegments;
                for (var x = 0; x <= widthSegments; x++) {
                    var s = x / widthSegments;

                    positions.push([2 * s - 1, 2 * t - 1, 0]);
                    Eif (texcoords) {
                        texcoords.push([s, t]);
                    }
                    Eif (normals) {
                        normals.push([0, 0, 1]);
                    }
                    if (x < widthSegments && y < heightSegments) {
                        var i = x + y * (widthSegments + 1);
                        faces.push([i, i + 1, i + widthSegments + 1]);
                        faces.push([i + widthSegments + 1, i + 1, i + widthSegments + 2]);
                    }
                }
            }

            attributes.position.fromArray(positions);
            attributes.texcoord0.fromArray(texcoords);
            attributes.normal.fromArray(normals);

            this.initIndicesFromArray(faces);

            this.boundingBox = new BoundingBox();
            this.boundingBox.min.set(-1, -1, 0);
            this.boundingBox.max.set(1, 1, 0);
        }
    });

    export default Plane;