-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaframe-layout-component.min.js
1 lines (1 loc) · 2.35 KB
/
aframe-layout-component.min.js
1
!function(t){function e(r){if(i[r])return i[r].exports;var n=i[r]={exports:{},id:r,loaded:!1};return t[r].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e){function i(t,e,i){for(var r=[],n=Math.ceil(e/t.columns),o=0;n>o;o++)for(var a=0;a<t.columns;a++)r.push([a*t.margin,o*t.margin,0]);return r}function r(t,e,i){for(var r=[],n=0;e>n;n++){var o=n*(2*Math.PI)/e;r.push([i.x+t.radius*Math.cos(o),i.y,i.z+t.radius*Math.sin(o)])}return r}function n(t,e,r){return t.columns=e,i(t,e,r)}function o(t,e,i){return c([[1,0,0],[0,1,0],[0,0,1],[-1,0,0],[0,-1,0],[0,0,-1]],i,t.radius/2)}function a(t,e,i){var r=(1+Math.sqrt(5))/2,n=1/r,o=2-r,a=-1*n,s=-1*o;return c([[-1,o,0],[-1,s,0],[0,-1,o],[0,-1,s],[0,1,o],[0,1,s],[1,o,0],[1,s,0],[n,n,n],[n,n,a],[n,a,n],[n,a,a],[o,0,1],[o,0,-1],[a,n,n],[a,n,a],[a,a,n],[a,a,a],[s,0,1],[s,0,-1]],i,t.radius/2)}function s(t,e,i){var r=Math.sqrt(3),n=-1/Math.sqrt(3),o=2*Math.sqrt(2/3);return c([[0,0,r+n],[-1,0,n],[1,0,n],[0,o,0]],i,t.radius/2)}function c(t,e,i){return e=[e.x,e.y,e.z],t.map(function(t){return t.map(function(t,r){return t*i+e[r]})})}function u(t,e){t.forEach(function(t,i){var r=e[i];t.setAttribute("position",{x:r[0],y:r[1],z:r[2]})})}AFRAME.registerComponent("layout",{schema:{columns:{"default":1,min:0,"if":{type:["box"]}},margin:{"default":1,min:0,"if":{type:["box","line"]}},radius:{"default":1,min:0,"if":{type:["circle","cube","dodecahedron","pyramid"]}},type:{"default":"line",oneOf:["box","circle","cube","dodecahedron","line","pyramid"]}},init:function(){var t=this.el;this.children=t.getChildEntities();var e=e=[];this.children.forEach(function(t){e.push(t.getComputedAttribute("position"))}),this.childAttachedCallback=this.update.bind(this),t.addEventListener("child-attached",this.childAttachedCallback)},update:function(t){var e,c,d=this.children,h=this.data,l=this.el,f=d.length,p=l.getComputedAttribute("position");switch(h.type){case"box":e=i;break;case"circle":e=r;break;case"cube":e=o;break;case"dodecahedron":e=a;break;case"pyramid":e=s;break;default:e=n}c=e(h,f,p),u(d,c)},remove:function(){el.removeEventListener("child-attached",this.childAttachedCallback),u(children,this.initialPositions)}}),t.exports.getBoxPositions=i,t.exports.getCirclePositions=r,t.exports.getLinePositions=n,t.exports.getCubePositions=o,t.exports.getDodecahedronPositions=a,t.exports.getPyramidPositions=s}]);