Skip to content

Instantly share code, notes, and snippets.

@mrdoob
mrdoob / convert.bash
Last active June 7, 2020 02:49
Batch convert draco/basis
for i in *.obj; do ../../draco/draco_encoder -i "$i"; done
for i in *.jpg; do sips -Z 2048 -s format png "$i" --out "$i".png; done
for i in *.png; do ../../basis/basisu -file "$i"; done
@mrdoob
mrdoob / stack.js
Created June 4, 2020 23:28
Log the stack trace of a function
try { throw new Error; }
catch(e) {
console.log(e.stack);
}
@mrdoob
mrdoob / html2canvas.js
Created March 9, 2020 23:36
Paints a HTML node into a <canvas> (Very basic CSS support)
/**
* @author mrdoob / http://mrdoob.com/
*/
function html2canvas( element ) {
var range = document.createRange();
function Clipper( context ) {
@mrdoob
mrdoob / adjoint.glsl
Created September 19, 2019 10:27
Matrix3.getNormalMatrix()
// Use to transform normals with transformation of
// arbitrary non-uniform scales (including negative)
// and skewing. The code assumes the last column of m is
// [0,0,0,1]. More info here:
// https://github.com/graphitemaster/normals_revisited
mat3 adjoint( in mat4 m )
{
return mat3(
m[1][1]*m[2][2]-m[1][2]*m[2][1],
@mrdoob
mrdoob / mov2gif.sh
Created June 10, 2019 22:27
ffmpeg: mov to gif
#!/bin/sh
palette="/tmp/palette.png"
filters="fps=25,scale=640:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
function JSONParseAsync( text, callback ) {
var code = 'onmessage = function ( e ) { postMessage( JSON.parse( e.data ) ); close(); }';
var blob = new Blob( [ code ], { type: 'text/plain' } );
var worker = new Worker( window.URL.createObjectURL( blob ) );
worker.addEventListener( 'message', function ( e ) { callback( e.data ); } );
worker.postMessage( text );
}
/**
* @author mrdoob / http://mrdoob.com/
*/
function Layers() {
this.mask = 1;
}