Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Javascript Matrix and Vector library for High Performance 3D web apps
The gl-matrix npm package is a high-performance matrix and vector operations library for WebGL and other JavaScript applications that require mathematical operations on vectors and matrices. It is optimized for performance and memory usage and provides a clean API for a variety of mathematical operations.
Matrix Operations
Perform operations on 4x4 matrices such as creation, translation, rotation, scaling, and more.
const mat4 = require('gl-matrix').mat4;
let matrix = mat4.create();
mat4.translate(matrix, matrix, [2, 3, 4]);
mat4.rotateX(matrix, matrix, Math.PI / 4);
Vector Operations
Perform operations on 3D vectors such as setting values, normalization, cross product, dot product, and more.
const vec3 = require('gl-matrix').vec3;
let vector = vec3.create();
vec3.set(vector, 1, 2, 3);
vec3.normalize(vector, vector);
Quaternion Operations
Perform operations on quaternions for representing rotations such as creating a quaternion, rotating it, inverting it, and more.
const quat = require('gl-matrix').quat;
let quaternion = quat.create();
quat.rotateX(quaternion, quaternion, Math.PI / 2);
quat.invert(quaternion, quaternion);
Three.js is a comprehensive 3D graphics library for JavaScript that includes its own set of vector and matrix math utilities. It is more feature-rich than gl-matrix as it is a full 3D engine, but it is also larger and less focused solely on math operations.
Math.gl is a suite of math modules for WebGL-focused applications, offering similar functionalities to gl-matrix. It provides a wider set of math utilities, including additional classes for working with geometries, cameras, and more.
Vecmath is a vector and matrix math library for JavaScript that is similar to gl-matrix but with a different API design. It may not be as optimized for performance as gl-matrix.
glMatrix is a high performance, very flexible library for vector and matrix operations in JavaScript/TypeScript, designed for the needs of realtime 3D graphics APIs like WebGL and WebGPU.
Documentation is available at https://glmatrix.net/docs/v4/
If your use case requires additional precision beyond the default 32-bit floats used by default, you can instead use a 64-bit verions of the library by importing from the f64/
directory of your chosen build type. For example:
import { Vec3 } from './gl-matrix/dist/esm/f64/vec3.js';
If you have a need to mix and match the 64 bit and 32 bit versions, you can do so by importing them as different names:
import { Vec3 as Vec3F32 } from './gl-matrix/dist/esm/vec3.js';
import { Vec3 as Vec3F64 } from './gl-matrix/dist/esm/f64/vec3.js';
All API calls are identical between the two versions, the only difference is the type of TypedArray which the classes extend.
FAQs
Javascript Matrix and Vector library for High Performance WebGL apps
The npm package gl-matrix receives a total of 1,478,890 weekly downloads. As such, gl-matrix popularity was classified as popular.
We found that gl-matrix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.