Skip to content

Instantly share code, notes, and snippets.

@ngokevin
Created September 4, 2017 09:45
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 ngokevin/07ed72398f2c3a559ba6eccad3024791 to your computer and use it in GitHub Desktop.
Save ngokevin/07ed72398f2c3a559ba6eccad3024791 to your computer and use it in GitHub Desktop.
Useful A-Frame utilities.
/**
* Helper to visualize lines.
*/
window.drawLine = (function () {
var els = {};
return function (name, vec1, vec2, color) {
if (!els[name]) {
els[name] = document.createElement('a-entity');
els[name].setAttribute('line', 'color', color || '#FFF');
els[name].setAttribute('id', name);
AFRAME.scenes[0].appendChild(els[name]);
}
els[name].setAttribute('line', 'start', vec1.clone());
els[name].setAttribute('line', 'end', vec2.clone());
};
})();
/**
* Helper to visualize vectors.
*/
window.drawVec3 = (function () {
var els = {};
return function (name, vec3, color) {
if (!els[name]) {
els[name] = document.createElement('a-sphere');
els[name].setAttribute('color', color || '#FFF');
els[name].setAttribute('radius', 0.02);
els[name].setAttribute('id', name);
els[name].setAttribute('text', {align: 'center', value: name, side: 'double'});
AFRAME.scenes[0].appendChild(els[name]);
}
els[name].setAttribute('position', vec3.clone());
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment