<commit_before>/* eslint no-unused-vars: "off" */
import DataTexture from '../texture/DataTexture';
import Vector3 from '../math/Vector3';
import Matrix3 from '../math/Matrix3';
import Matrix4 from '../math/Matrix4';
import log from '../utils/log';
import constants from '../constants';

const tempVector3 = new Vector3();
const tempMatrix3 = new Matrix3();
const tempMatrix4 = new Matrix4();
const tempFloat32Array4 = new Float32Array([0.5, 0.5, 0.5, 1]);
const tempFloat32Array2 = new Float32Array([0, 0]);
const blankInfo = {
    get() {
        return undefined;
    }
};

let camera;
let gl;
let lightManager;
let state;
let fog;
let renderer;

/**
 * 语义
 * @namespace semantic
 * @type {Object}
 */
const semantic = {
    /**
     * @type {WebGLState}
     */
    state: null,

    /**
     * @type {Camera}
     */
    camera: null,

    /**
     * @type {LightManager}
     */
    lightManager: null,

    /**
     * @type {Fog}
     */
    fog: null,

    /**
     * @type {WebGLRenderingContext}
     */
    gl: null,
    /**
     * WebGLRenderer
     * @type {WebGLRenderer}
     */
    renderer: null,

    blankInfo,

    /**
     * 初始化
     * @param  {WebGLState} _state
     * @param  {Camera} _camera
     * @param  {LightManager} _lightManager
     * @param  {Fog} _fog
     */
    init(_renderer, _state, _camera, _lightManager, _fog) {
        renderer = this._renderer = _renderer;
        state = this.state = _state;
        camera = this.camera = _camera;
        lightManager = this.lightManager = _lightManager;
        fog = this.fog = _fog;
        gl = this.gl = state.gl;
    },

    /**
     * 设置相机
     * @param {Camera} _camera
     */
    setCamera(_camera) {
        camera = this.camera = _camera;
    },

    /**
     * @param  {Texture|Color} value
     * @param  {number} textureIndex programInfo.textureIndex
     * @return {Float32Array|number}
     */
    handlerColorOrTexture(value, textureIndex) {
        if (value && value.isTexture) {
            return this.handlerTexture(value, textureIndex);
        }

        if (value && value.isColor) {
            value.toArray(tempFloat32Array4);
        } else {
            tempFloat32Array4[0] = tempFloat32Array4[1] = tempFloat32Array4[2] = 0.5;
        }

        return tempFloat32Array4;
    },

    /**
     * @param  {Texture} value
     * @param  {number} textureIndex programInfo.textureIndex
     * @return {number}
     */
    handlerTexture(value, textureIndex) {
        if (value && value.isTexture) {
            return this.handlerGLTexture(value.target, value.getGLTexture(state), textureIndex);
        }

        return undefined;
    },

    /**
     * @param  {GLenum} target
     * @param  {WebGLTexture} texture
     * @param  {number} textureIndex programInfo.textureIndex
     * @return {number}
     */
    handlerGLTexture(target, texture, textureIndex) {
        if (texture) {
            state.activeTexture(gl.TEXTURE0 + textureIndex);
            state.bindTexture(target, texture);
            return textureIndex;
        }

        return undefined;
    },

    /**
     * @param  {Texture} texture
     * @return {number} uv
     */
    handlerUV(texture) {
        if (texture && texture.isTexture) {
            return texture.uv || 0;
        }

        return 0;
    },

    // attributes

    /**
     * @type {semanticObject}
     */
    POSITION: {
        get(mesh, material, programInfo) {
            return mesh.geometry.vertices;
        }
    },

    /**
     * @type {semanticObject}
     */
    NORMAL: {
        get(mesh, material, programInfo) {
            return mesh.geometry.normals;
        }
    },

    /**
     * @type {semanticObject}
     */
    TANGENT: {
        get(mesh, material, programInfo) {
            const normalMap = material.normalMap || material.clearcoatNormalMap;
            if (normalMap && normalMap.isTexture) {
                if (Number(normalMap.uv) === 1) {
                    return mesh.geometry.tangents1;
                }
                return mesh.geometry.tangents;
            }

            return undefined;
        }
    },

    /**
     * @type {semanticObject}
     */
    TEXCOORD_0: {
        get(mesh, material, programInfo) {
            if (!mesh.geometry.uvs) {
                return undefined;
            }
            return mesh.geometry.uvs;
        }
    },

    /**
     * @type {semanticObject}
     */
    TEXCOORD_1: {
        get(mesh, material, programInfo) {
            if (!mesh.geometry.uvs1) {
                return undefined;
            }
            return mesh.geometry.uvs1;
        }
    },

    /**
     * @type {semanticObject}<commit_msg>fix: Semantic Tangent data should also be returned when there is no normal map<commit_after>/* eslint no-unused-vars: "off" */
import DataTexture from '../texture/DataTexture';
import Vector3 from '../math/Vector3';
import Matrix3 from '../math/Matrix3';
import Matrix4 from '../math/Matrix4';
import log from '../utils/log';
import constants from '../constants';

const tempVector3 = new Vector3();
const tempMatrix3 = new Matrix3();
const tempMatrix4 = new Matrix4();
const tempFloat32Array4 = new Float32Array([0.5, 0.5, 0.5, 1]);
const tempFloat32Array2 = new Float32Array([0, 0]);
const blankInfo = {
    get() {
        return undefined;
    }
};

let camera;
let gl;
let lightManager;
let state;
let fog;
let renderer;

/**
 * 语义
 * @namespace semantic
 * @type {Object}
 */
const semantic = {
    /**
     * @type {WebGLState}
     */
    state: null,

    /**
     * @type {Camera}
     */
    camera: null,

    /**
     * @type {LightManager}
     */
    lightManager: null,

    /**
     * @type {Fog}
     */
    fog: null,

    /**
     * @type {WebGLRenderingContext}
     */
    gl: null,
    /**
     * WebGLRenderer
     * @type {WebGLRenderer}
     */
    renderer: null,

    blankInfo,

    /**
     * 初始化
     * @param  {WebGLState} _state
     * @param  {Camera} _camera
     * @param  {LightManager} _lightManager
     * @param  {Fog} _fog
     */
    init(_renderer, _state, _camera, _lightManager, _fog) {
        renderer = this._renderer = _renderer;
        state = this.state = _state;
        camera = this.camera = _camera;
        lightManager = this.lightManager = _lightManager;
        fog = this.fog = _fog;
        gl = this.gl = state.gl;
    },

    /**
     * 设置相机
     * @param {Camera} _camera
     */
    setCamera(_camera) {
        camera = this.camera = _camera;
    },

    /**
     * @param  {Texture|Color} value
     * @param  {number} textureIndex programInfo.textureIndex
     * @return {Float32Array|number}
     */
    handlerColorOrTexture(value, textureIndex) {
        if (value && value.isTexture) {
            return this.handlerTexture(value, textureIndex);
        }

        if (value && value.isColor) {
            value.toArray(tempFloat32Array4);
        } else {
            tempFloat32Array4[0] = tempFloat32Array4[1] = tempFloat32Array4[2] = 0.5;
        }

        return tempFloat32Array4;
    },

    /**
     * @param  {Texture} value
     * @param  {number} textureIndex programInfo.textureIndex
     * @return {number}
     */
    handlerTexture(value, textureIndex) {
        if (value && value.isTexture) {
            return this.handlerGLTexture(value.target, value.getGLTexture(state), textureIndex);
        }

        return undefined;
    },

    /**
     * @param  {GLenum} target
     * @param  {WebGLTexture} texture
     * @param  {number} textureIndex programInfo.textureIndex
     * @return {number}
     */
    handlerGLTexture(target, texture, textureIndex) {
        if (texture) {
            state.activeTexture(gl.TEXTURE0 + textureIndex);
            state.bindTexture(target, texture);
            return textureIndex;
        }

        return undefined;
    },

    /**
     * @param  {Texture} texture
     * @return {number} uv
     */
    handlerUV(texture) {
        if (texture && texture.isTexture) {
            return texture.uv || 0;
        }

        return 0;
    },

    // attributes

    /**
     * @type {semanticObject}
     */
    POSITION: {
        get(mesh, material, programInfo) {
            return mesh.geometry.vertices;
        }
    },

    /**
     * @type {semanticObject}
     */
    NORMAL: {
        get(mesh, material, programInfo) {
            return mesh.geometry.normals;
        }
    },

    /**
     * @type {semanticObject}
     */
    TANGENT: {
        get(mesh, material, programInfo) {
            const normalMap = material.normalMap || material.clearcoatNormalMap;
            if (normalMap && normalMap.isTexture) {
                if (Number(normalMap.uv) === 1) {
                    return mesh.geometry.tangents1;
                }
            }
            return mesh.geometry.tangents;
        }
    },

    /**
     * @type {semanticObject}
     */
    TEXCOORD_0: {
        get(mesh, material, programInfo) {
            if (!mesh.geometry.uvs) {
                return undefined;
            }
            return mesh.geometry.uvs;
        }
    },

    /**
     * @type {semanticObject}
     */
    TEXCOORD_1: {
        get(mesh, material, programInfo) {
            if (!mesh.geometry.uvs1) {
                return undefined;
            }
            return mesh.geometry.uvs1;
        }
    },

    /**
     * @type {semanticObject}
{'fraction_non_alphanumeric': 0.12790945974802478, 'fraction_numerical': 0.01323937646807602, 'mean_word_length': 1.8103810381038103, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7116439', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2858, 'n_words': 608}