<commit_before>goog.provide('og.node.SkyBox');

goog.require('og.inheritance');
goog.require('og.node.RenderNode');

og.node.SkyBox = function () {
    og.inheritance.base(this, "skybox");
    this.size = 1;

    this.vertexPositionBuffers = new Array(6);
    this.vertexIndexBuffers = new Array(6);
    this.vertexTextureCoordBuffers = new Array(6);

    this.textures = new Array(6);
    this.texturesFileName = new Array(6);
    this.spath = og.RESOURCES_URL + "images/skyboxes/tycho/";
};

og.inheritance.extend(og.node.SkyBox, og.node.RenderNode);

og.node.SkyBox.FRONT_PLANE = 0;
og.node.SkyBox.BACK_PLANE = 1;
og.node.SkyBox.TOP_PLANE = 2;
og.node.SkyBox.BOTTOM_PLANE = 3;
og.node.SkyBox.RIGHT_PLANE = 4;
og.node.SkyBox.LEFT_PLANE = 5;

og.node.SkyBox.prototype.initialization = function () {

    this.initTexture(this.spath + "pz.jpg", og.node.SkyBox.FRONT_PLANE);
    this.initTexture(this.spath + "nz.jpg", og.node.SkyBox.BACK_PLANE);
    this.initTexture(this.spath + "py.jpg", og.node.SkyBox.TOP_PLANE);
    this.initTexture(this.spath + "ny.jpg", og.node.SkyBox.BOTTOM_PLANE);
    this.initTexture(this.spath + "px.jpg", og.node.SkyBox.RIGHT_PLANE);
    this.initTexture(this.spath + "nx.jpg", og.node.SkyBox.LEFT_PLANE);

    this.createBuffers();
    this.drawMode = this.renderer.handler.gl.TRIANGLES;
}

og.node.SkyBox.prototype.initTexture = function (fileName, plane) {
    var image = new Image();
    var that = this;
    image.onload = function () {
        that.textures[plane] = that.renderer.handler.createTextureFromImage(image);
    }
    image.src = this.texturesFileName[plane] = fileName;
};

og.node.SkyBox.prototype.frame = function () {

    this.renderer.handler.gl.disable(this.renderer.handler.gl.DEPTH_TEST);
    this.renderer.handler.shaderPrograms.skybox.activate();

    this.renderer.handler.shaderPrograms.skybox.set({
        uPMVMatrix: this.renderer.activeCamera.pmvMatrix._m,
        pos: this.renderer.activeCamera.eye.toVec()
    });

    for (var i = 0; i < 6; i++) {
        this.renderer.handler.shaderPrograms.skybox.set({
            uSampler: this.textures[i],
            aVertexPosition: this.vertexPositionBuffers[i],
            aTextureCoord: this.vertexTextureCoordBuffers[i]
        });

        this.renderer.handler.shaderPrograms.skybox.drawIndexBuffer(this.drawMode, this.vertexIndexBuffers[i]);
    }
    this.renderer.handler.gl.enable(this.renderer.handler.gl.DEPTH_TEST);
};

og.node.SkyBox.prototype.createBuffers = function () {
    var vertices = [
      // Front face
      [-1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
       1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
       1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
      -1.0 * this.size, 1.0 * this.size, 1.0 * this.size],

      // Back face
      [-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
      -1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
       1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
       1.0 * this.size, -1.0 * this.size, -1.0 * this.size],

      // Top face
      [-1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
      -1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
       1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
       1.0 * this.size, 1.0 * this.size, -1.0 * this.size],

      // Bottom face
      [-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
       1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
       1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
      -1.0 * this.size, -1.0 * this.size, 1.0 * this.size],

      // Right face
      [1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
       1.0 * this.size, 1.0 * this.size, -1.0 * this.size,
       1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
       1.0 * this.size, -1.0 * this.size, 1.0 * this.size],

      // Left face
      [-1.0 * this.size, -1.0 * this.size, -1.0 * this.size,
      -1.0 * this.size, -1.0 * this.size, 1.0 * this.size,
      -1.0 * this.size, 1.0 * this.size, 1.0 * this.size,
      -1.0 * this.size, 1.0 * this.size, -1.0 * this.size]];

    var vertexIndices = [
      [0, 3, 2, 0, 2, 1], // Front face
      [0, 3, 2, 0, 2, 1], // Back face
      [0, 3, 2, 0, 2, 1], // Top face
      [0, 3, 2, 0, 2, 1], // Bottom face
      [0, 3, 2, 0, 2, 1], // Right face
      [0, 3, 2, 0, 2, 1]  // Left face
    ]

    var textureCoords = [
      // Front face
      [0.0, 0.0,
      1.0, 0.0,
      1.0, 1.0,
      0.0, 1.0],

      // Back face
      [1.0, 0.0,
      1.0, 1.0,
      0.0, 1.0,
      0.0, 0.0],

      // Top face
      [0.0, 1.0,
      0.0, 0.0,
      1.0, 0.0,
      1.0, 1.0],

      // Bottom face
      [0.0, 0.0,
      1.0, 0.0,
      1.0, 1.0,
      0.0, 1.0],

      // Right face
      [1.0, 0.0,
      1.0, 1.0,
      0.0, 1.0,
      0.0, 0.0],

      // Left face
      [0.0, 0.0,
      1.0, 0.0,
      1.0, 1.0,
      0.0, 1.0]
    ];

    for (var i = 0; i < 6; i++) {
        this.vertexPositionBuffers[i] = this.renderer.handler.createArrayBuffer(new Float32Array(vertices[i]), 3, 4);
        this.vertexTextureCoordBuffers[i] = this.renderer.handler.createArrayBuffer(new Float32Array(textureCoords[i]), 2, 4);
        this.vertexIndexBuffers[i] = this.renderer.handler.createElementArrayBuffer(new Uint16Array(vertexIndices[i]), 1, 6);
    }
};<commit_msg>SkyBox to the cube textures refactoring.<commit_after>goog.provide('og.node.SkyBox');

