Skip to content

Instantly share code, notes, and snippets.

View manthrax's full-sized avatar

Michael Schlachter manthrax

View GitHub Profile
@manthrax
manthrax / gist:3724dac17379782794bd0e602637d7c5
Last active March 16, 2021 19:52
InstanceGroup abstraction for THREEJS.
import*as THREE from "https://threejs.org/build/three.module.js"
class InstanceCache {
constructor(geometry, material, startingCount) {
const mesh = (this.mesh = new THREE.InstancedMesh(
geometry.clone(),
material.clone(),
startingCount
));
mesh.userData.max = startingCount;
@manthrax
manthrax / gist:8e9d71ed5efe2f865846d3516d029fc0
Created February 9, 2021 20:07
Save/Load camera/controls target
/**
* Use the Web Storage API to save camera position and target between page refreshes.
*
* @param {Object} options
* @param {*} options.camera - The camera you want to store the position of.
* @param {*} [options.controls] - A controls object with a `.target` property.
* @param {String} [options.name="main"] - An optional label. Useful if you want to store multiple cameras.
* @param {Boolean} [options.session=true] - Indicates if you want to use local or session storage.
* See https://developer.mozilla.org/en-US/docs/Web/API/Storage
*/
class Easing {
}
Easing.fns = function() {
var x = Math.pow
, C = Math.sqrt
, T = Math.sin
, q = Math.cos
, B = Math.PI
/******** CANVAS RECORDER
Invoke with:
import CanvasRecorder from "./canvasrecorder.js"
CanvasRecorder( yourCanvas )
*/
@manthrax
manthrax / wichmann_hill_random.js
Created June 15, 2020 08:08
js wichmann hill rng.. untested.. drop in replacement for Math.random.. uses zelda ww seed by default
let wichmann_hill_rng = (s1=100,s2=100,s3=100)=>()=>((s1 = (171 * s1) % 30269) / 30269 + (s2 = (172 * s1) % 30307) / 30307 + (s3 = (170 * s1) % 30323) / 30323) % 1
let rng = wichmann_hill_rng()
for (let i = 0; i < 1000; i++) console.log(rng())
class vec3 {
set(x=0, y=0, z=0) {
this.x = x;
this.y = y;
this.z = z;
return this;
}
copy(v) {
return this.set(v.x, v.y, v.z)
}