ftb-matrix
- fast & small (WebAssembly) single-precision matrix4x4 library
- ThreeJs-like interface
- targets both modern browsers and NodeJs (UMD module)
Installation
CDN
Insert the following script before the closing body tag of your index.html file and before the other scripts :
<script src="https://cdn.jsdelivr.net/npm/ftb-matrix@0.0.9/dist/ftb-matrix.js"></script>
Via package managers
-
With
npm
:$ npm install --save ftb-matrix -
With
yarn
:$ yarn add ftb-matrix
Use
-
Without CDN only :
; -
Getting the matrix constructor :
const Mat = await ;```0.
Examples
IMPORTANT: these matrices use the column-major convention.
- 101 : Getting an identity matrix
const mat = ;// getting the elements as a Float32Arrayconst arr = matelements;// freeing the memory allocated in the WebAssembly memory object.mat;
- Enabling garbage collection awareness
const Mat g = await ;const mat = ;;// no need to do: mat.free();
Note: tedious but could be automated with framework like Svelte (inserting g(_=>varialbe) at compile time?).
const Mat = await ;
Note: you can use { autodetect: true } instead of { simd: true }, for automatic fallback to standard code.
Contributing
Feedbacks are welcome (email or PM, see my Twitter account):
- Improving garbage collection awareness (is it possible to do it automatically? not sure because of closures...), by using WeakRef instead of WeakMap?