Skip to content

Instantly share code, notes, and snippets.

@cubicleDowns
Created February 9, 2014 21:44
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 cubicleDowns/8906426 to your computer and use it in GitHub Desktop.
Save cubicleDowns/8906426 to your computer and use it in GitHub Desktop.
Example of using an AngularJS directive to interact with a THREEjs factory.
"use strict";
tttApp.directive("selectcube", function(ThreeEnv){
return {
restrict: "A",
link: function(scope, element){
var offsetLeft = element[0].offsetLeft,
offsetTop = element[0].offsetTop,
mouseDown = {x: null, y:null};
element.bind('mousedown', function(event){
// normalizing X/Y mousedown positions WRT the canvas position.
mouseDown.x = ((event.clientX - event.currentTarget.offsetLeft) / event.currentTarget.width) * 2 - 1;
mouseDown.y = -((event.clientY - event.currentTarget.offsetTop) / event.currentTarget.height) * 2 + 1;
ThreeEnv.makeSelection(mouseDown);
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment