Skip to content

Instantly share code, notes, and snippets.

@enjalot
Created February 4, 2013 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enjalot/4704693 to your computer and use it in GitHub Desktop.
Save enjalot/4704693 to your computer and use it in GitHub Desktop.
multi leap
{"description":"multi leap","endpoint":"","display":"webgl","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"leap.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"fullscreen":false,"thumbnail":"http://i.imgur.com/wPWKp70.png"}
var colorScale = d3.scale.category20();
var cube;
var cubes = [];
var ncubes = 40;
for(var i = ncubes; i--;) {
cube = makeCube(colorScale(i));
tributary.scene.add(cube);
cubes.push(cube);
}
tributary.events.off("leap");
tributary.events.on("leap", function(d) {
//console.log(d);
//console.log("d", d, d.arm);
/*
var hand, pointable;
for(var j = d.hands.length; j--;) {
hand = d.hands[j];
}
*/
//reset cube positions;
for(var j = ncubes; j--; ){
cubes[j].position.set(0,0,0);
}
for(var i = d.pointables.length; i--;) {
var pointer = d.pointables[i];
if(pointer.id < ncubes) {
var cube = cubes[pointer.id];
var pos = pointer.tipPosition;
//console.log(pos);
cube.position.set(pos[0], pos[1], pos[2]);
} else {
console.log("ID", pointer.id)
}
}
})
plane = new THREE.Mesh( new THREE.PlaneGeometry( 100, 100 ), new THREE.MeshBasicMaterial( { color: 0xa3a3a3 } ) );
plane.geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
tributary.scene.add( plane );
function toInt(color) { return parseInt(color.slice(1,7), 16) };
function makeCube(color) {
var materials = [];
for(var i = 6; i--; ) {
materials.push(new THREE.MeshBasicMaterial( { color: toInt(color)} ));
}
cube = new THREE.Mesh( new THREE.CubeGeometry( 19, 20, 20, 1, 1, 1, materials ), new THREE.MeshFaceMaterial() );
return cube
}
//tributary.useThreejsControls = false
if(!tributary.leap) tributary.leap = {};
// Support both the WebSocket and MozWebSocket objects
if ((typeof(WebSocket) == 'undefined') &&
(typeof(MozWebSocket) != 'undefined')) {
WebSocket = MozWebSocket;
}
// Create the socket with event handlers
tributary.leap.init = function() {
if(tributary.ws) {
tributary.ws.close();
}
console.log("Starting");
//Create and open the socket
tributary.ws = new WebSocket("ws://54.235.119.124:8000/");
var ws = tributary.ws;
// On successful connection
ws.onopen = function(event) {
console.log("Open");
ws.send("eye");
};
// On message received
ws.onmessage = function(event) {
tributary.events.trigger("leap", JSON.parse(event.data));
};
// On socket close
ws.onclose = function(event) {
ws = null;
}
//On socket error
ws.onerror = function(event) {
console.error("Received error");
};
}
tributary.leap.init();
tributary.events.on("restart", function() {
tributary.leap.init();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment