Skip to content

Instantly share code, notes, and snippets.

mrdoob /
Created Feb 17, 2021
Test module treeshaking
echo "import { Matrix4 } from './src/math/Matrix4.js'" | npx rollup -f es
mrdoob /
Created Dec 23, 2020
Three.js Converters (Node.js)

Utilities for converting model files to the Three.js JSON format. It's necessary to install the esm npm package before you can use the converters.



node -r esm obj2three.js model.obj
mrdoob / gist:00e94d2934246c1fa32a52d39fa63776
Created Nov 11, 2020
Raindrops in Emergency Light by Citavia
View gist:00e94d2934246c1fa32a52d39fa63776
data:text/html,<canvas id=R style=width:99%;background:navy><script>setInterval("s=Math.sin;q= Math.sqrt;d=(N,M,O,a)=>1/q((N-x+50-a/2)**2+(M-y+50-a%2)**2+(O-z+o)**2);f=a=>d(i,j,k,a)+d(j,-i,i,a)+d(k,i,-j,a)-.1-A;O=R.getContext('2d');i=s(n/2)* o;j=s(n+=.1)*o;k=s(n/3)*o;for(y=h;y--;)for(x=h;x--;){B=m=z=-o;for(r=9;m++;z+=r)A=0,A=f(0),A*B<0&&(r/=-2),B=A;z++;Z=f(0);z--;C=f(2)/Z;D=f(1)/Z;O.fillStyle='rgb('+s(n)*o/q(C*C+D*D)+',0,'+(C*h+n^D*h+n)+')';O.fillRect(x+h,y+o,1,1)}",n=o=25,h=99)</script>
mrdoob / responsive_imagemap.js
Last active Oct 1, 2020
Responsive image map coords
View responsive_imagemap.js
// @mrdoob: Can't believe image maps aren't responsive
window.onload = function () {
var image = document.getElementById( 'image' );
var delta = image.clientWidth / 1024;
var map = document.getElementById( 'map' );
var areas = map.getElementsByTagName( 'area' );
mrdoob / convert.bash
Last active Jun 7, 2020
Batch convert draco/basis
View convert.bash
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 / stack.js
Created Jun 4, 2020
Log the stack trace of a function
View stack.js
try { throw new Error; }
catch(e) {
mrdoob / html2canvas.js
Created Mar 9, 2020
Paints a HTML node into a <canvas> (Very basic CSS support)
View html2canvas.js
* @author mrdoob /
function html2canvas( element ) {
var range = document.createRange();
function Clipper( context ) {
mrdoob / adjoint.glsl
Created Sep 19, 2019
View adjoint.glsl
// 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:
mat3 adjoint( in mat4 m )
return mat3(
mrdoob /
Created Jun 10, 2019
ffmpeg: mov to gif
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