Skip to content

Instantly share code, notes, and snippets.

View mikolalysenko's full-sized avatar

Mikola Lysenko mikolalysenko

View GitHub Profile
@mikolalysenko
mikolalysenko / gist:4652191
Created January 28, 2013 01:51
Stream example
var spawn = require("child_process").spawn;
var temp = require("temp");
var fs = require("fs");
var path = require("path");
var Stream = require("stream");
//Eagerly create temporary directory
var directory_built = false
, directory_err = null
, directory_wait = []
@mikolalysenko
mikolalysenko / gist:5085308
Created March 4, 2013 20:24
Skeletal animation in JavaScript

Here is a sketch of how one might go about doing skeletal animation in JavaScript, broken down into different npm modules that would need to be written:

  • A BVH to JSON converter.
    BVH is a standard format for representing skeletal animation, there is tons of data in the format, and many tools can consume/produce it. So getting things working in this space is priority #1. I think the best way to tackle this problem would be to write a simple module that takes a stream, and produce a JSON object that exactly represents the HIERARCHY and MOTION sections of a BVH file, along with some serialize method that can produce the same output.
  • A simple animation viewer. Outside voxel.js, we should probably have a stick figure animation viewer. this could be done in THREE.js using wires to draw each of the joints.
  • A motion tweening module Or basically some method to interpolate between per-frame motions. This is necessary to perform
@mikolalysenko
mikolalysenko / gist:5110487
Created March 7, 2013 18:30
Sketch of greedy meshing in 3D
var map = getChunkBitmap()
, boxes = []
for(var z=0; z<CHUNK_Z; ++z) {
for(var y=0; y<CHUNK_Y; ++y) {
for(var x=0; x<CHUNK_X; ++x) {
if(map[x,y,z]) {
var w = 0, h = 0, d = 0
@mikolalysenko
mikolalysenko / gist:5277933
Last active December 15, 2015 14:58
Pointless rant

A list of completely unnecessary software projects (in no particular order)

Considering starting a new node.js module? Great! But here is a suggestion: try to do something useful with your time. If you are trying to work on one of the following projects, I beg you to reconsider and avoid wasting your time on projects that no one will use. Instead, to avoid duplicating effort you should try to make use of a module that already solves whatever problem you are trying to do before going out and making yet another one (only to add to future programmers' confusion and irritation). Here is a short (but by no means exhaustive) list of already solved problems which have hundreds of existing solutions. If you are going to work on one of these problems, I cannot stop you. But please pause to consider this: What will you do that will differentiate your library from the scads of others that have come before you?

Template engines

  • underscore
  • moustache
  • handlebars
  • plate
@mikolalysenko
mikolalysenko / gist:5311694
Created April 4, 2013 16:03
This is not as fast as 1.0 / Math.sqrt(number)
var FLOAT_VIEW = new Float32Array(1)
, INT_VIEW = new Uint32Array(FLOAT_VIEW.buffer)
function rsqrt(number) {
var threhalfs = 1.5
var x2 = 0.5 * number
FLOAT_VIEW[0] = number
INT_VIEW[0] = 0x5f3759df - ( INT_VIEW[0] >>> 1 )
FLOAT_VIEW[0] = FLOAT_VIEW[0] * ( 1.5 - ( x2 * FLOAT_VIEW[0] * FLOAT_VIEW[0] ) )
FLOAT_VIEW[0] = FLOAT_VIEW[0] * ( 1.5 - ( x2 * FLOAT_VIEW[0] * FLOAT_VIEW[0] ) )
@mikolalysenko
mikolalysenko / gist:5580867
Last active December 17, 2015 08:29
Spring!
//Config variables
var rest_length = 256.0
var spring_constant = 1.0
var dt = 0.01
//Hooke's law
function force(displacement) {
return spring_constant * (rest_length - displacement)
}
@mikolalysenko
mikolalysenko / gist:5602268
Created May 17, 2013 21:57
Installing tap
$ time npm install tap
npm http GET https://registry.npmjs.org/tap
npm http 304 https://registry.npmjs.org/tap
npm http GET https://registry.npmjs.org/difflet
npm http GET https://registry.npmjs.org/deep-equal
npm http GET https://registry.npmjs.org/buffer-equal
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/slide
npm http GET https://registry.npmjs.org/runforcover
npm http GET https://registry.npmjs.org/nopt
@mikolalysenko
mikolalysenko / gist:5674433
Created May 29, 2013 22:46
New texture.js api

texture.js

Browserify-compatible, streamable webgl 2D texture module.

var texture = require('texture.js')
  , canvas = document.createElement('canvas')
  , gl = canvas.getContext('experimental-webgl')
  , Texture = texture(gl)
@mikolalysenko
mikolalysenko / gist:5708673
Created June 4, 2013 19:18
Example showing how to unpack minecraft chunks into 32x32x32 cubes
var ndarray = require("ndarray")
var ops = require("ndarray-ops")
//Given a voxel.js chunk, its y coordinate in blocks and the 4 minecraft chunks it intersects unpack them into the voxel.js component
function unpackMinecraft(y_coord, voxeljs_chunk, mc_chunk00, mc_chunk01, mc_chunk10, mc_chunk_11) {
var varray = ndarray(voxeljs_chunk, [32,32,32])
var mc00 = ndarray(mc_chunk00, [16,128,16], [128, 1, 16*128])
var mc01 = ndarray(mc_chunk01, [16,128,16], [128, 1, 16*128])
var mc10 = ndarray(mc_chunk10, [16,128,16], [128, 1, 16*128])
<!DOCTYPE html>
<html>
<head>
<title>HTML5/JS Poject1</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<script src="http://code.jquery.com/jquery-2.0.2.min.js"></script> <!-- needed to run jQuery stuff -->
<script src="script.js" type="text/javascript"></script>
</head>
<body>
<div id='unit'></div>