[ Launch: multi leap ] 4733659 by enjalot
[ Launch: multi leap ] 4720756 by enjalot
[ Launch: multi leap ] 4704693 by enjalot
[ Launch: LeapMotion Three.js Visualizer ] 4703710 by enjalot
[ Launch: Tributary inlet ] 4646124 by enjalot
-
-
Save enjalot/4733659 to your computer and use it in GitHub Desktop.
localhost leap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"description":"localhost 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/YePnMiH.png"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var colorScale = d3.scale.category20(); | |
var svg = d3.select("#display") | |
.selectAll("svg") | |
.data(["shadowsvg"]) | |
svg.enter().append("svg"); | |
var cubes = {}; | |
tributary.events.off("leap"); | |
tributary.events.on("leap", function(d) { | |
//console.log(d.arm); | |
//console.log("d", d, d.arm); | |
if(!d.arm) d.arm = 1; | |
/* | |
var hand, pointable; | |
for(var j = d.hands.length; j--;) { | |
hand = d.hands[j]; | |
} | |
*/ | |
var arm = svg.selectAll("g.arm") | |
.data([d.arm], function(d) { return d }) | |
arm.enter() | |
.append("g").classed("arm",true); | |
var color = colorScale(d.arm); | |
var fingers = arm.selectAll("g.finger") | |
.data(d.pointables, function(p) { | |
return p.id | |
}); | |
fingers.enter() | |
.append("g") | |
.classed("finger", true) | |
.each(function(p) { | |
var cube = makeCube(color); | |
cubes[d.arm + "_" + p.id] = cube; | |
tributary.scene.add(cube); | |
//console.log("making", d.arm, p.id, cube); | |
}) | |
fingers.exit() | |
.each(function(p) { | |
var cube = cubes[d.arm + "_" + p.id]; | |
tributary.scene.remove(cube); | |
//console.log("removing", d.arm, p.id, cube); | |
}).remove(); | |
fingers.each(function(p) { | |
var pos = p.tipPosition; | |
var cube = cubes[d.arm + "_" + p.id]; | |
if(cube) { | |
cube.position.set(pos[0], pos[1], pos[2]); | |
} | |
}) | |
}) | |
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://localhost:6437/"); | |
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