- fast & small (WebAssembly) single-precision matrix4x4 library
- ThreeJs-like interface
- targets both modern browsers and NodeJs (UMD module)
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>
-
With
npm
:$ npm install --save ftb-matrix
-
With
yarn
:$ yarn add ftb-matrix
-
Without CDN only :
import ftbMatrix from 'ftb-matrix';
-
Getting the matrix constructor :
const { Mat } = await ftbMatrix();
IMPORTANT: these matrices use the column-major convention.
- 101 : Getting an identity matrix
const mat = new Mat();
// getting the elements as a Float32Array
const arr = mat.elements;
// freeing the memory allocated in the WebAssembly memory object.
mat.free();
- Enabling garbage collection awareness
const { Mat, g } = await ftbMatrix({ autoFree });
const mat = new Mat();g(_=>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 ftbMatrix({ simd: true });
Note: you can use { autodetect: true } instead of { simd: true }, for automatic fallback to standard code.
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?