Skip to content

Instantly share code, notes, and snippets.

@kaosat-dev
Created November 3, 2014 13:57
Show Gist options
  • Save kaosat-dev/f671027852da41a4f992 to your computer and use it in GitHub Desktop.
Save kaosat-dev/f671027852da41a4f992 to your computer and use it in GitHub Desktop.
Object rotation plugin for usco viewer
<polymer-element name="object-rotate-plugin" >
<script>
Polymer("object-rotate-plugin",{
methodsToInject: ["rotateSelection"],
attached:function(){
this.injectInParent();
},
injectInParent: function() {
var parentNode = undefined;
//this tricks allows plugins to be added both at the <template> level
//of an element, and at its instanciation
if(this.parentNode) parentNode = this.parentNode;
if(this.parentNode.host) parentNode = this.parentNode.host;
if (parentNode.injectPlugin && !this.objectParent) {
this.objectParent = parentNode;
parentNode.injectPlugin(this);
}
},
//this method will get added to the viewer
rotateSelection:function(axis, angle){
if(!this.selectedObject) return;
var axis = axis === undefined ? 'x': axis;
var angle = angle === undefined ? 0: angle;
if((["x","y","z"]).indexOf(axis) === -1){
throw new Error("'"+axis + "' is not a valid rotation axis");
}
//convert to radians
angle = angle * Math.PI /180;
this.selectedObject.rotation[axis] += angle;
}
});
</script>
</polymer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment