Skip to content

Instantly share code, notes, and snippets.

zoomAll() {
// Placeholder for calculating the bounding box of all nodes
let bounds = {
top: Infinity,
left: Infinity,
bottom: -Infinity,
right: -Infinity
};
this.renderCanvas({
target: webglrendertarget
});
let frameBuffer = webglrendertarget.__webglFramebuffer;
gl.bindFramebuffer( gl.FRAMEBUFFER, frameBuffer );
gl.viewport( 0, 0, 400, 400 );
gl.readPixels( 0, 0, 400, 400, gl.RGBA, gl.UNSIGNED_BYTE, pixelBuffer );
gl.bindFramebuffer( gl.FRAMEBUFFER, null );
function copyUIntToImageData( uint, imageData ) {
for( let i = 0; i < uint.length; i += 4 ) {
let index = uint.length - i; // flip how data is read
imageData.data[ index ] = uint[ i ]; //red
imageData.data[ index + 1 ] = uint[ i + 1 ]; //green
imageData.data[ index + 2 ] = uint[ i + 2 ]; //blue
imageData.data[ index + 3 ] = uint[ i + 3 ]; //alpha
}
function without( obj, ...keys ) {
return Object.keys( obj ).reduce( ( memo, key ) => {
if( keys.indexOf( key ) === -1 ) {
memo[ key ] = obj[ key ];
}
return memo;
}, {} );
}
return <group
position={ position }
rotation={ new THREE.Euler().setFromQuaternion( rotation ) }
scale={ scale }
>
<mesh
position={ offset }
ref="mesh"
castShadow
function getFrustrumAt( camera, fov, aspect, distanceFromCamera ) {
var frustumHeight = 2.0 * distanceFromCamera * Math.tan(fov * 0.5 * ( Math.PI / 180 ) ),
var box = new THREE.Box2();
var size = new THREE.Vector2( frustumHeight * aspect, frustumHeight );
box.width = size.x;
box.height = size.y;
return box.setFromCenterAndSize( camera.position, new THREE.Vector2(
frustumHeight * aspect
[14:40:39] Requiring external module babel-core/register
./react-three-renderer/node_modules/babel-plugin-runtime/lib/index.js:23
return new Plugin("runtime", {
^
TypeError: Plugin is not a function
[16:16:15] Requiring external module babel-core/register
./react-three-renderer/node_modules/babel-plugin-runtime/lib/index.js:23
return new Plugin("runtime", {
^
TypeError: Plugin is not a function
@AndrewRayCode
AndrewRayCode / stores.js
Created January 12, 2016 23:36
How to store nested data in Flux
// Bad! Not normalized, nested
classrooms: [{
id: 1,
name: 'Math',
students: [{
id: 1,
name: 'Sally'
}]
}]
let forceZ = 0;
...
// Is space pressed?
if( KeyCodes.SPACE in keysDown ) {
// Are we touching a wall / floor we can jump off of?
if( Object.keys( jumpableWalls ).length ) {
forceZ -= 5;