This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******** CANVAS RECORDER | |
Invoke with: | |
import CanvasRecorder from "./canvasrecorder.js" | |
CanvasRecorder( yourCanvas ) | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Easing { | |
} | |
Easing.fns = function() { | |
var x = Math.pow | |
, C = Math.sqrt | |
, T = Math.sin | |
, q = Math.cos | |
, B = Math.PI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// **** This is for testing each number in the 32 bit uint random state individually. **** | |
//#define BIT_BY_BIT_DEBUG | |
#define saturate(a) clamp(a, 0.0, 1.0) | |
// ---- Random functions use one 32 bit state var to change things up ---- | |
// This is the single state variable for the random number generator. | |
uint randomState = 4056649889u; | |
// 0xffffff is biggest 2^n-1 that 32 bit float does exactly. | |
// Check with Math.fround(0xffffff) in javascript. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as THREE from 'https:/threejs.org/build/three.module.js' | |
import {GLTFExporter} from 'https:/threejs.org/examples/jsm/exporters/GLTFExporter.js' | |
fetch('./map.json').then(data=>data.json().then((js)=>{ | |
console.log(js) | |
let g = new THREE.PlaneGeometry(1,1) | |
g.attributes.normal.array=new Float32Array(js.normal.length) | |
g.attributes.normal.array.set(js.normal) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let takeScreenShot=()=>{ | |
let d=document; | |
let e = d.createElement("a"); | |
e.setAttribute("href", renderer.domElement.toDataURL("image/jpeg")); | |
e.setAttribute("download", "Screenshot.jpeg"); | |
e.style.display = "none"; | |
d.body.appendChild(e); | |
d.click(); | |
d.body.removeChild(e); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DEG2RAD = Math.PI / 180; | |
let updateProjectionMatrixHorizontalFOV = (camera)=>{ | |
const near = camera.near; | |
/* | |
let top = near * Math.tan( DEG2RAD * 0.5 * camera.fov ) / camera.zoom; | |
let height = 2 * top; | |
let width = camera.aspect * height; |
OlderNewer