View on GitHub

spherical-harmonizer

A small TypeScript library to generate Spherical Harmonics representations of HDRI maps.

Spherical Harmonizer

A Typescript library to generate L2 spherical harmonics.

Example

Web interface

Documentation

Code reference

There’s only one relevant method to be called:

generateSH(data, width, height, onComplete, onProgress, options)

Here’s an example:

import { decodeRGBE } from "@derschmale/io-rgbe";
import { generateSH } from "@derschmale/spherical-harmonizer"; 


function convert(arrayBuffer) {
    const hdr = decodeRGBE(new DataView(arrayBuffer));
    generateSH(hdr.data, hdr.width, hdr.height, onComplete);
}

function onComplete(sh)
{
    // do something with sh coefficients
}

const request = new XMLHttpRequest();
request.open("GET", "/panorama.hdr", true);
request.responseType = "arraybuffer";
request.onload = _ => {
    const arrayBuffer = request.response; // Note: not oReq.responseText
    if (arrayBuffer)
        convert(arrayBuffer);
};

request.send(null);




Building

Building the code is simples:

npm install
npm run build