<commit_before>import { mat4, vec2, vec3, quat } from 'gl-matrix';
import { fromKeys, jsToGl, UniformStruct } from './utils.js';

class gltfLight
{
    constructor(type = "directional",
                color = [1, 1, 1],
                intensity = 1,
                innerConeAngle = 0.0,
                outerConeAngle = Math.PI / 4.0,
                range = -1.0, // if no range is defined in the json, this is the default the shader understands
                name = undefined,
                node = undefined)
    {
        this.type = type;
        this.color = color;
        this.intensity = intensity;
        this.innerConeAngle = innerConeAngle;
        this.outerConeAngle = outerConeAngle;
        this.range = range;
        this.name = name;
        this.node = node; // non-standard
    }

    fromJson(jsonLight)
    {
        fromKeys(this, jsonLight);
    }

    toUniform(gltf)
    {
        let uLight = new UniformLight();

        if (this.node !== undefined)
        {
            let transform = gltf.nodes[this.node].worldTransform;
            let rotation = quat.create();
            let alongNegativeZ = vec3.fromValues(0, 0, -1);
            mat4.getRotation(rotation, transform);
            vec3.transformQuat(uLight.direction, alongNegativeZ, rotation);
            mat4.getTranslation(uLight.position, transform);
        }

        uLight.range = this.range;
        uLight.color = jsToGl(this.color);
        uLight.intensity = this.intensity;

        uLight.innerConeCos = Math.cos(this.innerConeAngle);
        uLight.outerConeCos = Math.cos(this.outerConeAngle);

        switch(this.type)
        {
            case "spot":
                uLight.type = Type_Spot;
                break;
            case "point":
                uLight.type = Type_Point;
                break;
            case "directional":
            default:
                uLight.type = Type_Directional;
                break;
        }

        return uLight;
    }
}

const Type_Directional = 0;
const Type_Point = 1;
const Type_Spot = 2;

class UniformLight extends UniformStruct
{
    constructor()
    {
        super();

        const defaultDirection = vec3.fromValues(-0.7399, -0.6428, -0.1983);
        this.direction = defaultDirection;
        this.range = -1.0;

        this.color = jsToGl([1, 1, 1]);
        this.intensity = 1.0;

        this.position = jsToGl([0, 0, 0]);
        this.innerConeCos = 0.0;

        this.outerConeCos = Math.PI / 4.0;
        this.type = Type_Directional;
        this.padding = vec2.create();
    }<commit_msg>increased default light intensity from 1 to 2 (#129)<commit_after>import { mat4, vec2, vec3, quat } from 'gl-matrix';
import { fromKeys, jsToGl, UniformStruct } from './utils.js';

class gltfLight
{
    constructor(type = "directional",
                color = [1, 1, 1],
                intensity = 2,
                innerConeAngle = 0,
                outerConeAngle = Math.PI / 4,
                range = -1, // if no range is defined in the json, this is the default the shader understands
                name = undefined,
                node = undefined)
    {
        this.type = type;
        this.color = color;
        this.intensity = intensity;
        this.innerConeAngle = innerConeAngle;
        this.outerConeAngle = outerConeAngle;
        this.range = range;
        this.name = name;
        this.node = node; // non-standard
    }

    fromJson(jsonLight)
    {
        fromKeys(this, jsonLight);
    }

    toUniform(gltf)
    {
        let uLight = new UniformLight();

        if (this.node !== undefined)
        {
            let transform = gltf.nodes[this.node].worldTransform;
            let rotation = quat.create();
            let alongNegativeZ = vec3.fromValues(0, 0, -1);
            mat4.getRotation(rotation, transform);
            vec3.transformQuat(uLight.direction, alongNegativeZ, rotation);
            mat4.getTranslation(uLight.position, transform);
        }

        uLight.range = this.range;
        uLight.color = jsToGl(this.color);
        uLight.intensity = this.intensity;

        uLight.innerConeCos = Math.cos(this.innerConeAngle);
        uLight.outerConeCos = Math.cos(this.outerConeAngle);

        switch(this.type)
        {
            case "spot":
                uLight.type = Type_Spot;
                break;
            case "point":
                uLight.type = Type_Point;
                break;
            case "directional":
            default:
                uLight.type = Type_Directional;
                break;
        }

        return uLight;
    }
}

const Type_Directional = 0;
const Type_Point = 1;
const Type_Spot = 2;

class UniformLight extends UniformStruct
{
    constructor()
    {
        super();

        const defaultDirection = vec3.fromValues(-0.7399, -0.6428, -0.1983);
        this.direction = defaultDirection;
        this.range = -1;

        this.color = jsToGl([1, 1, 1]);
        this.intensity = 2;

        this.position = jsToGl([0, 0, 0]);
        this.innerConeCos = 0.0;

        this.outerConeCos = Math.PI / 4;
        this.type = Type_Directional;
        this.padding = vec2.create();
    }
{'fraction_non_alphanumeric': 0.10699826489300174, 'fraction_numerical': 0.02062849431270484, 'mean_word_length': 1.6978679147165887, 'pattern_counts': {'":': 6, '<': 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': '3544348', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1501, 'n_words': 342}