Skip to content

Instantly share code, notes, and snippets.

View sketchpunk's full-sized avatar
🏠
Working from home

SketchPunk sketchpunk

🏠
Working from home
View GitHub Profile
@sketchpunk
sketchpunk / _roundedline.js
Last active January 4, 2023 15:18
Round the edges of a multi part line or 2d polygon in a flat array of vec3
/*
const pnts = [
-2,0,-2,
-2,0,2,
2,0,2,
4,0,1,
];
const poly = roundedline( pnts );
const buf = new Vec3Buffer( poly );
@sketchpunk
sketchpunk / _polyline.js
Last active January 4, 2023 15:18
Polyline from flat array of Vector 3
/*
NOTES
https://blog.scottlogic.com/2019/11/18/drawing-lines-with-webgl.html
EXAMPLE
const pnts = [
-2,0,-2,
-2,0,2,
2,0,2,
4,0,0,
@sketchpunk
sketchpunk / iterFlatVec3Buf.js
Last active December 8, 2022 20:59
iterators
/*
const pnts = [-2,0,-2,-2,0,2,2,0,2,2,0,-2];
for( let v of iterFlatVec3Buf( pnts ) ) console.log( v );
instead of
const v = [0,0,0];
for( let i=0; i < pnts.length; i+=3 ){
v[0] = pnts[i+0];
v[1] = pnts[i+1];
@sketchpunk
sketchpunk / FetchBatch.js
Last active April 4, 2024 02:16
Various Fetch / Downloading functions or Objects
function nanoID( t=21 ){
const r = crypto.getRandomValues( new Uint8Array( t ) );
let n, e = '';
for( ;t--; ){
n = 63 & r[ t ];
e += ( n < 36 )? n.toString( 36 ) :
( n < 62 )? ( n - 26 ).toString( 36 ).toUpperCase() :
( n < 63 )? '_' : '-';
}
return e;
@sketchpunk
sketchpunk / KeyboardEvents.js
Last active November 17, 2022 16:25
Movement functions for use with ThreeJS Camera, Also inc Springs, Mouse/Keboard Event Handlers
function KeyboardEvents(){
let self;
const keys = new Map(); // State of a key press, lets user hold down multiple buttons
// #region HANDLERS
const onKeyDown = e=>{ keys.set( e.key, true ); };
const onKeyUp = e=>{ keys.set( e.key, false ); };
// #endregion
// #region MAIN
@sketchpunk
sketchpunk / _useThreeWebGL2.js
Last active November 17, 2022 15:22
useThreeWebGL2 & faceCube
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
/*
const App = useThreeWebGL2();
App.scene.add( facedCube( [0,3,0], 6 ) );
App
.sphericalLook( 45, 35, 40 )
.renderLoop();
*/
@sketchpunk
sketchpunk / resolvedShaderPromise.js
Last active November 2, 2022 21:59
Resolve shader code of three,js materials
import { ShaderChunk } from 'three';
/*
USAGE
const geo = new THREE.BoxGeometry( 1, 1, 1 );
const mat = new THREE.PointsMaterial( { size: 0.5, vertexColors: true } );
const mesh = new THREE.Points( geo, mat );
resolvedShaderPromise( mat ).
then( sh => console.log( sh ) );
*/
@sketchpunk
sketchpunk / FetchQueue.js
Last active October 7, 2022 21:25
Fetch Download Queue
function nanoID( t=21 ){
const r = crypto.getRandomValues( new Uint8Array( t ) );
let n, e = '';
for( ;t--; ){
n = 63 & r[ t ];
e += ( n < 36 )? n.toString( 36 ) :
( n < 62 )? ( n - 26 ).toString( 36 ).toUpperCase() :
( n < 63 )? '_' : '-';
}
return e;
@sketchpunk
sketchpunk / QuatTreeId.js
Created June 3, 2022 15:46
Quad Tree Node ID Generator
/* [ NOTES ] ============================================================
BigInt has 64 bits, since its signed there is only 63 bits to work with.
First 5 bits are reserved to store the Level value, which results the max value of 31
63bits - 5bits = 58 bits for quadrant information
Each quadrant needs 2bits to store its information
So 58 / 2 = 29, which is the max level to generate ids from
jntCount = ChainPose.count;
angles[] = new Array( jntCount ).fill( 0 )
loop
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Get world space transform (pos,rot,scl) of each bone in the chain
// Then preallocate space for the jacobian matrix
transforms[] = compute_WorldSpace_Transforms( ChainPose );
jacobian = Array( transforms.length * 3 * 3 ); // Each Joint gets 3 floats for 3 axes