/munum

Micro 3D Math Library for Rust, JavaScript and WebAssembly

Primary LanguageTypeScriptMIT LicenseMIT

🅼🆄🅽🆄🅼

μNum - Micro 3D Math Library in JavaScript and WebAssembly


License: MIT NPM size build

Overview

munum is a micro-sized, modular numerical library for high-performance 3D web applications. With munum, you can build isomorphic apps that targets both JavaScript via Babel/TypeScript, and WebAssembly via AssemblyScript using the same code base.

APIs

See TSDoc: http://andykswong.github.io/munum

Usage

Install via NPM for AssemblyScript or TypeScript projects:

npm install --save munum
import { vec4 } from 'munum';
const v = vec4.create();

Or load directly from CDN without having to use any build system:

<script type="module">
  import { vec4 } from 'https://unpkg.com/munum@latest';
  const v = vec4.create();
</script>

Sample usage to build a perspective camera view-projection matrix and frustum:

(Try it yourself here)

import { frustum, lookAt, mat4, perspective, vec3 } from 'munum'; // Or load from CDN

const eye = vec3.create(1, 1, 1);
const target = vec3.create(0, 0, 0);
const view = lookAt(eye, target);

const aspectRatio = width / height;
const yfov = Math.PI / 4;
const znear = 1;
const zfar = 100;
const proj = perspective(aspectRatio, yfov, znear, zfar);

const vp = mat4.mul(proj, view);
const f = frustum.fromViewProj(vp);

License

This repository and the code inside it is licensed under the MIT License. Read LICENSE for more information.