This fork are a solution for usage of glMatrix in Web Workers using the importScripts()
Simple, instead of exporting as a module are created a object like the module with methods.
worker.js:
// importing script on creation of classic worker.
// Considering are at same folder
importScripts("./gl-matrix.js");
// Create object
const glm = glmatrix();
onmessage = (e) => {
let r = glm.glMatrix.toRadian(e.data);
postMessage(r);
}
var glm;
var gl;
var canvas;
if( 'function' === typeof importScripts) {
importScripts("./gl-matrix.js");
glm = glmatrix();
addEventListener('message', onMessage);
function onMessage(e) {
data = e.data
if(gl == undefined){
// Initialize on first message
console.log("Renderer Thread Initializing...");
canvas = data.canvas;
gl = canvas.getContext("webgl2");
if(!gl) {console.error("RendererError: \n\nwebgl not supported!");}
initDemo()
}
}
}
function initDemo(){
// Your webgl application!
}
// See more of code in demo!
https://xt777br.github.io/gl-matrix-worker/demo/indigoCode/index.html
Original code from https://github.com/sessamekesh/IndigoCS-webgl-tutorials/tree/master/02%20-%20Rotating%20Cube
This is a not best to do that. But it´s very similar a module.
If you have better way you can send a pull request.
Javascript has evolved into a language capable of handling realtime 3D graphics, via WebGL, and computationally intensive tasks such as physics simulations. These types of applications demand high performance vector and matrix math, which is something that Javascript doesn't provide by default. glMatrix to the rescue!
glMatrix is designed to perform vector and matrix operations stupidly fast! By hand-tuning each function for maximum performance and encouraging efficient usage patterns through API conventions, glMatrix will help you get the most out of your browsers Javascript engine.
For documentation and news, visit the glMatrix Homepage
For a tutorial, see the "introducing glMatrix" section of Introduction to Computer Graphics by David J. Eck
For a babel plugin to make writing the API nicer, see babel-plugin-transfrom-gl-matrix
Regarding the current performance in modern web browsers, calling glMatrix.setMatrixArrayType(Array)
to use normal arrays instead of Float32Arrays can greatly increase the performance.
See CONTRIBUTING.md
See BUILDING.md