A simple and fast 3D math library for games and graphics. Written in TypeScript.
glam-js
is a TypeScript port of the incredible glam-rs library. Its primary objective is to provide a straightforward and efficient 3D math library for game development and computer graphics, written entirely in TypeScript.
Although some features specific to Rust are not available in TypeScript, glam-js
aims to offer a similar API.
Notable Changes:
- Unified types for number and boolean vectors
- Removal of Rust-specific methods related to the borrow checker
- Elimination of SIMD support
- Transition from
snake_case
tocamelCase
for naming conventions
glam-js
is currently in active development and is not yet suitable for production use. While some types are still missing, the Vector types have already been ported.
- ✨ Simple to use: since the code is generated, the API is super simple to understand
- 📦 0 dependencies
- 🔢
number
types- vectors:
Vec2
,Vec3
andVec4
- square matrices:
Mat2
,Mat3
,Mat3A
andMat4
(⚠️ PARTIAL, untested) a quaternion type:(Quat
⚠️ WIP)affine transformation types:(Affine2
andAffine3A
⚠️ WIP)
- vectors:
- ☑️
boolean
types- vectors:
BVec2
,BVec3
andBVec4
- vectors:
The design of this library is guided by a desire for simplicity and good performance.
- No generics and minimal type complexity in the public API for simplicity of usage
- Aiming for 100% test [coverage]
- Add the package to your project:
npm i glam-js
- Import the package into your project:
import { Vec3 } from "glam-js";
const vec = new Vec3(1, 2, 3);
vec.div(3);
vec.normalize();
The code in glam-js
is a direct port of the Rust library glam-rs, which in turn has inspirations for the interface and internals of glam from the
Rust and C++ worlds. In particular:
- How to write a maths library in 2016 inspired the initial
Vec3A
implementation - Realtime Math - header only C++11 with SSE and NEON SIMD intrinsic support
- DirectXMath - header only SIMD C++ linear algebra library for use in games and graphics apps
glam
is a play on the name of the popular C++ library GLM
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Contributions in any form (issues, pull requests, etc.) to this project must adhere to Rust's Code of Conduct and NPM's Code of Conduct.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
If you are interested in contributing or have a request or suggestion [start a discussion] on GitHub. See [CONTRIBUTING.md] (TBA) for more information for contributors.
Most code in glam-js
is generated, see the [codegen README] (TBA) for details.
glam
contains code ported from the following C++ libraries:
- DirectXMath - MIT License - Copyright (c) 2011-2020 Microsoft Corp
- Realtime Math - MIT License - Copyright (c) 2018 Nicholas Frechette
- GLM - MIT License - Copyright (c) 2005 - G-Truc Creation
See ATTRIBUTION.md for details.