goog.require('og.inheritance');
goog.require('og.node.RenderNode');
goog.require('og.shaderProgram.skybox');

og.node.SkyBox = function (params) {
    og.inheritance.base(this, "skybox");
    this.params = params;

    this.vertexPositionBuffer = null;
    this.texture = null;
};

og.inheritance.extend(og.node.SkyBox, og.node.RenderNode);

og.node.SkyBox.prototype.initialization = function () {
    this.renderer.handler.addShaderProgram(og.shaderProgram.skybox, true);
    this.texture = this.renderer.handler.loadCubeMapTexture(this.params);
    this.createBuffers();
    this.drawMode = this.renderer.handler.gl.TRIANGLES;
};

og.node.SkyBox.prototype.frame = function () {
    var h = this.renderer.handler;
    h.gl.disable(h.gl.DEPTH_TEST);

    h.shaderPrograms.skybox.activate();
    h.shaderPrograms.skybox.set({
        uPMVMatrix: this.renderer.activeCamera.pmvMatrix._m,
        pos: this.renderer.activeCamera.eye.toVec(),
        uSampler: this.texture,
        aVertexPosition: this.vertexPositionBuffer
    });
    h.shaderPrograms.skybox.drawArray(this.drawMode, this.vertexPositionBuffer.numItems);

    h.gl.enable(h.gl.DEPTH_TEST);
};

og.node.SkyBox.prototype.createBuffers = function () {
    var points = [
        -100.0, 100.0, -100.0,
        -100.0, -100.0, -100.0,
         100.0, -100.0, -100.0,
         100.0, -100.0, -100.0,
         100.0, 100.0, -100.0,
        -100.0, 100.0, -100.0,

        -100.0, -100.0, 100.0,
        -100.0, -100.0, -100.0,
        -100.0, 100.0, -100.0,
        -100.0, 100.0, -100.0,
        -100.0, 100.0, 100.0,
        -100.0, -100.0, 100.0,

         100.0, -100.0, -100.0,
         100.0, -100.0, 100.0,
         100.0, 100.0, 100.0,
         100.0, 100.0, 100.0,
         100.0, 100.0, -100.0,
         100.0, -100.0, -100.0,

        -100.0, -100.0, 100.0,
        -100.0, 100.0, 100.0,
         100.0, 100.0, 100.0,
         100.0, 100.0, 100.0,
         100.0, -100.0, 100.0,
        -100.0, -100.0, 100.0,

        -100.0, 100.0, -100.0,
         100.0, 100.0, -100.0,
         100.0, 100.0, 100.0,
         100.0, 100.0, 100.0,
        -100.0, 100.0, 100.0,
        -100.0, 100.0, -100.0,

        -100.0, -100.0, -100.0,
        -100.0, -100.0, 100.0,
         100.0, -100.0, -100.0,
         100.0, -100.0, -100.0,
        -100.0, -100.0, 100.0,
         100.0, -100.0, 100.0
    ];

    this.vertexPositionBuffer = this.renderer.handler.createArrayBuffer(new Float32Array(points), 3, 36);
};
{'fraction_non_alphanumeric': 0.18374603174603174, 'fraction_numerical': 0.09409523809523809, 'mean_word_length': 2.086206896551724, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1641389', 'n_tokens_mistral': 3588, 'n_tokens_neox': 3175, 'n_words': 569}