Skip to content

Instantly share code, notes, and snippets.

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

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.

obj2three.js

Usage:

node -r esm obj2three.js model.obj
@mrdoob
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
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
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
mrdoob / stack.js
Created Jun 4, 2020
Log the stack trace of a function
View stack.js
try { throw new Error; }
catch(e) {
console.log(e.stack);
}
@mrdoob
mrdoob / html2canvas.js
Created Mar 9, 2020
Paints a HTML node into a <canvas> (Very basic CSS support)
View html2canvas.js
/**
* @author mrdoob / http://mrdoob.com/
*/
function html2canvas( element ) {
var range = document.createRange();
function Clipper( context ) {
View css3drenderer.md
@mrdoob
mrdoob / adjoint.glsl
Created Sep 19, 2019
Matrix3.getNormalMatrix()
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:
// 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 Jun 10, 2019
ffmpeg: mov to gif
View mov2gif.sh
#!/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