0.0.9 • Published 4 years ago
ftb-matrix v0.0.9
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 :
import ftbMatrix from 'ftb-matrix';
Getting the matrix constructor :
const { Mat } = await ftbMatrix(); ```0.
Examples
IMPORTANT: these matrices use the column-major convention. 1. 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.
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?