ftb-matrix

0.0.9 • Public • Published

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

  1. With npm :

    $ npm install --save ftb-matrix
  2. With yarn :

    $ yarn add ftb-matrix

Use

  1. Without CDN only :

    import ftbMatrix from 'ftb-matrix';
  2. 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();
  1. 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?).

  1. Enabling vector processing (SIMD) for even more speed (Chrome/Chromium only)
const { Mat } = await ftbMatrix({ simd: true });

Note: you can use { autodetect: true } instead of { simd: true }, for automatic fallback to standard code.

  1. More functions - see the ThreeJs documentation

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?

Dependencies (0)

    Dev Dependencies (5)

    Package Sidebar

    Install

    npm i ftb-matrix

    Weekly Downloads

    1

    Version

    0.0.9

    License

    MIT

    Unpacked Size

    341 kB

    Total Files

    14

    Last publish

    Collaborators

    • marcchambon