- Shift + F - FPS mode
- Ctrl + Left Click - Select parent and its children
- Shift + Left Click - Hide parent and its children
// 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; | |
} |
vec2 rotate(vec2 v, float a) { | |
float s = sin(a); | |
float c = cos(a); | |
mat2 m = mat2(c, s, -s, c); | |
return m * v; | |
} |
current -= ( target + current ) * friction | |
current += ( target - current ) * friction |
import THREE from 'three'; | |
import CANNON from 'cannon'; | |
export const generateThreeVertices = (rawVerts) => { | |
let verts = []; | |
for(let v = 0; v < rawVerts.length; v+=3){ | |
verts.push(new THREE.Vector3(rawVerts[v], | |
rawVerts[v+1], | |
rawVerts[v+2])); |
// An implementation of CSS `background-size: cover` | |
// using http://stackoverflow.com/a/6565988 and my own crappy math | |
vec2 s = uScreenSize; // Screen | |
vec2 i = uBGSize; // Image | |
float rs = s.x / s.y; | |
float ri = i.x / i.y; | |
vec2 new = rs < ri ? vec2(i.x * s.y / i.y, s.y) : vec2(s.x, i.y * s.x / i.x); | |
vec2 offset = (rs < ri ? vec2((new.x - s.x) / 2.0, 0.0) : vec2(0.0, (new.y - s.y) / 2.0)) / new; | |
vec2 uv = vTexCoord * s / new + offset; | |
gl_FragColor = texture2D(uBGTex, uv); |
var cameraZ = camera.position.z; | |
var planeZ = 5; | |
var distance = cameraZ - planeZ; | |
var aspect = viewWidth / viewHeight; | |
var vFov = camera.fov * Math.PI / 180; | |
var planeHeightAtDistance = 2 * Math.tan(vFov / 2) * distance; | |
var planeWidthAtDistance = planeHeightAtDistance * aspect; | |
// or |
/** | |
* 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 = [], |
function loop(val, min, max) { | |
return ((val - min) % (max - min + 1) + (max - min + 1)) % (max - min + 1) + min; | |
} |
const cloneGltf = (gltf) => { | |
const clone = { | |
animations: gltf.animations, | |
scene: gltf.scene.clone(true) | |
}; | |
const skinnedMeshes = {}; | |
gltf.scene.traverse(node => { | |
if (node.isSkinnedMesh) { |