Skip to content

Instantly share code, notes, and snippets.

View patrickheng's full-sized avatar

Patrick HENG patrickheng

View GitHub Profile
@mattdesl
mattdesl / about.md
Last active December 24, 2017 14:47

shader-reload with budo

Say you want to use shader-reload on your current budo/ThreeJS application, but you don't want to use the glsl-server since you have some specific transforms or options you need.

You can write a new dev.js script (see below) and include any additional transforms you may want (babel, brfs, etc).

Now you can replace the budo command with node dev.js, and pass all other flags as usual.

Note: The utility handles live reloading for you (JS, HTML, CSS, GLSL), so you don't need to pass the --live or -l flags.

@aaronjanse
aaronjanse / anglediff.js
Created June 20, 2016 21:42
find the smallest distance between two angles
// from http://stackoverflow.com/a/7869457
// converted to js code
// x and y are the angles in radians
function getDifference(x, y) {
var a = x-y;
a = (function(i, j) {return i-Math.floor(i/j)*j})(a+Math.PI, Math.PI*2); // (a+180) % 360; this ensures the correct sign
a -= Math.PI;
return a;
}
@agconti
agconti / index.html
Created May 8, 2016 23:46
Fake Light
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Bonjourno World</title>
</head>
<body>
<script id="vertex-shader" type="text/vertex-shader">
/**
* Multiply each vertex by the model-view matrix
@kchapelier
kchapelier / merge-three-buffer-geometries.js
Last active September 11, 2018 22:04
Merge indexed and non-indexed THREE.BufferGeometry into a new indexed THREE.BufferGeometry. All missing uniforms are set to 0.
/**
* Combine indexed and non-indexed BufferGeometry into a new indexed BufferGeometry. All missing uniforms are set to 0.
* @param {array} geometries Array of THREE.BufferGeometry instances
* @returns {BufferGeometry}
*/
function mergeBufferGeometries (geometries) {
var indexLength = 0,
verticesLength = 0,
attributesInfos = {},
geometriesInfos = [],
@ayamflow
ayamflow / num-loop.js
Created September 11, 2017 18:04
Loop numbers between min/max using the modulo operator
function loop(val, min, max) {
return ((val - min) % (max - min + 1) + (max - min + 1)) % (max - min + 1) + min;
}
@patrickheng
patrickheng / Damping
Last active November 19, 2019 11:27
Formula
current -= ( target + current ) * friction
current += ( target - current ) * friction
@ayamflow
ayamflow / gist:a99fd49b773a53bc757df41f77fb369c
Created April 6, 2018 16:54
Visible width/height with threejs perspective camera
// https://discourse.threejs.org/t/functions-to-calculate-the-visible-width-height-at-a-given-z-depth-from-a-perspective-camera/269
function visibleHeightAtDepth(depth, camera) {
// compensate for cameras not positioned at z=0
const cameraOffset = camera.position.z;
if ( depth < cameraOffset ) depth -= cameraOffset;
else depth += cameraOffset;
// vertical fov in radians
const vFOV = camera.fov * Math.PI / 180;
// Math.abs to ensure the result is always positive
@clavis-magna
clavis-magna / objectRotation.js
Created November 24, 2012 04:36
local and global rotation functions for THREE.js objects updated for recent revisions of THREE.js
//following two rotation functions are updated versions of code from: https://github.com/mrdoob/three.js/issues/1219
//updated to work in latest versions (r52 tested) of THREE.js
// Rotate an object around an axis in object space
var rotationMatrix
function rotateAroundObjectAxis( object, axis, radians ) {
rotationMatrix = new THREE.Matrix4();
rotationMatrix.makeRotationAxis( axis.normalize(), radians );
object.matrix.multiplySelf( rotationMatrix ); // post-multiply
object.rotation.setEulerFromRotationMatrix(object.matrix, object.order);

Common Blender shortcuts

Camera

  • Shift + F - FPS mode

Outliner

  • Ctrl + Left Click - Select parent and its children
  • Shift + Left Click - Hide parent and its children
@souporserious
souporserious / getJSONFromFigmaFile.js
Created July 13, 2018 21:52
Generates JSON from Figma file
import request from 'request'
const api_endpoint = 'https://api.figma.com/v1'
const personal_access_token = 'FIGMA_ACCESS_TOKEN_HERE' // https://www.figma.com/developers/docs#auth-dev-token
function downloadSvgFromAWS(url) {
return new Promise((resolve, reject) => {
request.get(
url,
{