UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

325 lines (302 loc) 6.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Vector4Uniform = exports.Vector3Uniform = exports.Vector2Uniform = exports.NumberUniform = exports.Matrix4Uniform = exports.Matrix3Uniform = exports.Matrix2Uniform = exports.ColorUniform = void 0; var _Color = require("../../math/Color.js"); var _Matrix = require("../../math/Matrix2.js"); var _Matrix2 = require("../../math/Matrix3.js"); var _Matrix3 = require("../../math/Matrix4.js"); var _Vector = require("../../math/Vector2.js"); var _Vector2 = require("../../math/Vector3.js"); var _Vector3 = require("../../math/Vector4.js"); /** * Abstract base class for uniforms. * * @abstract * @private */ class Uniform { /** * Constructs a new uniform. * * @param {string} name - The uniform's name. * @param {any} value - The uniform's value. */ constructor(name, value) { /** * The uniform's name. * * @type {string} */ this.name = name; /** * The uniform's value. * * @type {any} */ this.value = value; /** * Used to build the uniform buffer according to the STD140 layout. * Derived uniforms will set this property to a data type specific * value. * * @type {number} */ this.boundary = 0; /** * The item size. Derived uniforms will set this property to a data * type specific value. * * @type {number} */ this.itemSize = 0; /** * This property is set by {@link UniformsGroup} and marks * the start position in the uniform buffer. * * @type {number} */ this.offset = 0; } /** * Sets the uniform's value. * * @param {any} value - The value to set. */ setValue(value) { this.value = value; } /** * Returns the uniform's value. * * @return {any} The value. */ getValue() { return this.value; } } /** * Represents a Number uniform. * * @private * @augments Uniform */ class NumberUniform extends Uniform { /** * Constructs a new Number uniform. * * @param {string} name - The uniform's name. * @param {number} value - The uniform's value. */ constructor(name, value = 0) { super(name, value); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isNumberUniform = true; this.boundary = 4; this.itemSize = 1; } } /** * Represents a Vector2 uniform. * * @private * @augments Uniform */ exports.NumberUniform = NumberUniform; class Vector2Uniform extends Uniform { /** * Constructs a new Number uniform. * * @param {string} name - The uniform's name. * @param {Vector2} value - The uniform's value. */ constructor(name, value = new _Vector.Vector2()) { super(name, value); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isVector2Uniform = true; this.boundary = 8; this.itemSize = 2; } } /** * Represents a Vector3 uniform. * * @private * @augments Uniform */ exports.Vector2Uniform = Vector2Uniform; class Vector3Uniform extends Uniform { /** * Constructs a new Number uniform. * * @param {string} name - The uniform's name. * @param {Vector3} value - The uniform's value. */ constructor(name, value = new _Vector2.Vector3()) { super(name, value); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isVector3Uniform = true; this.boundary = 16; this.itemSize = 3; } } /** * Represents a Vector4 uniform. * * @private * @augments Uniform */ exports.Vector3Uniform = Vector3Uniform; class Vector4Uniform extends Uniform { /** * Constructs a new Number uniform. * * @param {string} name - The uniform's name. * @param {Vector4} value - The uniform's value. */ constructor(name, value = new _Vector3.Vector4()) { super(name, value); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isVector4Uniform = true; this.boundary = 16; this.itemSize = 4; } } /** * Represents a Color uniform. * * @private * @augments Uniform */ exports.Vector4Uniform = Vector4Uniform; class ColorUniform extends Uniform { /** * Constructs a new Number uniform. * * @param {string} name - The uniform's name. * @param {Color} value - The uniform's value. */ constructor(name, value = new _Color.Color()) { super(name, value); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isColorUniform = true; this.boundary = 16; this.itemSize = 3; } } /** * Represents a Matrix2 uniform. * * @private * @augments Uniform */ exports.ColorUniform = ColorUniform; class Matrix2Uniform extends Uniform { /** * Constructs a new Number uniform. * * @param {string} name - The uniform's name. * @param {Matrix2} value - The uniform's value. */ constructor(name, value = new _Matrix.Matrix2()) { super(name, value); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isMatrix2Uniform = true; this.boundary = 16; this.itemSize = 4; } } /** * Represents a Matrix3 uniform. * * @private * @augments Uniform */ exports.Matrix2Uniform = Matrix2Uniform; class Matrix3Uniform extends Uniform { /** * Constructs a new Number uniform. * * @param {string} name - The uniform's name. * @param {Matrix3} value - The uniform's value. */ constructor(name, value = new _Matrix2.Matrix3()) { super(name, value); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isMatrix3Uniform = true; this.boundary = 48; this.itemSize = 12; } } /** * Represents a Matrix4 uniform. * * @private * @augments Uniform */ exports.Matrix3Uniform = Matrix3Uniform; class Matrix4Uniform extends Uniform { /** * Constructs a new Number uniform. * * @param {string} name - The uniform's name. * @param {Matrix4} value - The uniform's value. */ constructor(name, value = new _Matrix3.Matrix4()) { super(name, value); /** * This flag can be used for type testing. * * @type {boolean} * @readonly * @default true */ this.isMatrix4Uniform = true; this.boundary = 64; this.itemSize = 16; } } exports.Matrix4Uniform = Matrix4Uniform;