
/*
 * 3dtin.js
 * Copyright (C) 2010-2011  Jayesh Salvi <jayesh@3dtin.com>
 * All Rights Reserved
 */
var framework=typeof jQuery=="undefined"?exports:jQuery;
(function(y){if(typeof window==="undefined")_=require("../../../libs/underscore")._;var f={};f.C={specversion:"0.8",xformversion:1,temp_group_uid:1E3,proj_perspective:1,proj_orthographic:2,mode_cubicle:0,mode_freeform:1,mode_smooth:2,n0b2:1,n14e:2,n117:3,model_form_solid:1,model_form_wireframe:2,n1db:1,n1d1:2,n165:3,n145:4,n16b:5,n136:9,n0f0:12,n177:13,n148:14,n296:1,n23c:2,n248:3,n275:4,n16a:5,n27c:6,n1e8:7,n1eb:8,n1dc:10,n166:11,n16e:12,n0da:13,n1c4:14,n1cd:15,n1ee:16,n156:17,n0cb:23,n0a6:24,n0bb:25,
n082:26,n264:27,n1b9:28,n0a1:29,n0ef:30,op_objscale:31,op_objshear:32,cam_view_top:1,cam_view_bottom:2,cam_view_left:3,cam_view_right:4,cam_view_front:5,cam_view_back:6,cam_view_delta_left:7,cam_view_delta_right:8,cam_view_delta_top:9,cam_view_delta_bottom:10,template_voxel:-1,n122:1,n0d9:2,n099:3,n07a:4,n116:5,n0b5:6,n08e:7,n095:8,n138:9,n0d8:10,n0a2:11,template_custom:1E3,xform_translate:1,xform_rotate:2,n1ac:3,n1c0:4,xform_shear:5,center_align:1,min_align:2,max_align:3,lighttype_directional:1,
lighttype_point:2,lighttype_ambient:3,n0ce:1,n104:2,snapRange:0.5,error_corrupt_file:1,error_remove_nonexistent_cube:2,n234:30,n0d7:1E3/30,n129:10,n0bf:1E4/30,n0eb:20,n09a:2E4/30,ccworker_path:"/_src/tin/ccworker.js",max_smoothness:2,cube_size:0.4,n1d6:50,n102:5,n128_stl:15E3,n128_obj:2E4,exception_not_implemented:"Not implemented",exception_corrupt_file:"Corrupt document",n073:"No intersection found",n068:"No reference for adjascent",n086:"Ray in plane",n069:"gl.createBuffer failed",n064:"Overlaps with a geometry",
exception_ascii2binstl_failed:"Ascii2Binary STL conversion failed",exception_zipobj_failed:"Zip for OBJ failed",exception_geomprepare_failed:"Geometry preparation failed",exception_geomclone_failed:"Geometry clone failed",exception_geomcursorclone_failed:"Geometry cursor clone failed",exception_webgl_req_advgeom:"Webgl required, Advanced Geometry",exception_unexpected_empty_cubegroup:"Unexpected empty cubegroup",n075:1,n063:2};f.stats={bufsize:0};f.n107=function(k,n){return{r:k.r,g:k.g,b:k.b,a:n||
50}};f.precise=function(k,n){n=n||1E4;return Math.floor(k*n)/n};f.n29e=function(k){var n=k[0].toFixed(4),c=k[1].toFixed(4);k=k[2].toFixed(4);if(n==="-0.0000")n="0.0000";if(c==="-0.0000")c="0.0000";if(k==="-0.0000")k="0.0000";return n+"_"+c+"_"+k};f.templateLegacyMap={};f.templateLegacyMap[f.C.n122]="s";f.templateLegacyMap[f.C.n0d9]="w";f.templateLegacyMap[f.C.n099]="e";f.templateLegacyMap[f.C.n07a]="r";f.templateLegacyMap[f.C.n116]="t";f.templateLegacyMap[f.C.n0b5]="y";f.templateLegacyMap[f.C.n08e]=
"u";f.templateLegacyMap[f.C.n095]="i";f.templateLegacyMap[f.C.n138]="o";f.templateLegacyMap[f.C.n0d8]="p";f.templateLegacyMap[f.C.n0a2]="a";if(typeof window!=="undefined"){y.tin=f;if(!window.requestAnimationFrame)window.requestAnimationFrame=function(){return window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(k){window.setTimeout(k,1E3/60)}}()}else exports.tin=f;_.mixin({update:function(k,n,c){_(k).each(function(b){b[n]=
c})},isUsableNumber:function(k){return _.isNumber(k)&&!_.isNaN(k)}})})(framework);
(function(y){var f=y.tin,k=f.C.cube_size;f.n078=function(n,c,b,d,e,g){return f.n0e6(n,c,b,d,e,g)};f.n0e6=function(n,c,b,d,e,g){n=[g.xmax*(2*n/b-1),g.ymax*(2*c/d-1),-1*g.near];if(g.projection==f.C.proj_orthographic)return[n[0],n[1],e[2]];else{g=f.v3.direction(n,[0,0,0]);n=e[2]/g[2];return[n*g[0],n*g[1],e[2]]}};f.n0c1=function(n,c,b,d,e){var g=[e.xmax*(2*n/b-1),e.ymax*(2*c/d-1),-1*e.near];if(e.projection==f.C.proj_orthographic)e=[e.xmax*(2*n/b-1),e.ymax*(2*c/d-1),-1*e.far];else{n=f.v3.direction(g,[0,
0,0]);c=(-e.far- -e.near)/n[2];e=[c*n[0],c*n[1],-e.far]}return[g,e]};f.n0b8=function(n,c,b,d,e){var g=f.v3.sub(d,b),h=f.v3.sub(e,d);g=f.v3.cross(g,h);h=f.v3.dot(g,c);if(h==0)return null;var j=f.v3.dot(g,b)-f.v3.dot(g,n);j/=h;if(j<=0)return null;if(j>1)return null;n=f.v3.add(n,f.v3.mul(c,j));if(Math.abs(g[0])>Math.abs(g[1]))if(Math.abs(g[0])>Math.abs(g[2])){c=n[1]-b[1];g=d[1]-b[1];j=e[1]-b[1];h=n[2]-b[2];d=d[2]-b[2];e=e[2]-b[2]}else{c=n[0]-b[0];g=d[0]-b[0];j=e[0]-b[0];h=n[1]-b[1];d=d[1]-b[1];e=e[1]-
b[1]}else if(Math.abs(g[1])>Math.abs(g[2])){c=n[0]-b[0];g=d[0]-b[0];j=e[0]-b[0];h=n[2]-b[2];d=d[2]-b[2];e=e[2]-b[2]}else{c=n[0]-b[0];g=d[0]-b[0];j=e[0]-b[0];h=n[1]-b[1];d=d[1]-b[1];e=e[1]-b[1]}b=g*e-d*j;if(b==0)return null;b=1/b;e=(c*e-h*j)*b;if(e<0)return null;b=(g*h-d*c)*b;if(b<0)return null;if(e+b>1)return null;return n};y=function(n){this.normal=f.v3.cross(f.v3.sub(n[1],n[0]),f.v3.sub(n[2],n[1]));f.v3.normalize(this.normal);this.apoint=n[0];this.d=-1*f.v3.dot(n[0],this.normal)};y.prototype={n25c:function(n){return f.v3.dot(this.normal,
n)+this.d},contains:function(n){return this.n25c(n)<0.2},project:function(n){vdotn=f.v3.dot(n,this.normal);return f.v3.sub(n,f.v3.mul(this.normal,vdotn))},reflect:function(n){return f.v3.add(n,f.v3.mul(this.normal,-2*this.n25c(n)))},n1fd:function(n){var c=f.v3.dot(this.normal,n.d),b;if(Math.abs(c)<0.2)if(Math.abs(n.o[0]*this.normal[0]+n.o[1]*this.normal[1]+n.o[2]*this.normal[2]+this.d)<0.2)throw new Error(f.C.n086);else return null;b=-(this.normal[0]*n.o[0]+this.normal[1]*n.o[1]+this.normal[2]*n.o[2]+
this.d);b/=c;return f.v3.add(n.o,f.v3.mul(n.d,b))}};f.n2a9=y;f.Ray=function(n,c){this.o=n;this.d=f.v3.sub(c,n)};f.n084=function(n){var c=n.data.view;var b=(n28b=c.model.n087(c.n268(n),k*1.414/2,c))?n28b.pos:null;if(b)b=[Math.round(b[0]/k),Math.round(b[1]/k),Math.round(b[2]/k)];else{c.n159();pos=c.n19f(n);b=[Math.round(pos[0]/k),Math.round(pos[1]/k),Math.round(pos[2]/k)]}return b};f.merge2dExtents=function(n){var c={xmin:Infinity,xmax:-Infinity,ymin:Infinity,ymax:-Infinity};_(n).each(function(b){c.xmin=
Math.min(c.xmin,b.xmin);c.xmax=Math.max(c.xmax,b.xmax);c.ymin=Math.min(c.ymin,b.ymin);c.ymax=Math.max(c.ymax,b.ymax)},this);return c};f.n0b7=function(n,c,b,d,e){function g(j,p,o,s){o=o-j;s=s-p;for(var E=Math.round(Math.sqrt(o*o+s*s)/5),w=0;w<E;w+=2){h.moveTo(j+w/E*o,p+w/E*s);h.lineTo(j+(w+1)/E*o,p+(w+1)/E*s)}}var h=n.get(0).getContext("2d");h.clearRect(0,0,n.width(),n.height());h.save();h.strokeStyle="#000";h.beginPath();g(c,b,d,b);g(d,b,d,e);g(d,e,c,e);g(c,e,c,b);h.closePath();h.stroke();h.restore()};
f.ease=function(n){return-1*n*(n-2)}})(jQuery);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){y=typeof window==="undefined"?require("./declare").tin:y.tin;var f={};f.x=[1,0,0];f.y=[0,1,0];f.z=[0,0,1];f.mul=function(c,b){return[c[0]*b,c[1]*b,c[2]*b]};f.add=function(c,b){return[c[0]+b[0],c[1]+b[1],c[2]+b[2]]};f.sub=function(c,b){return[c[0]-b[0],c[1]-b[1],c[2]-b[2]]};f.cross=function(c,b){return[c[1]*b[2]-c[2]*b[1],c[2]*b[0]-c[0]*b[2],c[0]*b[1]-c[1]*b[0]]};f.dot=function(c,b){return c[0]*b[0]+c[1]*b[1]+c[2]*b[2]};f.n13d=function(c){return c[0]*c[0]+c[1]*c[1]+c[2]*c[2]};f.length=
function(c){return Math.sqrt(f.n13d(c))};f.normalize=function(c){var b=1/f.length(c);return[c[0]*b,c[1]*b,c[2]*b]};f.direction=function(c,b){return f.normalize(f.sub(c,b))};f.toString=function(c){a=_(c).map(function(b){return b.toFixed(2)});return"["+a+"]"};f.isZero=function(c){return c[0]==0&&c[1]==0&&c[2]==0};var k={};k.I=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];k.clone=function(c){return c.slice(0,c.length)};k.mul=function(c,b){var d=new Array(16);d[0]=b[0]*c[0]+b[1]*c[4]+b[2]*c[8]+b[3]*c[12];d[1]=b[0]*
c[1]+b[1]*c[5]+b[2]*c[9]+b[3]*c[13];d[2]=b[0]*c[2]+b[1]*c[6]+b[2]*c[10]+b[3]*c[14];d[3]=b[0]*c[3]+b[1]*c[7]+b[2]*c[11]+b[3]*c[15];d[4]=b[4]*c[0]+b[5]*c[4]+b[6]*c[8]+b[7]*c[12];d[5]=b[4]*c[1]+b[5]*c[5]+b[6]*c[9]+b[7]*c[13];d[6]=b[4]*c[2]+b[5]*c[6]+b[6]*c[10]+b[7]*c[14];d[7]=b[4]*c[3]+b[5]*c[7]+b[6]*c[11]+b[7]*c[15];d[8]=b[8]*c[0]+b[9]*c[4]+b[10]*c[8]+b[11]*c[12];d[9]=b[8]*c[1]+b[9]*c[5]+b[10]*c[9]+b[11]*c[13];d[10]=b[8]*c[2]+b[9]*c[6]+b[10]*c[10]+b[11]*c[14];d[11]=b[8]*c[3]+b[9]*c[7]+b[10]*c[11]+b[11]*
c[15];d[12]=b[12]*c[0]+b[13]*c[4]+b[14]*c[8]+b[15]*c[12];d[13]=b[12]*c[1]+b[13]*c[5]+b[14]*c[9]+b[15]*c[13];d[14]=b[12]*c[2]+b[13]*c[6]+b[14]*c[10]+b[15]*c[14];d[15]=b[12]*c[3]+b[13]*c[7]+b[14]*c[11]+b[15]*c[15];return d};k.n26b=function(c){var b=new Array(16),d=c[5]*c[10]*c[15]+c[6]*c[11]*c[13]+c[7]*c[9]*c[14]-c[13]*c[10]*c[7]-c[14]*c[11]*c[5]-c[15]*c[9]*c[6],e=(c[4]*c[10]*c[15]+c[6]*c[11]*c[12]+c[7]*c[8]*c[14]-c[12]*c[10]*c[7]-c[14]*c[11]*c[4]-c[15]*c[8]*c[6])*-1,g=c[4]*c[9]*c[15]+c[5]*c[11]*c[12]+
c[7]*c[8]*c[13]-c[12]*c[9]*c[7]-c[13]*c[11]*c[4]-c[15]*c[8]*c[5],h=(c[4]*c[9]*c[14]+c[5]*c[10]*c[12]+c[6]*c[8]*c[13]-c[12]*c[9]*c[6]-c[13]*c[10]*c[4]-c[14]*c[8]*c[5])*-1,j=c[0]*d+c[1]*e+c[2]*g+c[3]*h;if(j===0)throw"matrix not invertible";var p=(c[1]*c[10]*c[15]+c[2]*c[11]*c[13]+c[3]*c[9]*c[14]+-c[13]*c[10]*c[3]-c[14]*c[11]*c[1]-c[15]*c[9]*c[2])*-1,o=c[0]*c[10]*c[15]+c[2]*c[11]*c[12]+c[3]*c[8]*c[14]+-c[12]*c[10]*c[3]-c[14]*c[11]*c[0]-c[15]*c[8]*c[2],s=(c[0]*c[9]*c[15]+c[1]*c[11]*c[12]+c[3]*c[8]*c[13]+
-c[12]*c[9]*c[3]-c[13]*c[11]*c[0]-c[15]*c[8]*c[1])*-1,E=c[0]*c[9]*c[14]+c[1]*c[10]*c[12]+c[2]*c[8]*c[13]+-c[12]*c[9]*c[2]-c[13]*c[10]*c[0]-c[14]*c[8]*c[1],w=c[1]*c[6]*c[15]+c[2]*c[7]*c[13]+c[3]*c[5]*c[14]+-c[13]*c[6]*c[3]-c[14]*c[7]*c[1]-c[15]*c[5]*c[2],D=(c[0]*c[6]*c[15]+c[2]*c[7]*c[12]+c[3]*c[4]*c[14]+-c[12]*c[6]*c[3]-c[14]*c[7]*c[0]-c[15]*c[4]*c[2])*-1,B=c[0]*c[5]*c[15]+c[1]*c[7]*c[12]+c[3]*c[4]*c[13]+-c[12]*c[5]*c[3]-c[13]*c[7]*c[0]-c[15]*c[4]*c[1],m=(c[0]*c[5]*c[14]+c[1]*c[6]*c[12]+c[2]*c[4]*
c[13]+-c[12]*c[5]*c[2]-c[13]*c[6]*c[0]-c[14]*c[4]*c[1])*-1,A=(c[1]*c[6]*c[11]+c[2]*c[7]*c[9]+c[3]*c[5]*c[10]+-c[9]*c[6]*c[3]-c[10]*c[7]*c[1]-c[11]*c[5]*c[2])*-1,r=c[0]*c[6]*c[11]+c[2]*c[7]*c[8]+c[3]*c[4]*c[10]+-c[8]*c[6]*c[3]-c[10]*c[7]*c[0]-c[11]*c[4]*c[2],v=(c[0]*c[5]*c[11]+c[1]*c[7]*c[8]+c[3]*c[4]*c[9]+-c[8]*c[5]*c[3]-c[9]*c[7]*c[0]-c[11]*c[4]*c[1])*-1;c=c[0]*c[5]*c[10]+c[1]*c[6]*c[8]+c[2]*c[4]*c[9]+-c[8]*c[5]*c[2]-c[9]*c[6]*c[0]-c[10]*c[4]*c[1];b[0]=d/j;b[1]=p/j;b[2]=w/j;b[3]=A/j;b[4]=e/j;b[5]=
o/j;b[6]=D/j;b[7]=r/j;b[8]=g/j;b[9]=s/j;b[10]=B/j;b[11]=v/j;b[12]=h/j;b[13]=E/j;b[14]=m/j;b[15]=c/j;return b};k.n22b=function(c){var b=new Array(16);b[0]=c[0];b[1]=c[4];b[2]=c[8];b[3]=c[12];b[4]=c[1];b[5]=c[5];b[6]=c[9];b[7]=c[13];b[8]=c[2];b[9]=c[6];b[10]=c[10];b[11]=c[14];b[12]=c[3];b[13]=c[7];b[14]=c[11];b[15]=c[15];return b};k.n2b4=function(c,b){return[c[0]*b[0]+c[4]*b[1]+c[8]*b[2]+c[12],c[1]*b[0]+c[5]*b[1]+c[9]*b[2]+c[13],c[2]*b[0]+c[6]*b[1]+c[10]*b[2]+c[14],c[3]*b[0]+c[7]*b[1]+c[11]*b[2]+c[15]]};
k.rotate=function(c,b,d){c=n.$(b,c);c=n.n2ba(c);return k.mul(d,c)};k.translate=function(c,b,d,e){var g=new Array(16);g[0]=1;g[1]=0;g[2]=0;g[3]=0;g[4]=0;g[5]=1;g[6]=0;g[7]=0;g[8]=0;g[9]=0;g[10]=1;g[11]=0;g[12]=c;g[13]=b;g[14]=d;g[15]=1;return k.mul(e,g)};k.scale=function(c,b,d,e){var g=new Array(16);g[0]=c;g[1]=0;g[2]=0;g[3]=0;g[4]=0;g[5]=b;g[6]=0;g[7]=0;g[8]=0;g[9]=0;g[10]=d;g[11]=0;g[12]=0;g[13]=0;g[14]=0;g[15]=1;return k.mul(e,g)};k.shear=function(c,b,d,e,g,h,j){var p=new Array(16);p[0]=1;p[1]=
d;p[2]=g;p[3]=0;p[4]=c;p[5]=1;p[6]=h;p[7]=0;p[8]=b;p[9]=e;p[10]=1;p[11]=0;p[12]=0;p[13]=0;p[14]=0;p[15]=1;return k.mul(j,p)};k.n272=function(c,b,d,e,g,h){var j=new Array(16);j[0]=2*g/(b-c);j[1]=0;j[2]=0;j[3]=0;j[4]=0;j[5]=2*g/(e-d);j[6]=0;j[7]=0;j[8]=(b+c)/(b-c);j[9]=(e+d)/(e-d);j[10]=-(h+g)/(h-g);j[11]=-1;j[12]=0;j[13]=0;j[14]=-2*h*g/(h-g);j[15]=0;return j};k.perspective=function(c,b,d,e){c=d*Math.tan(c*Math.PI/360);var g=-c;return k.n272(g*b,c*b,g,c,d,e)};k.orthographic=function(c,b,d,e,g,h){var j=
new Array(16);j[0]=2/(b-c);j[1]=0;j[2]=0;j[3]=0;j[4]=0;j[5]=2/(e-d);j[6]=0;j[7]=0;j[8]=0;j[9]=0;j[10]=-2/(h-g);j[11]=0;j[12]=-(b+c)/(b-c);j[13]=-(e+d)/(e-d);j[14]=-(h+g)/(h-g);j[15]=1;return j};k.n28e=function(c,b,d){b=f.direction(c,b);d=f.normalize(f.cross(d,b));var e=f.normalize(f.cross(b,d));return k.mul([d[0],e[0],b[0],0,d[1],e[1],b[1],0,d[2],e[2],b[2],0,0,0,0,1],[1,0,0,0,0,1,0,0,0,0,1,0,-c[0],-c[1],-c[2],1])};k.toString=function(c){return"{"+c[0].toFixed(3)+","+c[4].toFixed(3)+","+c[8].toFixed(3)+
","+c[12].toFixed(3)+"}, \n{"+c[1].toFixed(3)+","+c[5].toFixed(3)+","+c[9].toFixed(3)+","+c[13].toFixed(3)+"}, \n{"+c[2].toFixed(3)+","+c[6].toFixed(3)+","+c[10].toFixed(3)+","+c[14].toFixed(3)+"}, \n{"+c[3].toFixed(3)+","+c[7].toFixed(3)+","+c[11].toFixed(3)+","+c[15].toFixed(3)+"} \n"};var n={};n.$=function(c,b){var d=Math.cos(b/2),e=Math.sin(b/2);b=c[0]*e;var g=c[1]*e;c=c[2]*e;e=new Array(4);e[0]=b;e[1]=g;e[2]=c;e[3]=d;return e};n.n2ba=function(c){var b=new Array(16),d=c[0],e=c[1],g=c[2];c=c[3];
b[0]=1-2*(e*e+g*g);b[1]=2*(d*e+g*c);b[2]=2*(d*g-e*c);b[3]=0;b[4]=2*(d*e-g*c);b[5]=1-2*(d*d+g*g);b[6]=2*(g*e+d*c);b[7]=0;b[8]=2*(d*g+e*c);b[9]=2*(e*g-d*c);b[10]=1-2*(d*d+e*e);b[11]=0;b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b};y.v3=f;y.m4=k})(framework);
(function(y){function f(c){this.view=c;this.rgba=c.n10e();this.cubes=[];this.isSolid=true;this.isGeometry=false}var k=y.tin,n=k.C.cube_size;f.prototype={n22f:function(c){this.rgba=c},n297:function(c){var b=_(this.cubes).select(function(d){return d.position[0]===c[0]&&d.position[1]===c[1]&&d.position[2]===c[2]},this);return b.length===1?b[0]:null},n10b:function(c,b){var d=c.position;c.n1b7=[];_([[d[0],d[1],d[2]-1],[d[0],d[1],d[2]+1],[d[0],d[1]+1,d[2]],[d[0],d[1]-1,d[2]],[d[0]+1,d[1],d[2]],[d[0]-1,
d[1],d[2]]]).each(function(e,g){if(e=this.n297(e)){c.n1b7.push(g);b&&this.n10b(e,false)}},this)},n0fc:function(c){_(c).each(function(b){b=new k.n24c({position:b,rgba:this.rgba});this.cubes.push(b);this.n10b(b,true)},this);if(this.view.n2bc){this.mesh&&this.mesh.destroy();this.mesh=new k.Mesh3D(this.view);this.n187(this.mesh);this.isSolid?this.mesh.generate_colored_n267():this.mesh.n081()}},n187:function(c){color=c.n1d3(this.rgba);_(this.cubes).each(function(b){var d=b.n28a(),e=_(k.n24c.vertices).map(function(g){return k.v3.add(d,
k.v3.mul(g,n/2))},this);_(e).each(function(g){c.n19a(g)},this);_(k.n24c.faces).each(function(g,h){if(!(b.n1b7.indexOf(h)>=0)){g=_(g).map(function(j){return k.v3.add(d,k.v3.mul(k.n24c.vertices[j],n/2))},this);c.n20b(g,color,true)}},this)},this)},n0ac:function(c){function b(){return{xmin:Infinity,xmax:-Infinity,ymin:Infinity,ymax:-Infinity,zmin:Infinity,zmax:-Infinity}}function d(o,s){o.xmin=Math.min(o.xmin,s.xmin);o.xmax=Math.max(o.xmax,s.xmax);o.ymin=Math.min(o.ymin,s.ymin);o.ymax=Math.max(o.ymax,
s.ymax);o.zmin=Math.min(o.zmin,s.zmin);o.zmax=Math.max(o.zmax,s.zmax)}if(this.currentGeomType==k.C.n14e)if(this.origmesh){this.mesh=this.origmesh.copy();this.mesh.n0fd();this.mesh.n22f(this.rgba)}else this.origmesh=this.mesh.copy();else if(this.currentGeomType==k.C.n117)if(this.origmeshes){this.meshes=_(this.origmeshes).map(function(o){return o.copy()});_(this.meshes).each(function(o){o.n0fd()},this);_(this.meshes).invoke("setAlpha",50)}else this.origmeshes=_(this.meshes).map(function(o){return o.copy()});
switch(c.type){case "scale":if(this.mesh){var e=this.mesh.n186();this.mesh.translate(k.v3.mul(e,-1));var g=k.m4.scale(c.scaleX,c.scaleY,c.scaleZ,k.m4.I);this.mesh.transform(g,true);this.mesh.translate(e,true);this.view._jq.trigger("current_geom_extents",this.mesh.extents)}else if(this.meshes){var h=b();_(this.meshes).each(function(o){d(h,o.extents)});g=h;e=[(g.xmin+g.xmax)/2,(g.ymin+g.ymax)/2,(g.zmin+g.zmax)/2];h=b();_(this.meshes).each(function(o){o.translate(k.v3.mul(e,-1));var s=k.m4.scale(c.scaleX,
c.scaleY,c.scaleZ,k.m4.I);o.transform(s,true);o.translate(e,true);d(h,o.extents)});this.view._jq.trigger("current_geom_extents",h)}break;case "shear":if(this.mesh){e=this.mesh.n186();this.mesh.translate(k.v3.mul(e,-1));g=k.m4.shear(c.shearXY,c.shearXZ,c.shearYX,c.shearYZ,c.shearZX,c.shearZY,k.m4.I);this.mesh.transform(g,true);this.mesh.translate(e,true);this.view._jq.trigger("current_geom_extents",this.mesh.extents)}else if(this.meshes){h=b();_(this.meshes).each(function(o){d(h,o.extents)});g=h;e=
[(g.xmin+g.xmax)/2,(g.ymin+g.ymax)/2,(g.zmin+g.zmax)/2];h=b();_(this.meshes).each(function(o){o.translate(k.v3.mul(e,-1));var s=k.m4.shear(c.shearXY,c.shearXZ,c.shearYX,c.shearYZ,c.shearZX,c.shearZY,k.m4.I);o.transform(s,true);o.translate(e,true);d(h,o.extents)});this.view._jq.trigger("current_geom_extents",h)}break;case "rotate":var j=[0,0,0];j[c.axis]=1;var p=c.clockwise?-c.angle:c.angle;p*=Math.PI/180;if(this.mesh){e=this.mesh.n186();this.mesh.translate(k.v3.mul(e,-1));g=k.m4.rotate(p,j,k.m4.I);
this.mesh.transform(g,true);this.mesh.translate(e,true);this.view._jq.trigger("current_geom_extents",this.mesh.extents)}else if(this.meshes){h={xmin:Infinity,xmax:-Infinity,ymin:Infinity,ymax:-Infinity,zmin:Infinity,zmax:-Infinity};_(this.meshes).each(function(o){h.xmin=Math.min(h.xmin,o.extents.xmin);h.xmax=Math.max(h.xmax,o.extents.xmax);h.ymin=Math.min(h.ymin,o.extents.ymin);h.ymax=Math.max(h.ymax,o.extents.ymax);h.zmin=Math.min(h.zmin,o.extents.zmin);h.zmax=Math.max(h.zmax,o.extents.zmax)});g=
h;e=[(g.xmin+g.xmax)/2,(g.ymin+g.ymax)/2,(g.zmin+g.zmax)/2];_(this.meshes).each(function(o){o.translate(k.v3.mul(e,-1));var s=k.m4.rotate(p,j,k.m4.I);o.transform(s,true);o.translate(e,true)});this.view._jq.trigger("current_geom_extents",h)}break}},n18d:function(c,b){function d(){if(b)if(e.mesh){e.mesh.n22f(e.rgba);var g=k.v3.sub(k.v3.mul(b,n),e.accoffset);e.accoffset=k.v3.mul(b,n);e.mesh.translate(g,true)}else if(e.meshes){g=k.v3.sub(k.v3.mul(b,n),e.accoffset);e.accoffset=k.v3.mul(b,n);_(e.meshes).each(function(h){h.translate(g,
true)})}}var e=this;if(this.currentGeomId!=c.uid){this.currentGeomId=c.uid;this.currentGeomType=c.geomType;if(c.geomType==k.C.n14e)c.clone(function(g){e.mesh=g.mesh;e.meshes=null;e.accoffset=[0,0,0];d()});else if(c.geomType==k.C.n117){c.clone(function(g){e.mesh=null;e.meshes=[];(function h(j){j.geomType==k.C.n14e?e.meshes.push(j.mesh):_(j.children).each(h)})(g);_(e.meshes).invoke("setAlpha",50)});e.accoffset=[0,0,0];d()}}else d();this.view.draw()},clear:function(){this.cubes=[];this.isGeometry=false;
this.origmeshes=this.origmesh=null},clearGeometry:function(){this.currentGeomId=null},draw:function(){if(this.view.n2bc)if(this.isSolid){k.n2be.n15b(false);k.n2be.n23b(true);if(this.mesh)this.mesh.surfaces?_(this.mesh.surfaces).each(function(c){k.n2bf.draw(c.n228,this.view)},this):_(this.mesh.n1ab).each(function(c){k.n2bf.drawColored(c.n228,this.view)},this);else if(this.meshes){k.n2be.n15b(true);_(this.meshes).each(function(c){c.surfaces?_(c.surfaces).each(function(b){k.n2bf.draw(b.n228,this.view)},
this):_(c.n1ab).each(function(b){k.n2bf.drawColored(b.n228,this.view)},this)},this)}}else if(this.mesh)if(this.mesh.surfaces){k.n2be.n174(7);_(this.mesh.surfaces).each(function(c){k.n2bf.drawLines(c.n228,this.rgba,this.view)},this);k.n2be.n174(1)}else{if(this.mesh.n228){k.n2be.n174(2);k.n2bf.drawLines(this.mesh.n228,this.rgba,this.view);k.n2be.n174(1)}}else this.meshes&&_(this.meshes).each(function(c){k.n2be.n174(2);k.n2bf.drawLines(c.n228,this.rgba,this.view);k.n2be.n174(1)},this)}};k.n1a6=f})(jQuery);
framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){function f(b,d,e,g){this.n269=b;this.color=d;this.n191=e;this.n185=g;this.update_vertices();this.n0e2();if(this.n191.view){this._project();this.n066();this.n06e()}}var k;if(typeof window!=="undefined")k=y.tin;else{_=require("../../../libs/underscore")._;k=require("./declare").tin}if(typeof Float32Array=="undefined")y=y=Array;else{y=Float32Array;y=Uint16Array}var n=k.C.cube_size,c=Base.extend({constructor:function(b){this.view=b;this.position=[0,0,0];this.clear()},clear:function(){this.n29d=
{};this.n23f={};this.icol=this.n2b8=0;this.colors=[];this.vertices=[];this.faces=[];this.n15c()},n15c:function(){this.extents={xmin:Infinity,xmax:-Infinity,ymin:Infinity,ymax:-Infinity,zmin:Infinity,zmax:-Infinity}},n137:function(b){this.extents.xmin=Math.min(this.extents.xmin,b[0]);this.extents.xmax=Math.max(this.extents.xmax,b[0]);this.extents.ymin=Math.min(this.extents.ymin,b[1]);this.extents.ymax=Math.max(this.extents.ymax,b[1]);this.extents.zmin=Math.min(this.extents.zmin,b[2]);this.extents.zmax=
Math.max(this.extents.zmax,b[2])},n186:function(){var b=this.extents;return[(b.xmin+b.xmax)/2,(b.ymin+b.ymax)/2,(b.zmin+b.zmax)/2]},n288:function(b){return b.r+"_"+b.g+"_"+b.b+"_"+b.a},n19a:function(b){var d=k.n29e(b);if(this.n29d[d]===undefined){this.n29d[d]=this.n2b8++;this.vertices.push(b);this.n137(b)}},n20b:function(b,d,e){this.faces.push(new f(_(b).map(function(g){return this.n29d[k.n29e(g)]},this),d,this,e))},n1d3:function(b){var d=this.n288(b);if(this.n23f[d]===undefined){this.n23f[d]=this.icol++;
this.colors.push(b)}return this.n23f[d]},n22f:function(b){this.colors[0]=b},n1d7:function(){var b=this.origcolors?this.origcolors:this.colors;if(!this.origcolors)this.origcolors=_(this.colors).map(function(d){return{r:d.r,g:d.g,b:d.b,a:d.a}},this);this.colors=_(b).map(function(d){return{r:Math.round(d.r/2),g:Math.round(d.g/2),b:Math.round(d.b/2),a:100}},this)},n162:function(){if(this.origcolors){this.colors=_(this.origcolors).map(function(b){return{r:b.r,g:b.g,b:b.b,a:b.a}},this);this.origcolors=
null}},translate:function(b){this.n15c();this.vertices=_(this.vertices).map(function(d){d=k.v3.add(d,b);this.n137(d);return d},this);_(this.faces).invoke("update_vertices");_(this.faces).invoke("n0e2")},transform:function(b){this.n15c();this.vertices=_(this.vertices).map(function(d){d=k.m4.n2b4(b,d);this.n137(d);return d},this);_(this.faces).invoke("update_vertices");_(this.faces).invoke("n0e2")},flip:function(b){var d=this.extents,e=[(d.xmin+d.xmax)/2,(d.ymin+d.ymax)/2,(d.zmin+d.zmax)/2];this.n15c();
this.vertices=_(this.vertices).map(function(g){var h=g.slice(0,3);h[b]=e[b]-(g[b]-e[b]);this.n137(h);return h},this);_(this.faces).invoke("reverse_order");_(this.faces).invoke("update_vertices");_(this.faces).invoke("n0e2")},n11f:function(){return c.n11f(this.extents)},dump:function(){return JSON.stringify({vertices:this.vertices,faces:_(this.faces).map(function(b){return b.n269})})},copy:function(){var b=new c;b.view=this.view;b.n29d=_.clone(this.n29d);b.n23f=_.clone(this.n23f);b.extents=_.clone(this.extents);
b.n2b8=this.n2b8;b.icol=this.icol;b.colors=this.colors.slice(0,this.colors.length);b.vertices=this.vertices.slice(0,this.vertices.length);b.faces=_(this.faces).map(function(d){d=d.copy();d.n191=b;return d},this);return b}});f.prototype={copy:function(){return new f(this.n269.slice(0,this.n269.length),this.color,this.n191,this.n185)},update_vertices:function(){this.vertices=_(this.n269).map(function(b){return this.n191.vertices[b]},this)},reverse_order:function(){this.n269.reverse()},_project:function(){this.pvertices=
_(this.vertices).map(function(b){return this.n191.view.project(b)},this)},n0e2:function(){var b=k.v3.sub(this.vertices[1],this.vertices[0]),d=k.v3.sub(this.vertices[2],this.vertices[0]);this.normal=k.v3.normalize(k.v3.cross(b,d))},n06e:function(){var b=k.v3.sub(this.pvertices[1],this.pvertices[0]),d=k.v3.sub(this.pvertices[2],this.pvertices[0]);this.pnormal=k.v3.normalize(k.v3.cross(b,d))},n066:function(){this.pcentroid=[0,0,0];_(this.pvertices).each(function(b){this.pcentroid[0]+=b[0];this.pcentroid[1]+=
b[1];this.pcentroid[2]+=b[2]},this);return[this.pcentroid[0]/4,this.pcentroid[1]/4,this.pcentroid[2]/4]},n112:function(b){b=k.m4.n2b4(b.n27e,this.normal);b=Math.max(k.v3.dot(b,k.n2c0.n233),0);b=k.v3.add(k.n2c0.n240,k.v3.mul(k.n2c0.n254,b));var d=this.n191.colors[this.color];d=[d.r/255,d.g/255,d.b/255,d.a/100];b=[d[0]*b[0],d[1]*b[1],d[2]*b[2],d[3]];return"rgba("+parseInt(255*b[0],10)+","+parseInt(255*b[1],10)+","+parseInt(255*b[2],10)+","+parseInt(100*b[3],10)+")"},n203:function(){var b=this.n191.colors[this.color];
return[b.r/255,b.g/255,b.b/255,b.a/100]},n202:function(){var b;this._project();this.n066();this.n06e();if(this.n191.view.projection===k.C.proj_perspective){b=k.v3.direction([0,0,0],this.pcentroid);b=k.v3.dot(this.pnormal,b)}else b=k.v3.dot(this.pnormal,[0,0,1]);return b<=0}};c.n11f=function(b){function d(h){return Math.round(h/n)-k.precise(h/n,100)}var e=k.C.snapRange;b={xmin:d(b.xmin),ymin:d(b.ymin),zmin:d(b.zmin),xmax:d(b.xmax),ymax:d(b.ymax),zmax:d(b.zmax)};var g=[];g[0]=Math.abs(b.xmin)<Math.abs(b.xmax)?
Math.abs(b.xmin)<e?b.xmin:0:Math.abs(b.xmax)<e?b.xmax:0;g[1]=Math.abs(b.ymin)<Math.abs(b.ymax)?Math.abs(b.ymin)<e?b.ymin:0:Math.abs(b.ymax)<e?b.ymax:0;g[2]=Math.abs(b.zmin)<Math.abs(b.zmax)?Math.abs(b.zmin)<e?b.zmin:0:Math.abs(b.zmax)<e?b.zmax:0;return g};k.Mesh=c;k.n252=f})(framework);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){var f;if(typeof window!=="undefined")f=y.tin;else{_=require("../../../libs/underscore")._;f=require("./declare").tin}if(typeof Float32Array=="undefined")var k=Array,n=Array;else{k=Float32Array;n=Uint16Array}var c=f.C.cube_size;y=f.Mesh.extend({constructor:function(b){this.view=b;this.position=[0,0,0];this.clear();this.n2bc=true},clear:function(){this.surfaces=null;this.n15c();this.base()},n196:function(b){if(!b)throw new Error("surfaces not inited");this.surfaces=b;this.n15c();_(b).each(function(d){_(d.vertices).each(function(e){e[0]=
f.v3.mul(e[0],c);this.n137(e[0])},this)},this);this.n0fd()},merge:function(b){if(!this.surfaces)this.surfaces=[];this.surfaces=this.surfaces.concat(b.surfaces)},setAlpha:function(b){_(this.surfaces).each(function(d){var e=_.extend(_.clone(d.rgba),{a:b});d.rgba=e;if(d.n228)d.n228.rgba=e},this)},n22f:function(b){_(this.surfaces).each(function(d){d.rgba=b;if(d.n228)d.n228.rgba=b},this)},translate:function(b,d){this.n15c();if(this.surfaces){_(this.surfaces).each(function(e){_(e.vertices).each(function(g){g[0]=
f.v3.add(g[0],b);this.n137(g[0])},this)},this);d&&this.ren0fd("vtx")}else if(this.n1ab){_(this.vertices).each(function(e,g){this.vertices[g]=f.v3.add(e,b);this.n137(this.vertices[g])},this);d&&this.regenerate_colored_n267("vtx")}},transform:function(b,d,e){this.n15c();if(this.surfaces){_(this.surfaces).each(function(g){_(g.vertices).each(function(h){h[0]=f.m4.n2b4(b,h[0]);var j=e?b:f.m4.n22b(f.m4.n26b(b));h[2]=f.m4.n2b4(j,h[2]);h[2]=e?h[2]:f.v3.normalize(h[2]);this.n137(h[0])},this)},this);if(d){this.ren0fd("vtx");
this.ren0fd("nrm")}}else if(this.n1ab){_(this.vertices).each(function(g,h){this.vertices[h]=f.m4.n2b4(b,g);this.n137(this.vertices[h])},this);_(this.faces).each(function(g){var h=e?b:f.m4.n22b(f.m4.n26b(b));g.normal=f.m4.n2b4(h,g.normal);g.normal=e?g.normal:f.v3.normalize(g.normal)},this);d&&this.regenerate_colored_n267("vtx");d&&this.regenerate_colored_n267("nrm")}},flip:function(b,d,e){var g=this.extents;d=d||[(g.xmin+g.xmax)/2,(g.ymin+g.ymax)/2,(g.zmin+g.zmax)/2];this.n15c();if(this.surfaces){_(this.surfaces).each(function(h){_(h.vertices).each(function(j){var p=
j[0].slice(0,3);p[b]=d[b]-(j[0][b]-d[b]);j[0]=p;j[2][b]=-1*j[2][b];this.n137(j[0])},this);_(h.faces).invoke("reverse")},this);if(e){this.ren0fd("vtx");this.ren0fd("nrm");this.ren0fd("idx")}}else if(this.n1ab){_(this.vertices).each(function(h,j){var p=h.slice(0,3);p[b]=d[b]-(h[b]-d[b]);this.vertices[j]=p;this.n137(this.vertices[j])},this);_(this.faces).each(function(h){h.normal[b]=-1*h.normal[b];h.reverse_order()},this);if(e){this.regenerate_colored_n267("vtx");this.regenerate_colored_n267("nrm");
this.regenerate_colored_n267("idx")}}},generate_colored_n267:function(){this.n1ab={};_(this.faces).each(function(d){var e=this.n288(this.colors[d.color]);this.n1ab[e]||(this.n1ab[e]={vcount:0,icount:0,rgba:this.colors[d.color]});this.n1ab[e].vcount+=3*d.n269.length;this.n1ab[e].icount+=3*(d.n269.length-2)},this);for(key in this.n1ab){var b=this.n1ab[key];b.n1bb={vtx:new k(b.vcount),nrm:new k(b.vcount),idx:new n(b.icount),rgba:b.rgba};b.vcount=b.icount=0}_(this.faces).each(function(d){var e=[],g=d.normal,
h=this.n1ab[this.n288(this.colors[d.color])],j=h.n1bb;_(d.n269).each(function(p){e.push(h.vcount/3);var o=this.vertices[p];_(3).times(function(s){j.vtx[h.vcount+s]=o[s]});_(3).times(function(s){j.nrm[h.vcount+s]=g[s]});h.vcount+=3},this);_(d.n269.length-2).times(function(p){j.idx[h.icount]=e[0];j.idx[h.icount+1]=e[p+1];j.idx[h.icount+2]=e[p+2];h.icount+=3},this)},this);for(key in this.n1ab){b=this.n1ab[key];b.n228=f.n2bf.upload(b.n1bb);b.n228||this.view.log("n2bf upload failed")}},regenerate_colored_n267:function(b){if(b==
"idx"){for(key in this.n1ab){var d=this.n1ab[key];d.vcount=d.icount=0}_(this.faces).each(function(e){var g=[],h=this.n1ab[this.n288(this.colors[e.color])],j=h.n1bb;_(e.n269).each(function(){g.push(h.vcount/3);h.vcount+=3},this);_(e.n269.length-2).times(function(p){j.idx[h.icount]=g[0];j.idx[h.icount+1]=g[p+1];j.idx[h.icount+2]=g[p+2];h.icount+=3},this)},this);for(key in this.n1ab){d=this.n1ab[key];f.n2bf.updateIndex(d.n228.idx,d.n1bb.idx)}}else{for(key in this.n1ab){d=this.n1ab[key];d.vcount=0}_(this.faces).each(function(e){var g=
[],h=e.normal,j=this.n1ab[this.n288(this.colors[e.color])],p=j.n1bb;_(e.n269).each(function(o){g.push(j.vcount/3);var s=this.vertices[o];b=="vtx"&&_(3).times(function(E){p.vtx[j.vcount+E]=s[E]});b=="nrm"&&_(3).times(function(E){p.nrm[j.vcount+E]=h[E]});j.vcount+=3},this)},this);for(key in this.n1ab){d=this.n1ab[key];if(b=="vtx")f.n2bf.update(d.n228.vtx,d.n1bb.vtx);else b=="nrm"&&f.n2bf.update(d.n228.nrm,d.n1bb.nrm)}}},n0fd:function(){this.numpoly=0;_(this.surfaces).each(function(b){this.numpoly+=
b.faces.length;var d={vtx:new k(b.vertices.length*3),tex:new k(b.vertices.length*2),nrm:new k(b.vertices.length*3),idx:new n(b.faces.length*3),rgba:b.rgba};f.stats.bufsize+=4*b.vertices.length*8+2*b.faces.length*3;_(b.vertices).each(function(e,g){_(3).times(function(h){d.vtx[3*g+h]=e[0][h]});_(2).times(function(h){d.tex[2*g+h]=e[1][h]});_(3).times(function(h){d.nrm[3*g+h]=e[2][h]})},this);_(b.faces).each(function(e,g){_(e).each(function(h,j){d.idx[3*g+j]=h})},this);b.n1bb=d;b.n228=f.n2bf.upload(d)},
this)},ren0fd:function(b){_(this.surfaces).each(function(d){var e=d.n1bb;if(b=="idx"){_(d.faces).each(function(g,h){_(g).each(function(j,p){e.idx[3*h+p]=j})},this);f.n2bf.updateIndex(d.n228.idx,e.idx)}else if(b=="vtx"){_(d.vertices).each(function(g,h){_(3).times(function(j){e.vtx[3*h+j]=g[0][j]})},this);f.n2bf.update(d.n228.vtx,e.vtx)}else if(b=="nrm"){_(d.vertices).each(function(g,h){_(3).times(function(j){e.nrm[3*h+j]=g[2][j]})},this);f.n2bf.update(d.n228.nrm,e.nrm)}},this)},n081:function(){if(this.surfaces)_(this.surfaces).each(function(h){var j=
0,p=0,o=0;_(h.faces).each(function(E){j+=3*E.length;p+=4*E.length;o+=2*E.length},this);var s={vtx:new k(j),col:new k(p),nrm:new k(j),idx:new n(o)};o=p=j=0;_(h.faces).each(function(E){var w=[];_(E).each(function(D){w.push(j/3);var B=h.vertices[D];_(3).times(function(m){s.vtx[j+m]=B[0][m]});s.nrm[j]=0;s.nrm[j+1]=0;s.nrm[j+2]=1;s.col[p]=0;s.col[p+1]=0;s.col[p+2]=0;s.col[p+3]=1;j+=3;p+=4},this);_(E.length).times(function(D){s.idx[o]=w[D];s.idx[o+1]=w[(D+1)%w.length];o+=2},this)},this);h.n228=f.n2bf.upload(s)},
this);else{var b=0,d=0,e=0;_(this.faces).each(function(h){b+=3*h.n269.length;d+=4*h.n269.length;e+=2*h.n269.length},this);var g={vtx:new k(b),col:new k(d),nrm:new k(b),idx:new n(e)};e=d=b=0;_(this.faces).each(function(h){var j=[];_(h.n269).each(function(p){j.push(b/3);var o=this.vertices[p];_(3).times(function(s){g.vtx[b+s]=o[s]});g.nrm[b]=0;g.nrm[b+1]=0;g.nrm[b+2]=1;g.col[d]=0;g.col[d+1]=0;g.col[d+2]=0;g.col[d+3]=1;b+=3;d+=4},this);_(h.n269.length).times(function(p){g.idx[e]=j[p];g.idx[e+1]=j[(p+
1)%j.length];e+=2},this)},this);this.n228=f.n2bf.upload(g)}},destroy:function(){_(this.surfaces).each(function(b){b.n228&&f.n2bf.destroy(b.n228)},this)},copy:function(){var b=new f.Mesh3D;b.view=this.view;b.extents=_.clone(this.extents);if(this.surfaces)b.surfaces=_(this.surfaces).map(function(d){return{faces:_(d.faces).map(function(e){return _.clone(e)}),vertices:_(d.vertices).map(function(e){return[_.clone(e[0]),_.clone(e[1]),_.clone(e[2])]}),rgba:d.rgba}},this);else{b.vertices=_.clone(this.vertices);
b.faces=_(this.faces).map(function(d){d=d.copy();d.n191=b;return d},this)}return b}});f.Mesh3D=y})(framework);
(function(y){function f(){}var k=y.tin;f.upload=function(n){var c=k.n2be,b={};if(n.vtx)b.vtx=c.makeBuffer(c.gl.ARRAY_BUFFER,c.gl.DYNAMIC_DRAW,n.vtx,3,n.vtx.length/3);if(n.tex)b.tex=c.makeBuffer(c.gl.ARRAY_BUFFER,c.gl.STATIC_DRAW,n.tex,2,n.tex.length/2);if(n.nrm)b.nrm=c.makeBuffer(c.gl.ARRAY_BUFFER,c.gl.DYNAMIC_DRAW,n.nrm,3,n.nrm.length/3);if(n.idx)b.idx=c.makeBuffer(c.gl.ELEMENT_ARRAY_BUFFER,c.gl.DYNAMIC_DRAW,n.idx,1,n.idx.length);if(n.col)b.col=c.makeBuffer(c.gl.ARRAY_BUFFER,c.gl.STATIC_DRAW,n.col,
4,n.col.length/4);if(n.rgba)b.rgba=n.rgba;return b};f.update=function(n,c){k.n2be.updateBuffer(n,c)};f.updateIndex=function(n,c){k.n2be.updateIndexBuffer(n,c)};f.draw=function(n,c){k.n2be.drawTextured(n,k.n2be.gl.TRIANGLES,c)};f.drawColored=function(n,c){k.n2be.drawColored(n,k.n2be.gl.TRIANGLES,c)};f.drawLines=function(n,c,b){k.n2be.drawLine(n,c,b)};f.destroy=function(n){n.vtx&&k.n2be.deleteBuffer(n.vtx);n.tex&&k.n2be.deleteBuffer(n.tex);n.nrm&&k.n2be.deleteBuffer(n.nrm);n.idx&&k.n2be.deleteBuffer(n.idx);
n.col&&k.n2be.deleteBuffer(n.col)};k.n2bf=f})(jQuery);
(function(y){function f(){}function k(t){A=(new Date).getTime();if(t.projection==o.C.proj_orthographic)v=t.ymax;else H=t.zoom;r&&clearTimeout(r);n(t)}function n(t){var u=(new Date).getTime();if(u-A>o.C.n0d7){var C=t.n0af()?o.ease((u-A)/o.C.n0bf):(u-A)/o.C.n0bf;if(t.projection==o.C.proj_orthographic){C=v-C;if(C<=1)C=1;var q=C*t.aspect;t.update({ymax:C,xmax:q})}else{var F=H-8*C;if(F<2)F=2;C=t.near*Math.tan(t.zoom*Math.PI/360);q=t.ymax*t.aspect;t.update({zoom:F,ymax:C,xmax:q})}}if(u-A<o.C.n0bf)r=setTimeout(function(){n(t)},
o.C.n0d7)}function c(t){A=(new Date).getTime();if(t.projection==o.C.proj_orthographic)v=t.ymax;else H=t.zoom;r&&clearTimeout(r);b(t)}function b(t){var u=(new Date).getTime();if(u-A>o.C.n0d7){var C=o.ease((u-A)/o.C.n0bf);if(t.projection==o.C.proj_orthographic){C=v+C;if(C>=40)C=40;var q=C*t.aspect;t.update({ymax:C,xmax:q})}else{var F=H+8*C;if(F>179)F=179;C=t.near*Math.tan(t.zoom*Math.PI/360);q=t.ymax*t.aspect;t.update({zoom:F,ymax:C,xmax:q})}}if(u-A<o.C.n0bf)r=setTimeout(function(){b(t)},o.C.n0d7)}
function d(t){var u=t.data.view,C=y.browser.webkit||y.browser.msie?true:false;if(t.originalEvent.detail!=undefined&&t.originalEvent.detail!=0)if(t.originalEvent.detail>0)C?k(u):c(u);else{if(t.originalEvent.detail<0)C?c(u):k(u)}else if(t.originalEvent.wheelDelta>0)C?k(u):c(u);else if(t.originalEvent.wheelDelta<0)C?c(u):k(u)}function e(t,u,C){var q=C.getX(u);u=C.height-C.getY(u);C=o.n0e6(q,u,C.width,C.height,C.project(t.n186()),C);m={type:o.C.n275,offset:[0,0,0],n190:C};if(t.geomType==o.C.n117&&t.isTemporary())m.geometry_uid_list=
_(t.children).pluck("uid");else m.geometry_uid=t.uid;t.focus({r:0,g:0,b:255});B=true}function g(t,u,C){var q=C.getX(t);t=C.height-C.getY(t);q=o.n0e6(q,t,C.width,C.height,C.project(u.n186()),C);q=o.v3.sub(C.n21b(q),C.n21b(m.n190));q[C.n1b5]=0;if(u.geomType!=o.C.n0b2){q=[q[0]/s,q[1]/s,q[2]/s];u.n1f8(q);C.snapToGrid&&u.addOffset(u.n11f())}else{q=[Math.round(q[0]/s),Math.round(q[1]/s),Math.round(q[2]/s)];u.n1f8(q)}u.n0db();u.focus({r:0,g:0,b:255});C.draw()}function h(t,u,C){B=false;var q=C.getX(t);t=
C.height-C.getY(t);q=o.n0e6(q,t,C.width,C.height,C.project(u.n186()),C);if(u.geomType!=o.C.n0b2)q=o.v3.mul(u.getOffset(),1/s);else{q=o.v3.sub(C.n21b(q),C.n21b(m.n190));q[C.n1b5]=0;q=[Math.round(q[0]/s),Math.round(q[1]/s),Math.round(q[2]/s)]}C=q[0]||q[1]||q[2];u.n1f8([0,0,0]);if(C){q={type:o.C.xform_translate,v:o.C.xformversion,delta:q};u.translate(q);m.xform=q}u.n0db();return C}function j(t,u,C){m={type:o.C.n27c};u={type:o.C.n1c0,v:o.C.xformversion,flipAxis:u};t.flip(u);m.xform=u;if(t.geomType==o.C.n117&&
t.isTemporary())m.geometry_uid_list=_(t.children).pluck("uid");else m.geometry_uid=t.uid;y(C.canvas).trigger("model_changed",C.model)}function p(t,u){var C=t.n092();_(C.n231).each(t.n1c1,t);_(C.n255).each(t.n26d,t);m={type:o.C.n16e,mod_type:"adderase",add_mods:[{cubeg_uid:t.uid,cubes:_(C.n255).map(function(q){return{position:q.position,rgba:{r:q.rgba.r,g:q.rgba.g,b:q.rgba.b,a:q.rgba.a}}})}],erase_mods:[{cubeg_uid:t.uid,cubes:_(C.n231).map(function(q){return{position:q.position,rgba:{r:q.rgba.r,g:q.rgba.g,
b:q.rgba.b,a:q.rgba.a}}})}]};y(u.canvas).trigger("model_changed",u.model)}var o=y.tin,s=o.C.cube_size,E=false,w=false,D=false,B=false,m=null,A,r,v,H;f.n1b3=k;f.n171=c;f.onMouseDown=function(t){try{var u=t.data.view;n293=u.getX(t);n298=u.getY(t);if(t.ctrlKey){o.n192.onDown(t);t.stopPropagation();t.preventDefault()}else{switch(u.action){case o.C.n177:o.n192.onDown(t);break;case o.C.n148:o.n178.onDown(t);break;case o.C.n1d1:o.n222.onDown(t);E=true;break;case o.C.n136:o.n14b.onDown(t);break;case o.C.n165:o.n1a4.onDown(t);
w=true;break;case o.C.n16b:o.n1af.onDown(t);D=true;break;case o.C.n0f0:o.ColorPickAction.onDown(t);break}t.stopPropagation();t.preventDefault();return false}}catch(C){console.log(C.message);if(C.message!==o.C.n073)if(C.message!==o.C.n086)C.message===o.C.n069?t.data.view.user_alert(o.C.n069):t.data.view.error(C,"onMouseDown")}};f.onMouseUp=function(t){try{var u=t.data.view;if(t.ctrlKey)o.n192.onUp(t);else{switch(u.action){case o.C.n177:o.n192.onUp(t);break;case o.C.n148:o.n178.onUp(t);break;case o.C.n1d1:E&&
o.n222.onUp(t);break;case o.C.n165:w&&o.n1a4.onUp(t);break;case o.C.n16b:D&&o.n1af.onUp(t)}D=w=E=false;if(u.action==o.C.n1d1||u.action==o.C.n165)u.n141=true;t.stopPropagation();t.preventDefault();return false}}catch(C){t.data.view.error(C,"onMouseUp")}};f.onMouseMove=function(t){try{var u=t.data.view;if(t.ctrlKey)o.n192.onMove(t);else{switch(u.action){case o.C.n177:o.n192.onMove(t);break;case o.C.n148:o.n178.onMove(t);break;case o.C.n1d1:E?o.n222.onMove(t):o.n0f3.onMove(t);break;case o.C.n136:o.n09f.onMove(t);
break;case o.C.n165:w?o.n1a4.onMove(t):o.n0cf.onMove(t);break;case o.C.n16b:D?o.n1af.onMove(t):o.Previewn1af.onMove(t);break;case o.C.n0f0:o.Previewn1af.onMove(t);break}t.stopPropagation();t.preventDefault();return false}}catch(C){if(C.message!==o.C.n073)if(C.message!==o.C.n086)if(C.message!==o.C.n068)C.message===o.C.n069?t.data.view.user_alert(o.C.n069):t.data.view.error(C,"onMouseMove")}};f.onMouseWheel=function(t){d(t);t.stopPropagation();t.preventDefault();return false};f.bind=function(t){var u=
t.data("instance");t.bind("oo.rotate.continue",function(C,q){try{var F=u.alignedDir<0?q.clockwise:!q.clockwise;u.n19b.isSolid=true;u.n19b.n0ac({type:"rotate",axis:u.n1b5,clockwise:F,angle:q.angle});u.draw()}catch(G){u.error(G,"handler[oo.rotate.continue]")}});t.bind("oo.rotate.start",function(C,q){try{q.geometry.isHidden=true;q.geometry.defocus();u.n141=true;u.n19b.clear();u.n19b.clearGeometry();u.n19b.isSolid=true;u.n19b.n18d(q.geometry);q.geometry.getColor&&u.n19b.n22f(o.n107(q.geometry.getColor(),
70));u.draw()}catch(F){u.error(F,"handler[oo.rotate.start]")}});t.bind("oo.rotate.stop",function(C,q){try{q.geometry.isHidden=false;u.n141=false;var F={type:o.C.xform_rotate,clockwise:u.alignedDir<0?q.clockwise:!q.clockwise,pivotAxis:u.n1b5,angle:q.angle,v:o.C.xformversion};q.geometry.rotate(F,false);m={type:o.C.n16a,xform:F};if(q.geometry.geomType==o.C.n117&&q.geometry.isTemporary())m.geometry_uid_list=_(q.geometry.children).pluck("uid");else m.geometry_uid=q.geometry.uid;u.draw();u.model.do_(m);
m=null}catch(G){u.error(G,"handler[oo.rotate.stop]")}});t.bind("oo.rotate.standard",function(C,q){try{var F={type:o.C.xform_rotate,clockwise:u.alignedDir<0?q.clockwise:!q.clockwise,pivotAxis:u.n1b5,angle:q.angle,v:o.C.xformversion};u.n141=false;q.geometry.rotate(F,true);m={type:o.C.n16a,xform:F};if(q.geometry.geomType==o.C.n117&&q.geometry.isTemporary())m.geometry_uid_list=_(q.geometry.children).pluck("uid");else m.geometry_uid=q.geometry.uid;u.model.do_(m);m=null}catch(G){u.error(G,"handler[oo.rotate.standard]")}});
t.bind("oo.scale.continue",function(C,q){try{u.n19b.isSolid=true;u.n19b.n0ac({type:"scale",scaleX:q.scaleX,scaleY:q.scaleY,scaleZ:q.scaleZ});u.draw()}catch(F){u.error(F,"handler[oo.scale.continue]")}});t.bind("oo.scale.start",function(C,q){try{q.geometry.isHidden=true;q.geometry.defocus();u.n141=true;u.n19b.clear();u.n19b.clearGeometry();u.n19b.isSolid=true;u.n19b.n18d(q.geometry);q.geometry.getColor&&u.n19b.n22f(o.n107(q.geometry.getColor(),70));u.draw()}catch(F){u.error(F,"handler[oo.scale.start]")}});
t.bind("oo.scale.stop",function(C,q){try{q.geometry.isHidden=false;u.n141=false;var F={type:o.C.n1ac,scaleX:q.scaleX,scaleY:q.scaleY,scaleZ:q.scaleZ,v:o.C.xformversion};q.geometry.scale(F,false);m={type:o.C.op_objscale,xform:F};if(q.geometry.geomType==o.C.n117&&q.geometry.isTemporary())m.geometry_uid_list=_(q.geometry.children).pluck("uid");else m.geometry_uid=q.geometry.uid;u.draw();u.model.do_(m);m=null}catch(G){u.error(G,"handler[oo.rotate.stop]")}});t.bind("oo.shear.start",function(C,q){try{q.geometry.isHidden=
true;q.geometry.defocus();u.n141=true;u.n19b.clear();u.n19b.clearGeometry();u.n19b.isSolid=true;u.n19b.n18d(q.geometry);q.geometry.getColor&&u.n19b.n22f(o.n107(q.geometry.getColor(),70));u.draw()}catch(F){u.error(F,"handler[oo.shear.start]")}});t.bind("oo.shear.continue",function(C,q){try{u.n19b.isSolid=true;u.n19b.n0ac({type:"shear",shearXY:u.n1b5==2&&q.shearType=="horz"?q.shearRatio:0,shearYX:u.n1b5==2&&q.shearType=="vert"?q.shearRatio:0,shearXZ:u.n1b5==1&&q.shearType=="horz"?q.shearRatio:0,shearZX:u.n1b5==
1&&q.shearType=="vert"?q.shearRatio:0,shearZY:u.n1b5==0&&q.shearType=="horz"?q.shearRatio:0,shearYZ:u.n1b5==0&&q.shearType=="vert"?q.shearRatio:0});u.draw()}catch(F){u.error(F,"handler[oo.shear.continue]")}});t.bind("oo.shear.stop",function(C,q){try{q.geometry.isHidden=false;u.n141=false;var F={type:o.C.xform_shear,shearXY:u.n1b5==2&&q.shearType=="horz"?q.shearRatio:0,shearYX:u.n1b5==2&&q.shearType=="vert"?q.shearRatio:0,shearXZ:u.n1b5==1&&q.shearType=="horz"?q.shearRatio:0,shearZX:u.n1b5==1&&q.shearType==
"vert"?q.shearRatio:0,shearZY:u.n1b5==0&&q.shearType=="horz"?q.shearRatio:0,shearYZ:u.n1b5==0&&q.shearType=="vert"?q.shearRatio:0,v:o.C.xformversion};q.geometry.shear(F,false);m={type:o.C.op_objshear,xform:F};if(q.geometry.geomType==o.C.n117&&q.geometry.isTemporary())m.geometry_uid_list=_(q.geometry.children).pluck("uid");else m.geometry_uid=q.geometry.uid;u.draw();u.model.do_(m);m=null}catch(G){u.error(G,"handler[oo.shear.stop]")}});t.bind("oo.flip",function(C,q){try{u.n141=false;j(q.geometry,q.horizFlip?
u.n23a:u.n265,u);u.model.do_(m);m=null}catch(F){u.error(F,"handler[oo.flip]")}});t.bind("oo.move.start",function(C,q){try{u.n141=false;e(q.geometry,q.ev,u)}catch(F){u.error(F,"handler[oo.move.start]")}});t.bind("oo.move.continue",function(C,q){try{u.n141=false;B&&m&&g(q.ev,q.geometry,u)}catch(F){u.error(F,"handler[oo.move.continue]")}});t.bind("oo.move.stop",function(C,q){try{u.n141=false;if(B&&m){var F=h(q.ev,q.geometry,u);q.geometry.focus({r:0,g:0,b:255});if(F){y(u.canvas).trigger("view_changed",
u);u.model.do_(m)}m=null}}catch(G){G.message!=o.C.exception_unexpected_empty_cubegroup&&u.error(G,"handler[oo.move.stop]")}});t.bind("oo.2x",function(C,q){try{p(q.geometry,u);u.model.do_(m);m=null}catch(F){u.error(F,"handler[oo.2x]")}});t.bind("oo.smooth",function(C,q){try{var F=q.geometry.smoothness;q.geometry.setSmoothness(q.smoothness,function(){y(u.canvas).trigger("model_changed",u.model)});m={type:o.C.n0da,cubeg_uid:q.geometry.uid,oldsmoothness:F,newsmoothness:q.smoothness};u.model.do_(m);m=
null}catch(G){u.error(G,"handler[oo.smooth]")}});t.bind("oo.clone",function(C,q){try{q.geometry.clone(function(G){G.origuid=q.geometry.uid;G.n0c9();G.alignToGrid();u.geometry=G;app.editor.setAction(o.C.n1d1)})}catch(F){u.error(F,"handler[oo.clone]")}});t.bind("oo.edit",function(C,q){try{m={type:o.C.n1dc,geometry_uid:q.geometry.uid,oldparams:q.geometry.params,oldmesh:q.geometry.origmesh,oldalignment:q.geometry.alignment,newparams:q.newparams,newmesh:q.newmesh,newalignment:q.newalignment};q.geometry.n153(q.newmesh,
q.newparams,q.newalignment);u.model.do_(m);m=null}catch(F){u.error(F,"handler[oo.edit]")}});t.bind("oo.delete",function(C,q){try{var F=function(I){var J={type:o.C.n1cd,geomsign:I.n1ad()};u.model.removeGeometry(I);return J};C=function(I){var J={type:o.C.n16e,mod_type:"erase",mods:[{cubeg_uid:I.uid,cubes:_(I.cubes).chain().compact().map(function(L){return{position:L.position,rgba:_.clone(L.rgba)}}).value()}]};I.removeAllCubes();return J};var G=function(I){return{type:o.C.n0ef,delete_ops:_(I).map(function(J){if(J.geomType==
o.C.n0b2)throw new Error("Unexpected: cubegroup geometry in group");else return F(J)})}};m=_.isArray(q.geometry)?G(q.geometry):q.geometry.geomType==o.C.n0b2?C(q.geometry):F(q.geometry);u.model.do_(m);m=null;y(u.canvas).trigger("model_changed",u.model)}catch(K){u.error(K,"handler[oo.delete]")}});t.bind("select.update",function(C,q){C={xmin:Math.min(q.xmin,q.xmax),xmax:Math.max(q.xmin,q.xmax),ymin:Math.min(q.ymin,q.ymax),ymax:Math.max(q.ymin,q.ymax)};u.n079(C)});t.bind("select.done",function(C,q){C=
{xmin:Math.min(q.xmin,q.xmax),xmax:Math.max(q.xmin,q.xmax),ymin:Math.min(q.ymin,q.ymax),ymax:Math.max(q.ymin,q.ymax)};q=u.n079(C);if(q.length>0){C=_(q).invoke("get2dextents",u);u._jq.trigger("geometry_selected",{geometry:q,extents:o.merge2dExtents(C)})}});t.bind("oo.group",function(C,q){_(q.geometry).invoke("defocus");C=u.model.n11c(q.geometry);m={type:o.C.n264,children:_(q.geometry).pluck("uid"),group:C.uid};u.model.do_(m);m=null;u.model.n109([C],{r:0,g:0,b:255})});t.bind("oo.ungroup",function(C,
q){C=u.model.n115(q.geometry);m={type:o.C.n1b9,children:_(C).pluck("uid"),group:q.geometry.uid};u.model.do_(m);m=null;u.model.n109(C)});t.bind("oo.topalign",function(C,q){if(q.geometry.geomType==o.C.n117&&q.geometry.isTemporary()){var F=q.geometry.extents.ymax;_(q.geometry.children).each(function(G){G.translate({type:o.C.xform_translate,delta:[0,(F-(G.geomType==o.C.n117?G.extents.ymax:G.mesh.extents.ymax))/s,0],v:o.C.xformversion},true)},this)}});t.bind("oo.bottomalign",function(C,q){if(q.geometry.geomType==
o.C.n117&&q.geometry.isTemporary()){var F=q.geometry.extents.ymin;_(q.geometry.children).each(function(G){G.translate({type:o.C.xform_translate,delta:[0,(F-(G.geomType==o.C.n117?G.extents.ymin:G.mesh.extents.ymin))/s,0],v:o.C.xformversion},true)},this)}});t.bind("oo.vcenteralign",function(C,q){if(q.geometry.geomType==o.C.n117&&q.geometry.isTemporary()){var F=(q.geometry.extents.ymax+q.geometry.extents.ymin)/2;_(q.geometry.children).each(function(G){G.translate({type:o.C.xform_translate,delta:[0,(F-
(G.geomType==o.C.n117?(G.extents.ymax+G.extents.ymin)/2:(G.mesh.extents.ymax+G.mesh.extents.ymin)/2))/s,0],v:o.C.xformversion},true)},this)}});t.bind("oo.leftalign",function(C,q){if(q.geometry.geomType==o.C.n117&&q.geometry.isTemporary()){var F=q.geometry.extents.xmin;_(q.geometry.children).each(function(G){G.translate({type:o.C.xform_translate,delta:[(F-(G.geomType==o.C.n117?G.extents.xmin:G.mesh.extents.xmin))/s,0,0],v:o.C.xformversion},true)},this)}});t.bind("oo.rightalign",function(C,q){if(q.geometry.geomType==
o.C.n117&&q.geometry.isTemporary()){var F=q.geometry.extents.xmax;_(q.geometry.children).each(function(G){G.translate({type:o.C.xform_translate,delta:[(F-(G.geomType==o.C.n117?G.extents.xmax:G.mesh.extents.xmax))/s,0,0],v:o.C.xformversion},true)},this)}});t.bind("oo.hcenteralign",function(C,q){if(q.geometry.geomType==o.C.n117&&q.geometry.isTemporary()){var F=(q.geometry.extents.xmax+q.geometry.extents.xmin)/2;_(q.geometry.children).each(function(G){G.translate({type:o.C.xform_translate,delta:[(F-
(G.geomType==o.C.n117?(G.extents.xmax+G.extents.xmin)/2:(G.mesh.extents.xmax+G.mesh.extents.xmin)/2))/s,0,0],v:o.C.xformversion},true)},this)}})};o.Controller=f})(jQuery);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){function f(){}var k;k=typeof window==="undefined"?require("./declare").tin:y.tin;var n;f.init=function(b){n=b.get(0).getContext("2d");y("#helpscreen #debugmsg").text("using Canvas2D (v"+k.appVersion+")");b.show()};f.n174=function(b){n.lineWidth=b};f.clearHeadless=function(){f.n240=[0.3,0.3,0.3];f.n254=[0.9,0.9,0.9];var b=k.v3.normalize([-5,-5,-10]);f.n233=[-1*b[0],-1*b[1],-1*b[2]]};f.clear=function(b){if(y.browser.msie&&parseInt(y.browser.version,10)!=9){f.n240=[0.2,0.2,0.2];f.n254=[0.8,
0.8,0.8]}else{f.n240=[0.3,0.3,0.3];f.n254=[0.9,0.9,0.9]}var d=k.v3.normalize([-5,-5,-10]);f.n233=[-1*d[0],-1*d[1],-1*d[2]];n.clearRect(0,0,b.width(),b.height());n.fillStyle=y.browser.msie?"rgb(255,255,255)":"rgba(255,255,255,100)";n.fillRect(0,0,b.width(),b.height())};f.n17f=function(b,d){var e,g;if(d.projection==k.C.proj_orthographic){e=b[0];g=b[1]}else{e=-d.near*(b[0]/b[2]);g=-d.near*(b[1]/b[2])}b=d.height;e=d.width/2*(e/d.xmax+1);d=b/2*(g/d.ymax+1);d=b-d;return[e,d]};var c=[];f.n283=function(b){c.push(b)};
f.n20a=function(){function b(d,e){var g=e[0]-d[0],h=e[1]-d[1],j=Math.sqrt(g*g+h*h);if(j!==0){g/=2*j;h/=2*j;d[0]-=g;d[1]-=h;e[0]+=g;e[1]+=h}}n.save();_(c).each(function(d){if(d.type===k.C.n0ce){n.strokeStyle="#000";d=d.points;if(d.length>3){n.beginPath();n.moveTo(d[0][0],d[0][1]);n.lineTo(d[1][0],d[1][1]);n.lineTo(d[2][0],d[2][1]);n.lineTo(d[3][0],d[3][1])}else{n.beginPath();n.moveTo(d[0][0],d[0][1]);n.lineTo(d[1][0],d[1][1]);n.lineTo(d[2][0],d[2][1])}n.lineTo(d[0][0],d[0][1]);n.closePath();n.stroke()}else{n.fillStyle=
d.style;d=d.points;if(d.length>3){b(d[0],d[1]);b(d[1],d[2]);b(d[2],d[3]);b(d[3],d[0]);n.beginPath();n.moveTo(d[0][0],d[0][1]);n.lineTo(d[1][0],d[1][1]);n.lineTo(d[2][0],d[2][1]);n.lineTo(d[3][0],d[3][1])}else{b(d[0],d[1]);b(d[1],d[2]);b(d[2],d[0]);n.beginPath();n.moveTo(d[0][0],d[0][1]);n.lineTo(d[1][0],d[1][1]);n.lineTo(d[2][0],d[2][1])}n.lineTo(d[0][0],d[0][1]);n.closePath();n.fill()}});n.restore();c=[]};f.n1e7=function(b,d){n.save();if(d)n.strokeStyle=d;n.beginPath();n.moveTo(b[0][0],b[0][1]);
n.lineTo(b[1][0],b[1][1]);n.closePath();n.stroke();n.restore()};k.n2c0=f})(framework);
(function(y){function f(r,v){r=m.createShader(r);m.shaderSource(r,v);m.compileShader(r);if(!m.getShaderParameter(r,m.COMPILE_STATUS))return null;return r}function k(){var r=f(m.VERTEX_SHADER,s);if(!r)throw{name:"E_COMPILE_VERTEX_SHADER",message:m.getShaderInfoLog(r)};var v=f(m.FRAGMENT_SHADER,o);if(!v)throw{name:"E_COMPILE_FRAGMENT_SHADER",message:m.getShaderInfoLog(v)};var H=f(m.VERTEX_SHADER,w);if(!H)throw{name:"E_COMPILE_VERTEX_SHADER",message:m.getShaderInfoLog(H)};var t=f(m.FRAGMENT_SHADER,E);
if(!t)throw{name:"E_COMPILE_FRAGMENT_SHADER",message:m.getShaderInfoLog(t)};var u=f(m.VERTEX_SHADER,B);if(!u){console.error(m.getShaderInfoLog(u));throw{name:"E_COMPILE_VERTEX_SHADER",message:m.getShaderInfoLog(u)};}var C=f(m.FRAGMENT_SHADER,D);if(!C){console.error(m.getShaderInfoLog(C));throw{name:"E_COMPILE_FRAGMENT_SHADER",message:m.getShaderInfoLog(C)};}h=m.createProgram();m.attachShader(h,r);m.attachShader(h,v);m.linkProgram(h);if(!m.getProgramParameter(h,m.LINK_STATUS))throw{name:"E_LINK_SHADER",
message:m.getProgramInfoLog(h)};j=m.createProgram();m.attachShader(j,H);m.attachShader(j,t);m.linkProgram(j);if(!m.getProgramParameter(j,m.LINK_STATUS))throw{name:"E_LINK_SHADER",message:m.getProgramInfoLog(j)};p=m.createProgram();m.attachShader(p,u);m.attachShader(p,C);m.linkProgram(p);if(!m.getProgramParameter(p,m.LINK_STATUS)){console.error(m.getProgramInfoLog(p));throw{name:"E_LINK_SHADER",message:m.getProgramInfoLog(p)};}h.vertexPositionAttribute=m.getAttribLocation(h,"a_position");h.vertexNormalAttribute=
m.getAttribLocation(h,"a_normal");h.textureCoordAttribute=m.getAttribLocation(h,"a_texn2ad");h.samplerUniform=m.getUniformLocation(h,"u_sampler");h.n27fUniform=m.getUniformLocation(h,"u_n27f");h.n261Uniform=m.getUniformLocation(h,"u_n261");h.n27eUniform=m.getUniformLocation(h,"u_n27e");h.ambientColorUniform=m.getUniformLocation(h,"u_n240");h.directionalColorUniform=m.getUniformLocation(h,"u_n254");h.pointColorUniform=m.getUniformLocation(h,"u_pointColor");h.n233ectionUniform=m.getUniformLocation(h,
"u_dirD");h.pointLightLocationUniform=m.getUniformLocation(h,"u_pointL");j.vertexPositionAttribute=m.getAttribLocation(j,"a_position");j.vertexNormalAttribute=m.getAttribLocation(j,"a_normal");j.colorUniform=m.getUniformLocation(j,"u_color");j.n27fUniform=m.getUniformLocation(j,"u_n27f");j.n261Uniform=m.getUniformLocation(j,"u_n261");j.n27eUniform=m.getUniformLocation(j,"u_n27e");j.ambientColorUniform=m.getUniformLocation(j,"u_n240");j.directionalColorUniform=m.getUniformLocation(j,"u_n254");j.pointColorUniform=
m.getUniformLocation(j,"u_pointColor");j.n233ectionUniform=m.getUniformLocation(j,"u_dirD");j.pointLightLocationUniform=m.getUniformLocation(j,"u_pointL");p.vertexPositionAttribute=m.getAttribLocation(p,"a_position");p.n27fUniform=m.getUniformLocation(p,"u_n27f");p.n261Uniform=m.getUniformLocation(p,"u_n261");p.colorUniform=m.getUniformLocation(p,"u_color")}function n(r,v){m.uniformMatrix4fv(r.n27fUniform,false,new e(v.n27f));m.uniformMatrix4fv(r.n261Uniform,false,new e(v.n261));r.n27eUniform&&m.uniformMatrix4fv(r.n27eUniform,
false,new e(v.n27e))}function c(){}function b(r){var v=[];r=r||{r:200,g:200,b:200};if(r.r<30&&r.g<30&&r.b<30){r.r=Math.max(r.r,30);r.g=Math.max(r.g,30);r.b=Math.max(r.b,30)}var H=r.r+"_"+r.g+"_"+r.b+"_"+r.a;if(A[H])return A[H];for(var t=0;t<4;t++)r.a&&r.a<100?v.push(r.r,r.g,r.b,r.a):v.push(r.r,r.g,r.b);v=new Uint8Array(v);m.pixelStorei(m.UNPACK_ALIGNMENT,1);t=m.createTexture();m.bindTexture(m.TEXTURE_2D,t);r.a&&r.a<100?m.texImage2D(m.TEXTURE_2D,0,m.RGBA,2,2,0,m.RGBA,m.UNSIGNED_BYTE,v):m.texImage2D(m.TEXTURE_2D,
0,m.RGB,2,2,0,m.RGB,m.UNSIGNED_BYTE,v);m.texParameteri(m.TEXTURE_2D,m.TEXTURE_MIN_FILTER,m.NEAREST);m.texParameteri(m.TEXTURE_2D,m.TEXTURE_MAG_FILTER,m.NEAREST);m.texParameteri(m.TEXTURE_2D,m.TEXTURE_WRAP_S,m.CLAMP_TO_EDGE);m.texParameteri(m.TEXTURE_2D,m.TEXTURE_WRAP_T,m.CLAMP_TO_EDGE);m.generateMipmap(m.TEXTURE_2D);m.bindTexture(m.TEXTURE_2D,null);return A[H]=t}var d=y.tin;if(typeof Float32Array=="undefined")var e=Array,g=Array;else{e=Float32Array;g=Uint16Array}var h,j,p,o="precision highp float;varying vec3 v_lightWt;varying vec4 v_position;varying vec4 v_tnormal;uniform vec3 u_pointL;uniform vec3 u_pointColor;varying vec2 v_texn2ad;uniform sampler2D u_sampler;void main(void){  vec3 n233 = normalize(u_pointL - v_position.xyz);  vec3 normal = normalize(v_tnormal.xyz);  vec3 eyedir = normalize(-v_position.xyz);  vec3 reflectdir = reflect(-n233, normal);  float specularLightWt = pow(max(dot(reflectdir, eyedir), 0.0), 9.0);  vec3 totalLightWt = v_lightWt + specularLightWt * u_pointColor;  vec4 t_color = texture2D(u_sampler, vec2(v_texn2ad.s, v_texn2ad.t));  gl_FragColor = vec4(t_color.rgb * totalLightWt, t_color.a);}",
s="attribute vec3 a_position;attribute vec3 a_normal;uniform mat4 u_n261;uniform mat4 u_n27f;uniform mat4 u_n27e;varying vec4 v_position;varying vec3 v_lightWt;varying vec4 v_tnormal;uniform vec3 u_dirD;uniform vec3 u_pointL;uniform vec3 u_n240;uniform vec3 u_n254;uniform vec3 u_pointColor;attribute vec2 a_texn2ad;varying vec2 v_texn2ad;void main(void) {  v_position = u_n261 * vec4(a_position, 1.0);  gl_Position = u_n27f * v_position;  v_tnormal = u_n27e * vec4(a_normal, 1.0);  float lightWeight = max(dot(v_tnormal.xyz, u_dirD), 0.0);  v_lightWt = u_n240 + u_n254 * lightWeight;  v_texn2ad = a_texn2ad;}",
E="precision highp float;varying vec3 v_lightWt;varying vec4 v_position;varying vec4 v_tnormal;uniform vec3 u_pointL;uniform vec3 u_pointColor;varying vec4 v_color;void main(void){  vec3 n233 = normalize(u_pointL - v_position.xyz);  vec3 normal = normalize(v_tnormal.xyz);  vec3 eyedir = normalize(-v_position.xyz);  vec3 reflectdir = reflect(-n233, normal);  float specularLightWt = pow(max(dot(reflectdir, eyedir), 0.0), 9.0);  vec3 totalLightWt = v_lightWt + specularLightWt * u_pointColor;  gl_FragColor = vec4(v_color.rgb * totalLightWt, v_color.a);}",
w="attribute vec3 a_position;attribute vec3 a_normal;uniform mat4 u_n261;uniform mat4 u_n27f;uniform mat4 u_n27e;varying vec4 v_position;varying vec3 v_lightWt;varying vec4 v_tnormal;uniform vec3 u_dirD;uniform vec3 u_pointL;uniform vec3 u_n240;uniform vec3 u_n254;uniform vec3 u_pointColor;uniform vec4 u_color;varying vec4 v_color;void main(void) {  v_position = u_n261 * vec4(a_position, 1.0);  gl_Position = u_n27f * v_position;  v_tnormal = u_n27e * vec4(a_normal, 1.0);  float lightWeight = max(dot(v_tnormal.xyz, u_dirD), 0.0);  v_lightWt = u_n240 + u_n254 * lightWeight;  v_color = u_color;}",
D="precision highp float;uniform vec4 u_color;void main(void) {  gl_FragColor = u_color;}",B="attribute vec3 a_position;uniform vec4 u_color;uniform mat4 u_n261;uniform mat4 u_n27f;void main(void) {  gl_Position = u_n27f * u_n261 * vec4(a_position, 1.0);}",m;c.init=function(r){m=r.get(0).getContext("experimental-webgl",{antialias:true});c.gl=m;c.LINES=m.LINES;c.TRIANGLES=m.TRIANGLES;c.ARRAY_BUFFER=m.GL_ARRAY_BUFFER;c.ELEMENT_ARRAY_BUFFER=m.GL_ELEMENT_ARRAY_BUFFER;c.STATIC_DRAW=m.STATIC_DRAW;c.DYNAMIC_DRAW=
m.DYNAMIC_DRAW;m.viewport(0,0,r.width(),r.height());k();y("#helpscreen #debugmsg").text("using WebGL (v"+d.appVersion+")");r.show();m.clearColor(1,1,1,1);m.clearDepth(1);m.enable(m.DEPTH_TEST);m.depthFunc(m.LEQUAL);m.frontFace(m.CCW);m.cullFace(m.BACK);m.enable(m.CULL_FACE);m.blendFunc(m.ONE,m.ONE_MINUS_SRC_ALPHA)};c.n23b=function(r){r?m.enable(m.BLEND):m.disable(m.BLEND)};c.n15b=function(r){r?m.enable(m.DEPTH_TEST):m.disable(m.DEPTH_TEST)};c.makeBuffer=function(r,v,H,t,u){var C=m.createBuffer();
if(!C)throw new Error(d.C.n069);m.bindBuffer(r,C);m.bufferData(r,H,v);C.b3dItemSize=t;C.b3dNumItems=u;m.bindBuffer(r,null);return C};c.updateBuffer=function(r,v){m.bindBuffer(m.ARRAY_BUFFER,r);m.bufferData(m.ARRAY_BUFFER,v,m.DYNAMIC_DRAW);m.bindBuffer(m.ARRAY_BUFFER,null)};c.updateIndexBuffer=function(r,v){m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,r);m.bufferData(m.ELEMENT_ARRAY_BUFFER,v,m.DYNAMIC_DRAW);m.bindBuffer(m.ARRAY_BUFFER,null)};c.drawLine=function(r,v,H){m.enableVertexAttribArray(p.vertexPositionAttribute);
v=v||{r:200,g:200,b:200};m.useProgram(p);m.bindBuffer(m.ARRAY_BUFFER,r.vtx);m.vertexAttribPointer(p.vertexPositionAttribute,r.vtx.b3dItemSize,m.FLOAT,false,0,0);m.uniform4f(p.colorUniform,v.r/255,v.g/255,v.b/255,1);n(p,H);m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,r.idx);m.drawElements(m.LINES,r.idx.b3dNumItems,m.UNSIGNED_SHORT,0);m.bindBuffer(m.ARRAY_BUFFER,null);m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,null);m.disableVertexAttribArray(p.vertexPositionAttribute)};c.drawTextured=function(r,v,H){m.enableVertexAttribArray(h.vertexPositionAttribute);
m.enableVertexAttribArray(h.vertexNormalAttribute);m.enableVertexAttribArray(h.textureCoordAttribute);m.useProgram(h);m.bindBuffer(m.ARRAY_BUFFER,r.vtx);m.vertexAttribPointer(h.vertexPositionAttribute,r.vtx.b3dItemSize,m.FLOAT,false,0,0);m.bindBuffer(m.ARRAY_BUFFER,r.nrm);m.vertexAttribPointer(h.vertexNormalAttribute,r.nrm.b3dItemSize,m.FLOAT,false,0,0);m.bindBuffer(m.ARRAY_BUFFER,r.tex);m.vertexAttribPointer(h.textureCoordAttribute,r.tex.b3dItemSize,m.FLOAT,false,0,0);m.activeTexture(m.TEXTURE0);
m.bindTexture(m.TEXTURE_2D,b(r.rgba));m.uniform1i(h.samplerUniform,0);n(h,H);m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,r.idx);m.drawElements(m.TRIANGLES,r.idx.b3dNumItems,m.UNSIGNED_SHORT,0);m.bindBuffer(m.ARRAY_BUFFER,null);m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,null);m.disableVertexAttribArray(h.vertexPositionAttribute);m.disableVertexAttribArray(h.vertexNormalAttribute);m.disableVertexAttribArray(h.textureCoordAttribute)};c.drawColored=function(r,v,H){m.enableVertexAttribArray(j.vertexPositionAttribute);
m.enableVertexAttribArray(j.vertexNormalAttribute);m.useProgram(j);m.bindBuffer(m.ARRAY_BUFFER,r.vtx);m.vertexAttribPointer(j.vertexPositionAttribute,r.vtx.b3dItemSize,m.FLOAT,false,0,0);m.bindBuffer(m.ARRAY_BUFFER,r.nrm);m.vertexAttribPointer(j.vertexNormalAttribute,r.nrm.b3dItemSize,m.FLOAT,false,0,0);m.uniform4f(j.colorUniform,r.rgba.r/255,r.rgba.g/255,r.rgba.b/255,r.rgba.a/100);n(j,H);m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,r.idx);m.drawElements(m.TRIANGLES,r.idx.b3dNumItems,m.UNSIGNED_SHORT,0);m.bindBuffer(m.ARRAY_BUFFER,
null);m.bindBuffer(m.ELEMENT_ARRAY_BUFFER,null);m.disableVertexAttribArray(j.vertexPositionAttribute);m.disableVertexAttribArray(j.vertexNormalAttribute)};c.n174=function(r){m.lineWidth(r)};c.deleteBuffer=function(r){m.deleteBuffer(r)};c.enableStencil=function(){m.clearStencil(0);m.clear(m.STENCIL_BUFFER_BIT);m.enable(m.STENCIL_TEST);m.stencilFunc(m.ALWAYS,1,65535);m.stencilOp(m.KEEP,m.KEEP,m.REPLACE)};c.setStencil=function(){m.stencilFunc(m.NOTEQUAL,1,65535);m.stencilOp(m.KEEP,m.KEEP,m.REPLACE)};
c.disableStencil=function(){m.disable(m.STENCIL_TEST)};c.clear=function(r){var v=r.backgroundColor?_.extend({a:100},r.backgroundColor):{r:0,g:0,b:0,a:0};m.clearColor(v.r/255,v.g/255,v.b/255,v.a/100);m.clear(m.COLOR_BUFFER_BIT|m.DEPTH_BUFFER_BIT);m.useProgram(h);if(r.ambientLightColor){v=r.ambientLightColor;m.uniform3f(h.ambientColorUniform,v.r/255,v.g/255,v.b/255)}else m.uniform3f(h.ambientColorUniform,0.2,0.2,0.2);if(r.dirLightColor){v=r.dirLightColor;m.uniform3f(h.directionalColorUniform,v.r/255,
v.g/255,v.b/255)}if(r.pointLightColor){v=r.pointLightColor;m.uniform3f(h.pointColorUniform,v.r/255,v.g/255,v.b/255)}if(r.dirLightDirection){v=d.v3.normalize(r.dirLightDirection);m.uniform3f(h.n233ectionUniform,-1*v[0],-1*v[1],-1*v[2])}if(r.pointLightPosition){v=r.pointLightPosition;m.uniform3f(h.pointLightLocationUniform,v[0],v[1],v[2])}m.useProgram(j);if(r.ambientLightColor){v=r.ambientLightColor;m.uniform3f(j.ambientColorUniform,v.r/255,v.g/255,v.b/255)}else m.uniform3f(j.ambientColorUniform,0.2,
0.2,0.2);if(r.dirLightColor){v=r.dirLightColor;m.uniform3f(j.directionalColorUniform,v.r/255,v.g/255,v.b/255)}if(r.pointLightColor){v=r.pointLightColor;m.uniform3f(j.pointColorUniform,v.r/255,v.g/255,v.b/255)}if(r.dirLightDirection){v=d.v3.normalize(r.dirLightDirection);m.uniform3f(j.n233ectionUniform,-1*v[0],-1*v[1],-1*v[2])}if(r.pointLightPosition){v=r.pointLightPosition;m.uniform3f(j.pointLightLocationUniform,v[0],v[1],v[2])}};var A={};d.n2be=c})(jQuery);
(function(y){function f(d,e){this.n2bc=d;this.view=e;this.update(e);var g=this;y(e.canvas).bind("view_changed",function(h,j){g.update(j)})}var k=y.tin,n=k.C.cube_size;if(typeof Float32Array=="undefined")var c=Array,b=Array;else{c=Float32Array;b=Uint16Array}f.makeGridHole=function(d,e,g,h){var j=new c(3*(2*h+1)*(2*e+1)),p=0;for(z=-h;z<=h;z++)for(x=-e;x<=e;x++){j[p]=x*n;j[p+1]=0;j[p+2]=z*n;p+=3}p=0;var o=2*e+1+(2*h+1)+(2*d+1)+(2*g+1),s=new Uint16Array(2*o);for(z=-h;z<=h;z++){if(Math.abs(z)>d)s[p]=(z+
h)*(2*e+1);else{s[p]=(z+h)*(2*e+1);s[p+1]=(z+h)*(2*e+1)+(e-d);p+=2;s[p]=(z+h)*(2*e+1)+(e+d)}s[p+1]=(z+h)*(2*e+1)+2*e;p+=2}for(x=-e;x<=e;x++){if(Math.abs(x)>g){s[p]=x+e;s[p+1]=x+e+(2*e+1)*2*h}else{s[p]=x+e;s[p+1]=x+e+(2*e+1)*(h-g);p+=2;s[p]=x+e+(2*e+1)*(h+g);s[p+1]=x+e+(2*e+1)*2*h}p+=2}d=k.n2be.makeBuffer(k.n2be.gl.ARRAY_BUFFER,k.n2be.gl.STATIC_DRAW,j,3,(2*h+1)*(2*e+1));o=k.n2be.makeBuffer(k.n2be.gl.ELEMENT_ARRAY_BUFFER,k.n2be.gl.STATIC_DRAW,s,1,2*o);return{vtx:d,idx:o}};f.prototype={update:function(d){var e,
g,h=-1*n/2,j;if(this.n2bc){if(!this.n2a3){this.n2a3=[];this.n2a3.push(f.makeGridHole(0,20,0,20));this.n2a3.push(f.makeGridHole(20,22,20,22));this.n2a3.push(f.makeGridHole(22,25,22,25))}}else{var p=function(w){w=k.m4.n2b4(d.n261,w);if(w[2]>=0)throw"E_CLIP";else return k.n2c0.n17f(w,d)},o=function(w,D){w=k.m4.n2b4(d.n261,w);D=k.m4.n2b4(d.n261,D);var B;if(w[2]>=0){B=(-0.01-w[2])/(D[2]-w[2]);w[0]+=B*(D[0]-w[0]);w[1]+=B*(D[1]-w[1]);w[2]=-0.01}if(D[2]>=0){B=(-0.01-D[2])/(w[2]-D[2]);D[0]+=B*(w[0]-D[0]);
D[1]+=B*(w[1]-D[1]);D[2]=-0.01}return[k.n2c0.n17f(w,d),k.n2c0.n17f(D,d)]};this.n29f=[];for(j=-20;j<21;j++){e=[n*(j+0.5),h,n*-19.5];g=[n*(j+0.5),h,n*20.5];try{this.n29f.push([p(e),p(g)])}catch(s){this.n29f.push(o(e,g))}}for(j=-20;j<21;j++){e=[n*-19.5,h,n*(j+0.5)];g=[n*20.5,h,n*(j+0.5)];try{this.n29f.push([p(e),p(g)])}catch(E){this.n29f.push(o(e,g))}}}},draw:function(){if(this.n2bc){k.n2be.n174(1);k.n2be.drawLine(this.n2a3[0],{r:223,g:223,b:223},this.view);k.n2be.drawLine(this.n2a3[1],{r:235,g:235,
b:235},this.view);k.n2be.drawLine(this.n2a3[2],{r:245,g:245,b:245},this.view)}else for(var d=0,e=this.n29f.length;d<e;d++)k.n2c0.n1e7([this.n29f[d][0],this.n29f[d][1]],"#ddd")}};k.Grid=f;k.AxisDial={update:function(d){function e(B,m){if(m.projection==k.C.proj_orthographic){m=B[0];B=B[1]}else{m=-w*(B[0]/B[2]);B=-w*(B[1]/B[2])}m=p/2*(m/s+1);B=o/2*(B/E+1);B=o-B;return[m,B]}function g(B,m){j.save();if(m)j.strokeStyle=m;j.lineCap="round";j.beginPath();j.moveTo(B[0][0],B[0][1]);j.lineTo(B[1][0],B[1][1]);
j.closePath();j.stroke();j.restore()}var h=y("#axisdial"),j=h.get(0).getContext("2d"),p=h.get(0).width=75,o=h.get(0).height=75,s,E,w=0.1;s=d.projection==k.C.proj_orthographic?(E=8):(E=w*Math.tan(70*Math.PI/360));j.clearRect(0,0,h.width(),h.height());var D=function(B){return k.m4.n2b4(d.n261,B)};h=function(B){return e(B,d)};D=[[D([0,0,0]),D([7,0,0]),"#55f"],[D([0,0,0]),D([0,7,0]),"#5f5"],[D([0,0,0]),D([0,0,7]),"#f55"]];D=_(D).sortBy(function(B){return B[1][2]});j.lineWidth=2;g([h(D[0][0]),h(D[0][1])],
D[0][2]);g([h(D[1][0]),h(D[1][1])],D[1][2]);g([h(D[2][0]),h(D[2][1])],D[2][2])}}})(jQuery);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){var f;if(typeof window==="undefined"){require("util");_=require("../../../libs/underscore")._;logger=require("../../ext/ain.js").set({tag:"EXPORT",facility:"local2"});Base=require("../../../libs/base").Base;f=require("./declare").tin;require("./basecube");require("./interactivecubestub");require("./cubegroup");require("./groupgeometry");require("./csggeometry");require("./ccengine");require("./mesh3d")}else f=y.tin;var k=f.C.cube_size,n=f.C.min_align;y=Base.extend({constructor:function(){this.n1c9=
[];this.n29c=[];this.n278=false;this.smoothness=0;this.opq=[];this.n1f9=this.n217=this.n243=0;this.form=f.C.model_form_solid},_OPQ_LENGTH:50,n286:function(c){this.view=c},n297:function(c){var b=_(this.n1c9).select(function(d){return d.contains(c)},this)[0];if(b&&b.n297)return b.n297(c)},n1c9At:function(c){return _(this.n1c9).select(function(b){return b.contains(c)},this)},removeAll:function(){this.n1c9=[]},addGeometry:function(c){this.n1c9.push(c)},removeGeometry:function(c){this.n1c9=_(this.n1c9).reject(function(b){return _.isEqual(b.uid,
c.uid)})},n11c:function(c,b){var d=new f.n14d(this,c,b);_(c).each(function(e){this.removeGeometry(e);e.parent=d},this);this.addGeometry(d);return d},n115:function(c){if(c.geomType==f.C.n117){this.removeGeometry(c);_(c.children).each(this.addGeometry,this);return c.children}else throw new Error("Only group geometry can be ungrouped");},hasGeometry:function(c){return _(this.n1c9).any(function(b){return b.uid===c.uid},this)},unfadeAllGeometries:function(){_(this.n1c9).each(function(c){c.isFaded=false})},
forceCubicle:function(){_(this.n1c9).each(function(c){if(!c.isCSG)c.forceCubicle=true},this)},unforceCubicle:function(){_(this.n1c9).each(function(c){if(!c.isCSG)c.forceCubicle=false},this)},n176:function(c){return _([[c[0],c[1],c[2]-1],[c[0],c[1],c[2]+1],[c[0],c[1]+1,c[2]],[c[0],c[1]-1,c[2]],[c[0]+1,c[1],c[2]],[c[0]-1,c[1],c[2]]]).chain().map(this.n297,this).select(function(b){return b&&!b.isVirtual}).value()},n1cf:function(c,b){return this.n297([c[0]+f.n24c.deltas[b][0],c[1]+f.n24c.deltas[b][1],
c[2]+f.n24c.deltas[b][2]])},n1a1:function(){var c=0;_(this.n1c9).each(function(b){b.type||_(b.cubes).each(function(d){if(d)c+=6-d.n1b7.length},this)},this);return c},setForm:function(c){var b=this.form;this.form=c;_(this.n1c9).each(function(d){d.setForm(c)});b!=c&&this.prepare()},n0b4:function(){for(var c=this.smoothness,b=this.n1a1();;)if(b*Math.pow(4,c)>5E3){c-=1;if(c===0)return 0}else return c;return c},countPoly:function(){return _(this.n1c9).reduce(function(c,b){return c+b.mesh.numpoly},0)},
fromString:function(c,b,d){this.n1c9=[];try{var e=JSON.parse(c)}catch(g){this.view.error(g,"Corrupt Document");throw new Error(f.C.exception_corrupt_file);}this.fromJSON(e,b,d)},listCSGToPrepare:function(c){function b(e){_(e).each(function(g){if(g.template)d.push(g);else g.geomType==f.C.n117&&b(g.children)})}var d=[];_(c.objects).each(function(e){if(e.template)d.push(e);else e.geomType==f.C.n117&&b(e.children)});return d},preprocessJSON:function(c,b){function d(p){if(p.template){if(!g.view.n2bc&&
typeof window!="undefined")throw new Error(f.C.exception_webgl_req_advgeom);if(typeof p.template!="string")p.template=f.templateLegacyMap[p.template];var o=c.colorlist.slice(4*p.color,4*p.color+4),s={r:o[0],g:o[1],b:o[2],a:o[3]};g.view.meshLoader.getMesh(p.template,p.params,function(E){var w=new f.Mesh3D(g.view);w.n196(E.surfaces);g.n0d0.push(new f.n18e(p.template,g,g.view,s,p.params,{mesh:w,alignment:p.alignment||{x:n,y:n,z:n}},p.uid));j++;g.view._jq&&g.view._jq.trigger("sketchelem_load_inprogress",
parseInt(j*100/h.length,10));e++;if(e<h.length)d(h[e]);else b&&b()},function(E){var w=new Error(f.C.exception_geomprepare_failed);g.view.error(w,E);throw w;})}else{e++;if(e<h.length)d(h[e]);else b&&b()}}this.n0d0=[];var e=0,g=this,h=this.listCSGToPrepare(c),j=0;if(e<h.length)d(h[e]);else b&&b()},fromJSON:function(c,b,d){function e(w,D){if(typeof w.template!="string")w.template=f.templateLegacyMap[w.template];c.colorlist.slice(4*w.color,4*w.color+4);var B=j.n0d0[p++];_(w.transforms).each(function(m){if(m.type==
f.C.xform_rotate)if(parseFloat(c.specversion)<=0.4)m.clockwise=!m.clockwise;B.n131(m)},j);D?B.setParent(D):j.addGeometry(B);return B}function g(w,D){for(var B=new f.n200(j,j.view,w.uid),m=0,A=w.locations.length/3;m<A;m++){var r=w.locations.slice(3*m,3*m+3),v=c.colorlist.slice(4*w.colors[m],4*w.colors[m]+4);r=new f.n10a({position:r,rgba:{r:v[0],g:v[1],b:v[2],a:v[3]}});B.n26d(r);B.smoothness=w.smoothness?Math.min(w.smoothness,f.C.max_smoothness):0}B.n14c();D?B.setParent(D):j.addGeometry(B);return B}
function h(w,D){var B=new f.n14d(j,null,w.uid);_(w.children).each(function(m){m.template?B.addChild(e(m,B)):B.addChild(h(m,B))});B.makeVoxels();B.calcExtents();D?B.setParent(D):j.addGeometry(B);return B}if(!c.specversion)throw"Old experimental format (now unsupported)";var j=this,p=0;_(c.objects).each(function(w){if(w.template)e(w);else w.geomType==f.C.n117?h(w):g(w)},this);if(c.currentcolor){var o=c.currentcolor;this.view.setCurrentColor({r:o[0],g:o[1],b:o[2],a:o[3]})}o={};if(c.camera){var s=c.camera.projection==
"p"?f.C.proj_perspective:f.C.proj_orthographic;this.view.n08c(s);if(s==f.C.proj_perspective){if(c.camera.yfov){o.zoom=parseInt(c.camera.yfov,10);o.ymax=this.view.near*Math.tan(o.zoom*Math.PI/360);o.xmax=o.ymax*this.view.aspect}}else if(c.camera.ymag){o.ymax=parseInt(c.camera.ymag,10);o.xmax=o.ymax*this.view.aspect}}if(c.icamera)c.icamera.position&&c.icamera.target?this.view.camera.update({position:c.icamera.position,target:c.icamera.target}):this.view.camera.update({position:[0,25,25],target:[0,0,
0]});if(c.point){s=c.point.color;this.view.n08f(f.C.lighttype_point,{r:s[0],g:s[1],b:s[2]},false)}if(c.directional){s=c.directional.color;this.view.n08f(f.C.lighttype_directional,{r:s[0],g:s[1],b:s[2]},false)}if(c.ambient){s=c.ambient.color;this.view.n08f(f.C.lighttype_ambient,{r:s[0],g:s[1],b:s[2]},false)}s={r:255,g:255,b:255};if(c.background){s=c.background.color;s={r:s[0],g:s[1],b:s[2]}}this.view.n06b(s,false);c.ipoint&&this.view.n065(c.ipoint.position,false);c.idirectional?this.view.n061(c.idirectional.direction,
false):this.view.n061([-5,-5,-10],false);this.view.update(o);if(c.specversion==="0.3")if(_.isUndefined(c.smoothness))b&&b();else{var E=d?this.checkSmoothnessHighPoly(c.smoothness,d):c.smoothness;_(this.n1c9).each(function(w){if(!w.isCSG)w.smoothness=E},this);this.setSmoothness(b)}else if(parseFloat(c.specversion)>=0.4)this.setSmoothness(b);else b&&b()},n12b:function(){return _(this.n1c9).any(function(c){return c.isAbstractCSG()})},hasCSG:function(){return _(this.n1c9).any(function(c){return c.isCSG})},
toString:function(){function c(A){var r=-1;_(g).each(function(v,H){if(_.isEqual(v,A))r=H});if(r<0){r=g.length;g.push(A)}return r}function b(A){return obj={uid:A.uid,geomType:f.C.n14e,template:A.type,params:A.params,color:c(A.color),alignment:A.alignment,transforms:A.transforms}}function d(A){var r={uid:A.uid,locations:[],colors:[],smoothness:A.smoothness,geomType:f.C.n14e};_(A.cubes).each(function(v){if(v){r.locations.push(v.position);v=c(v.rgba);r.colors.push(v)}},this);r.locations=_(r.locations).flatten();
return r}function e(A){var r=_(A.children).map(function(v){if(v.geomType==f.C.n14e)return b(v);else if(v.geomType==f.C.n117)return e(v)});return{uid:A.uid,geomType:f.C.n117,children:r,transforms:A.transforms}}var g=[],h=[];_(this.n1c9).each(function(A){if(A.geomType==f.C.n14e)h.push(b(A));else if(A.geomType==f.C.n0b2)h.push(d(A));else A.geomType==f.C.n117&&h.push(e(A))},this);g=_(g).chain().map(function(A){return[A.r,A.g,A.b,A.a]}).flatten().value();var j=this.view.projection==f.C.proj_perspective?
"p":"o",p=this.view.n10e();p=[p.r,p.g,p.b,p.a];var o=this.view.getLightColor(f.C.lighttype_directional);o=[o.r,o.g,o.b];var s=this.view.getLightColor(f.C.lighttype_point);s=[s.r,s.g,s.b];var E=this.view.getLightColor(f.C.lighttype_ambient);E=[E.r,E.g,E.b];var w=this.view.getBackgroundColor();w=[w.r,w.g,w.b];var D=this.view.camera.position[0]+","+this.view.camera.position[1]+","+this.view.camera.position[2],B=this.view.camera.target[0]+","+this.view.camera.target[1]+","+this.view.camera.target[2],
m="{";m+='"filetype":"cubicle",';m+='"specversion":"'+f.C.specversion+'",';m+='"colorlist" : '+JSON.stringify(g)+",";m+='"objects" : '+JSON.stringify(h);m+=",";m+='"currentcolor": '+JSON.stringify(p)+",";m+='"camera" : {';m+='"projection": "'+j+'",';m+=this.view.projection==f.C.proj_perspective?'"yfov": "'+this.view.zoom+'",':'"ymag": "'+this.view.ymax+'",';m+='"aspect_ratio": "'+this.view.aspect+'",';m+='"znear": "'+this.view.near+'",';m+='"zfar": "'+this.view.far+'"';m+="},";m+='"icamera" : {';
m+='"position" : ['+D+"],";m+='"target" : ['+B+"]";m+="},";m+='"background" : {';m+='"color" : ['+w+"]";m+="},";m+='"ambient" : {';m+='"color" : ['+E+"]";m+="},";m+='"directional" : {';m+='"color" : ['+o+"]";m+="},";m+='"point" : {';m+='"color" : ['+s+"]";m+="},";m+='"ipoint" : {';m+='"position" : ['+this.view.getPointLightPosition()+"]";m+="},";m+='"idirectional" : {';m+='"direction" : ['+this.view.getDirectionalLightDirection()+"]";m+="}";m+="}";return m},n0abes:function(c){this.view._jq&&this.view._jq.trigger("smoothen_started");
this.smoothen(function(b){_(this.n1c9).each(function(d){d.geomType==f.C.n0b2&&d.smoothness!==0&&d.n0ab(b[d.uid])},this);this.view._jq&&this.view._jq.trigger("smoothen_finished");c&&c()})},smoothen:function(c){if(this.view.ccengineSupport){f.ccengine.reset();_(this.n1c9).each(function(b){if(b.geomType==f.C.n0b2)if(b.smoothness!==0){var d=b.uid;f.ccengine.prepare(d,b.smoothness);_(b.cubes).each(function(e){if(e)if(e.n1b7.length!==6){_(8).times(function(g){f.ccengine.n204(d,e.n21e(g))},this);_(6).times(function(g){if(!(e.n1b7.indexOf(g)>=
0)){var h=f.n24c.faces[g],j=[];_(4).times(function(p){j.push(e.n21e(h[p]))});f.ccengine.n27b(d,j,e.rgba)}},this)}},this)}},this);f.ccengine.run(c,this,this.view.n2bc)}},getExtents:function(){var c=1E4,b=1E4,d=1E4,e=-10000,g=-10000,h=-10000;_(this.n1c9).each(function(j){if(j.geomType==f.C.n117)j=j.extents;else{j.mesh||j.prepare();j=j.mesh.extents}c=Math.min(j.xmin,c);b=Math.min(j.ymin,b);d=Math.min(j.zmin,d);e=Math.max(j.xmax,e);g=Math.max(j.ymax,g);h=Math.max(j.zmax,h)},this);return{minx:c,miny:b,
minz:d,maxx:e,maxy:g,maxz:h}},getVolume:function(){var c=this.getExtents();return[(c.maxx-c.minx)/k,(c.maxy-c.miny)/k,(c.maxz-c.minz)/k]},getCenter:function(){var c=this.getExtents();return[Math.round((c.maxx+c.minx)/2),Math.round((c.maxy+c.miny)/2),Math.round((c.maxz+c.minz)/2)]},getFlatGeometries:function(){var c=[];(function b(d){_(d).each(function(e){e.geomType==f.C.n117?b(e.children):c.push(e)})})(this.n1c9);return c},checkSmoothnessHighPoly:function(c){return Math.min(c,f.C.max_smoothness)},
setSmoothness:function(c){this.n0abes(c)}});y.n12a=function(c){if(_.isArray(c[0])){var b=[];_(c).each(function(d){d[0]&&b.push([-d[0],d[1],d[2]])},this);return b}else return c[0]?[-c[0],c[1],c[2]]:null};y.getAbstractCSGListfromDoc=function(c){return _(c.objects).chain().filter(function(b){return b.template&&typeof(b.template=="string")},this).map(function(b){return typeof b.template!="string"?{uid:f.templateLegacyMap[b.template],params:b.params}:{uid:b.template,params:b.params}}).value()};f.n226=
y})(framework);
(function(y){var f=y.tin,k=f.C.cube_size,n=f.n226.extend({constructor:function(){this.base()},effort_:0,persistence_:0,opq:[],n243:0,n217:0,numops:0,findIntersection:function(c,b,d){return _(this.n1c9).chain().invoke("findIntersection",c,b,d).compact().max(function(e){return d.project(e.n28a())[2]}).value()},n087:function(c,b,d){if(b=this.findIntersection(c,b,d)){var e=b.n28a(),g=d.n21b(c.o);e=f.v3.sub(e,g);c=b.n093(c,d);if(c===0||c===1)c=2;else if(c===2||c===3)c=1;else if(c===4||c===5)c=0;else{c=
Math.abs(e[0]);d=Math.abs(e[1]);g=Math.abs(e[2]);c=c>d?c>g?0:2:d>g?1:2}e=-1*e[c]/Math.abs(e[c]);b=b.position.slice(0,3);b[c]+=e;b=[b[0]*k,b[1]*k,b[2]*k];var h;switch(c){case 0:h=e>0?0:1;break;case 1:h=e>0?2:3;break;case 2:h=e>0?4:5;break}return{pos:b,dir:h}}return null},n152:function(c,b,d){var e,g,h;if(!b)throw new Error(f.C.n068);b=b.n28a();switch(d.n1b5){case 0:e=[b[0],b[1],b[2]];g=[b[0],b[1]+k,b[2]];h=[b[0],b[1],b[2]+k];break;case 1:e=[b[0],b[1],b[2]];g=[b[0]+k,b[1],b[2]];h=[b[0],b[1],b[2]+k];
break;case 2:e=[b[0],b[1],b[2]];g=[b[0],b[1]+k,b[2]];h=[b[0]+k,b[1],b[2]];break}e=f.m4.n2b4(d.n261,e);g=f.m4.n2b4(d.n261,g);h=f.m4.n2b4(d.n261,h);c=(new f.n2a9([e,g,h])).n1fd(c);if(!c)throw new Error(f.C.n073);c=d.n21b(c);return[Math.round(c[0]/k),Math.round(c[1]/k),Math.round(c[2]/k)]},n0a3:function(){_(this.n1c9).invoke("defocus")},get2dExtentsInfo:function(){return _(this.n1c9).map(function(c){return y.extend({geometry:c},c.get2dextents(this.view))},this)},n270:function(c){var b=this,d,e,g;try{switch(c.type){case f.C.n1c4:c.geomsign.children?
f.n14d.n13f(c.geomsign,b,function(j){b.addGeometry(j)}):f.n18e.n13f(c.geomsign,b,function(j){b.addGeometry(j)});break;case f.C.n1cd:this.removeGeometry(f.Geometry.map[c.geomsign.uid]);break;case f.C.n156:f.Geometry.map[c.csg_uid].n22f(c.newcolor);break;case f.C.n166:e=new f.n200(this,this.view,c.cubeg_uid);_(c.cubes_added).each(function(j){e.n26d(new f.n10a(j))});this.addGeometry(e);break;case f.C.n16e:switch(c.mod_type){case "erase":_(c.mods).each(function(j){e=f.Geometry.map[j.cubeg_uid];_(j.cubes).each(function(p){d=
b.n297(p.position);e.n1c1(d)})});break;case "add":_(c.mods).each(function(j){e=f.Geometry.map[j.cubeg_uid];_(j.cubes).each(function(p){e.n26d(new f.n10a(p))})});break;case "color":_(c.mods).each(function(j){e=f.Geometry.map[j.cubeg_uid];_(j.cubes).each(function(p){e.n22f(e.n297(p.position),p.newcolor)})});break;case "adderase":_(c.erase_mods).each(function(j){e=f.Geometry.map[j.cubeg_uid];_(j.cubes).each(function(p){d=b.n297(p.position);e.n1c1(d)})});_(c.add_mods).each(function(j){e=f.Geometry.map[j.cubeg_uid];
_(j.cubes).each(function(p){e.n26d(new f.n10a(p))})});break}break;case f.C.n0da:f.Geometry.map[c.cubeg_uid].setSmoothness(c.newsmoothness,function(){y(b.view.canvas).trigger("model_changed",b.view.model)});break;case f.C.n275:c.geometry_uid?f.Geometry.map[c.geometry_uid].translate(c.xform,true):_(c.geometry_uid_list).each(function(j){f.Geometry.map[j].translate(c.xform,true)},this);break;case f.C.n16a:if(c.geometry_uid){g=f.Geometry.map[c.geometry_uid];if(c.xform.offsets){c.xform.offsets=g.n2a2Separately(c.xform.offsets);
g.mesh=null;g.smoothMeshCache=null}else g.rotate(c.xform,true)}else _(c.geometry_uid_list).each(function(j){f.Geometry.map[j].rotate(c.xform,true)},this);break;case f.C.op_objscale:c.geometry_uid?f.Geometry.map[c.geometry_uid].scale(c.xform,true):_(c.geometry_uid_list).each(function(j){f.Geometry.map[j].scale(c.xform,true)},this);break;case f.C.op_objshear:c.geometry_uid?f.Geometry.map[c.geometry_uid].shear(c.xform,true):_(c.geometry_uid_list).each(function(j){f.Geometry.map[j].shear(c.xform,true)},
this);break;case f.C.n27c:if(c.geometry_uid){g=f.Geometry.map[c.geometry_uid];if(c.xform.offsets){c.xform.offsets=g.n2a2Separately(c.xform.offsets);g.mesh=null;g.smoothMeshCache=null}else g.flip(c.xform)}else _(c.geometry_uid_list).each(function(j){f.Geometry.map[j].flip(c.xform)},this);break;case f.C.n1dc:g=f.Geometry.map[c.geometry_uid];g.n153(c.newmesh,c.newparams,c.newalignment);break;case f.C.n0cb:switch(c.mod_type){case "direction":this.view.n061(c.mod.newdirection,true);break;case "color":this.view.n08f(f.C.lighttype_directional,
c.mod.newcolor,true);break}break;case f.C.n0a6:switch(c.mod_type){case "position":this.view.n065(c.mod.newposition,true);break;case "color":this.view.n08f(f.C.lighttype_point,c.mod.newcolor,true);break}break;case f.C.n0bb:switch(c.mod_type){case "color":this.view.n08f(f.C.lighttype_ambient,c.mod.newcolor,true);break}break;case f.C.n082:this.view.n06b(c.newcolor,true);break;case f.C.n264:this.n109([this.n11c(_(c.children).map(function(j){return f.Geometry.map[j]}),c.group)],{r:0,g:0,b:255});break;
case f.C.n1b9:this.n109(this.n115(f.Geometry.map[c.group]));break;case f.C.n0a1:this.view.n08c(c.newprojection);break;case f.C.n0ef:b=this;_(c.delete_ops).each(function(j){j.type==f.C.n1cd&&b.removeGeometry(f.Geometry.map[j.geomsign.uid])});break}}catch(h){this.view.error(h)}},n20d:function(c){var b,d,e=this;try{switch(c.type){case f.C.n1c4:this.removeGeometry(f.Geometry.map[c.geomsign.uid]);break;case f.C.n1cd:c.geomsign.children?f.n14d.n13f(c.geomsign,e,function(h){e.addGeometry(h)}):f.n18e.n13f(c.geomsign,
e,function(h){e.addGeometry(h)});break;case f.C.n156:f.Geometry.map[c.csg_uid].n22f(c.oldcolor);break;case f.C.n166:this.removeGeometry(f.Geometry.map[c.cubeg_uid]);break;case f.C.n16e:switch(c.mod_type){case "erase":_(c.mods).each(function(h){cubegroup=f.Geometry.map[h.cubeg_uid];_(h.cubes).each(function(j){cubegroup.n26d(new f.n10a(j))})});break;case "add":_(c.mods).each(function(h){cubegroup=f.Geometry.map[h.cubeg_uid];_(h.cubes).each(function(j){b=e.n297(j.position);cubegroup.n1c1(b)})});break;
case "color":_(c.mods).each(function(h){cubegroup=f.Geometry.map[h.cubeg_uid];_(h.cubes).each(function(j){cubegroup.n22f(cubegroup.n297(j.position),j.oldcolor)})});break;case "adderase":_(c.add_mods).each(function(h){cubegroup=f.Geometry.map[h.cubeg_uid];_(h.cubes).each(function(j){b=e.n297(j.position);cubegroup.n1c1(b)})});_(c.erase_mods).each(function(h){cubegroup=f.Geometry.map[h.cubeg_uid];_(h.cubes).each(function(j){cubegroup.n26d(new f.n10a(j))})});break}break;case f.C.n0da:f.Geometry.map[c.cubeg_uid].setSmoothness(c.oldsmoothness,
function(){y(e.view.canvas).trigger("model_changed",e.view.model)});break;case f.C.n275:c.geometry_uid?f.Geometry.map[c.geometry_uid].undoTranslate(c.xform):_(c.geometry_uid_list).each(function(h){f.Geometry.map[h].undoTranslate()},this);break;case f.C.n16a:if(c.geometry_uid){d=f.Geometry.map[c.geometry_uid];if(c.xform.offsets){c.xform.offsets=d.n2a2Separately(c.xform.offsets);d.mesh=null;d.smoothMeshCache=null}else d.undoRotate()}else _(c.geometry_uid_list).each(function(h){f.Geometry.map[h].undoRotate()},
this);break;case f.C.op_objscale:c.geometry_uid?f.Geometry.map[c.geometry_uid].undoScale():_(c.geometry_uid_list).each(function(h){f.Geometry.map[h].undoScale()},this);break;case f.C.op_objshear:c.geometry_uid?f.Geometry.map[c.geometry_uid].undoShear():_(c.geometry_uid_list).each(function(h){f.Geometry.map[h].undoShear()},this);break;case f.C.n27c:if(c.geometry_uid){d=f.Geometry.map[c.geometry_uid];if(c.xform.offsets){c.xform.offsets=d.n2a2Separately(c.xform.offsets);d.mesh=null;d.smoothMeshCache=
null}else d.undoFlip()}else _(c.geometry_uid_list).each(function(h){f.Geometry.map[h].undoFlip()},this);break;case f.C.n1dc:d=f.Geometry.map[c.geometry_uid];d.n153(c.oldmesh,c.oldparams,c.oldalignment);break;case f.C.n0cb:switch(c.mod_type){case "direction":this.view.n061(c.mod.olddirection,true);break;case "color":this.view.n08f(f.C.lighttype_directional,c.mod.oldcolor,true);break}break;case f.C.n0a6:switch(c.mod_type){case "position":this.view.n065(c.mod.oldposition,true);break;case "color":this.view.n08f(f.C.lighttype_point,
c.mod.oldcolor,true);break}break;case f.C.n0bb:switch(c.mod_type){case "color":this.view.n08f(f.C.lighttype_ambient,c.mod.oldcolor,true);break}break;case f.C.n082:this.view.n06b(c.oldcolor,true);break;case f.C.n264:this.n109(this.n115(f.Geometry.map[c.group]));break;case f.C.n1b9:this.n109([this.n11c(_(c.children).map(function(h){return f.Geometry.map[h]}),c.group)],{r:0,g:0,b:255});break;case f.C.n0a1:this.view.n08c(c.oldprojection);break;case f.C.n0ef:_(c.delete_ops).each(function(h){if(h.type==
f.C.n1cd)h.geomsign.children?f.n14d.n13f(h.geomsign,e,function(j){e.addGeometry(j)}):f.n18e.n13f(h.geomsign,e,function(j){e.addGeometry(j)})});break}}catch(g){this.view.error(g)}},getOpqDump:function(){var c="";c+="n243: "+this.n243+"<br/>";c+="numops: "+this.numops+"<br/>";c+="n217: "+this.n217+"<br/>";return c},do_:function(c){this.n278=true;this.view._jq.trigger("op_done");this.view._jq.trigger("undo_stack_populated");this.opq[this.n243]=c;this.numops++;this.n243=(this.n243+1)%f.C.n1d6;this.n217=
0;this.view._jq.trigger("redo_stack_finished")},undo:function(){if(this.numops!==0){this.n243--;if(this.n243<0)this.n243=f.C.n1d6-1;if(this.opq[this.n243]){this.n20d(this.opq[this.n243]);this.view._jq.trigger("redo_stack_populated");this.n217++;this.numops--;if(this.n217===f.C.n1d6)this.numops=0;this.numops===0&&this.view._jq.trigger("undo_stack_finished")}else this.n243=(this.n243+1)%f.C.n1d6}},redo:function(){if(this.n217!==0){this.n270(this.opq[this.n243]);this.n243=(this.n243+1)%f.C.n1d6;this.n217--;
this.numops++;this.view._jq.trigger("undo_stack_populated");this.n217===0&&this.view._jq.trigger("redo_stack_finished")}}});f.n0ed=n})(jQuery);
(function(y){var f=y.tin;y=f.n0ed.extend({prepare:function(k){var n=-1,c=this.n1c9,b=function(){n++;if(n<c.length)c[n].prepare2D(b);else k&&k()};b()},draw:function(k,n){var c=[];_(this.n1c9).each(function(d){d.mesh&&_(d.mesh.faces).each(function(e){e.n202()||c.push(e)},this)},this);if(k){var b=new f.Mesh(this.view);k&&!k.isGeometry&&k.n187(b);_(b.faces).each(function(d){d.n202()||c.push(d)},this);k&&k.isGeometry&&_(k.mesh.faces).each(function(d){c.push(d)},this)}c.sort(function(d,e){return d.pcentroid[2]-
e.pcentroid[2]});_(c).each(function(d){var e=[];_(d.n269).map(function(g){g=f.n2c0.n17f(this.view.project(d.n191.vertices[g]),this.view);e.push(g)},this);f.n2c0.n283({points:e,style:d.n185?"#000":d.n112(this.view),type:d.n185?f.C.n0ce:f.C.n104})},this);n&&_(n.mesh.faces).each(function(d){var e=[];_(d.n269).map(function(g){g=f.n2c0.n17f(this.view.project(d.n191.vertices[g]),this.view);e.push(g)},this);f.n2c0.n283({points:e,style:"#000",type:f.C.n0ce})},this);f.n2c0.n20a()}});f.n0dd=y})(jQuery);
(function(y){var f=y.tin;y=f.n0ed.extend({constructor:function(){this.base()},prepare:function(k){_(this.n1c9).invoke("prepare3D",_.after(this.n1c9.length,k))},n109:function(k,n){var c=this;_(k).invoke("focus",{r:255,g:0,b:0},8);this.view.draw();_.delay(function(){_(k).each(function(b){n?b.focus(n):b.defocus()});c.view.draw()},300)},draw:function(){function k(e){return!e.isHidden&&(!e.isCSG||e.getColor().a==100)&&!e.focusColor}function n(e){return!e.isHidden&&e.isCSG&&e.getColor().a<100&&!e.focusColor}
function c(e){return!e.isHidden&&(!e.isCSG||e.getColor().a==100)&&!!e.focusColor}function b(e){return!e.isHidden&&e.isCSG&&e.getColor().a<100&&!!e.focusColor}var d=_(this.n1c9).any(function(e){return!!e.focusColor});f.n2be.n15b(true);f.n2be.n23b(false);_(this.n1c9).chain().select(k).invoke("draw",this.view);f.n2be.n15b(false);f.n2be.n23b(true);_(this.n1c9).chain().select(n).invoke("draw",this.view);d&&f.n2be.enableStencil();f.n2be.n15b(true);f.n2be.n23b(false);_(this.n1c9).chain().select(c).invoke("draw",
this.view);f.n2be.n15b(false);f.n2be.n23b(true);_(this.n1c9).chain().select(b).invoke("draw",this.view);f.n2be.n15b(true);f.n2be.n23b(false);if(d){f.n2be.setStencil();_(this.n1c9).chain().select(function(e){return!!e.focusColor}).invoke("drawWireframe",this.view);f.n2be.disableStencil()}}});f.n0d2=y})(jQuery);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){var f;f=typeof window!=="undefined"?y.tin:require("./declare").tin;f.CC={n09c:function(k){var n=[0,0,0];k=k.n242;for(var c=0;c<4;c++){n=f.v3.add(n,k.vertex.n2ad);k=k.next}return[n[0]/4,n[1]/4,n[2]/4]},n0a0:function(k){var n=[0,0,0],c=k.vertex;n=f.v3.add(n,c.n2ad);c=k.pair.vertex;n=f.v3.add(n,c.n2ad);n=f.v3.add(n,k.face.n180);n=f.v3.add(n,k.pair.face.n180);return[n[0]/4,n[1]/4,n[2]/4]},n083:function(k){for(var n=[0,0,0],c=k.n242,b=c,d=0;;){n=f.v3.add(n,c.face.n180);c=c.pair.next;d++;if(c===
b)break}var e=[n[0]/d,n[1]/d,n[2]/d];n=[0,0,0];b=c=k.n242;for(var g=k.n2ad;;){var h=c.next.vertex;h=h.n2ad;h=f.v3.mul(f.v3.add(g,h),0.5);n=f.v3.add(n,h);c=c.pair.next;if(c===b)break}n=[n[0]/d,n[1]/d,n[2]/d];k=k.n2ad;return[(e[0]+2*n[0]+(d-3)*k[0])/d,(e[1]+2*n[1]+(d-3)*k[1])/d,(e[2]+2*n[2]+(d-3)*k[2])/d]}}})(framework);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){function f(b,d,e,g){this.face=b;this.next=d;this.pair=e;this.vertex=g}function k(b,d){this.n242=b;this.rgba=d}function n(b,d){this.n2ad=b;this.n242=d;this.n274=[];this.normal_count=[]}var c;c=typeof window!=="undefined"?y.tin:require("./declare").tin;k.prototype.n103=function(){if(!this.normal){var b=this.n242,d=[];do{d.push(b.vertex.n2ad);b=b.next}while(b!=this.n242);b=c.v3.sub(d[1],d[0]);d=c.v3.sub(d[2],d[1]);this.normal=c.v3.normalize(c.v3.cross(b,d))}return this.normal};c.HE={n246:f,
Face:k,Vertex:n}})(framework);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){function f(){}var k;if(typeof window==="undefined"){_=require("../../../libs/underscore")._;k=require("./declare").tin}else k=y.tin;var n=Math.cos(20*Math.PI/180),c=1.001;f.prototype={};f.n11d=function(b){function d(B,m){return B.r==m.r&&B.g==m.g&&B.b==m.b&&B.a==m.a}function e(B,m){B=k.v3.dot(B,m);return B>=n&&B<=c}function g(B,m){var A=m.xmax-m.xmin,r=m.ymax-m.ymin;_(B).each(function(v){v.texn2ad=[Math.abs(v.n2ad[0]-m.xmin)/A,Math.abs(v.n2ad[1]-m.ymin)/r]})}function h(B,m){var A=m.ymax-
m.ymin,r=m.zmax-m.zmin;_(B).each(function(v){v.texn2ad=[Math.abs(v.n2ad[1]-m.ymin)/A,Math.abs(v.n2ad[2]-m.zmin)/r]})}function j(B,m){var A=m.xmax-m.xmin,r=m.zmax-m.zmin;_(B).each(function(v){v.texn2ad=[Math.abs(v.n2ad[0]-m.xmin)/A,Math.abs(v.n2ad[2]-m.zmin)/r]})}for(var p={},o=1,s;;){s=null;i=0;for(l=b.n207.length;i<l;i++){var E=b.n207[i];if(!E.group_id){s=E;break}}if(!s)break;s.group_id=o;o+=1;E=0;queue=new Queue;for(queue.enqueue(s);!queue.isEmpty();){s=queue.dequeue();if(p[s.group_id])p[s.group_id].push(s);
else p[s.group_id]=[s];var w=s.n242;do{neighbour=w.pair.face;if(d(neighbour.rgba,s.rgba)&&e(neighbour.n103(),s.n103()))if(!neighbour.group_id&&E<100){neighbour.group_id=s.group_id;E++;queue.enqueue(neighbour)}w=w.next}while(w!=s.n242)}}var D=[];_(p).each(function(B,m){function A(F){var G=k.v3.mul(F.n274[m],1/F.normal_count[m]);return[F.n2ad,F.texn2ad,G]}var r={},v=[],H=[];_(B).each(function(F){var G=F.n103(),K=[],I=F.n242;do{var J=k.n29e(I.vertex.n2ad);if(r[J]===undefined){r[J]=v.length;v.push(I.vertex);
I.vertex.n274[m]=[0,0,0];I.vertex.normal_count[m]=0}K.push(r[J]);I.vertex.n274[m]=k.v3.add(I.vertex.n274[m],G);I.vertex.normal_count[m]+=1;I=I.next}while(I!=F.n242);H.push([K[0],K[1],K[2]]);H.push([K[0],K[2],K[3]])});var t={xmin:Infinity,xmax:-Infinity,ymin:Infinity,ymax:-Infinity,zmin:Infinity,zmax:-Infinity};_(v).each(function(F){t.xmin=Math.min(t.xmin,F.n2ad[0]);t.ymin=Math.min(t.ymin,F.n2ad[1]);t.zmin=Math.min(t.zmin,F.n2ad[2]);t.xmax=Math.max(t.xmax,F.n2ad[0]);t.ymax=Math.max(t.ymax,F.n2ad[1]);
t.zmax=Math.max(t.zmax,F.n2ad[2])});var u=Math.abs(t.xmax-t.xmin),C=Math.abs(t.ymax-t.ymin),q=Math.abs(t.zmax-t.zmin);if(u<C)q<u?g(v,t):h(v,t);else q<C?g(v,t):j(v,t);D.push({vertices:_(v).map(A),faces:H,rgba:B[0].rgba})});return D};k.autotex=f})(framework);
(function(y){function f(b){b.sort(function(d,e){return d[0]-e[0]||d[1]-e[1]||d[2]-e[2]});return n.n29e(b[0])+"_"+n.n29e(b[1])}function k(b){b=b||{};if(!b.forceSync&&typeof Worker!=="undefined"){this.ccworker=new Worker(n.C.ccworker_path);var d=this;this.ccworker.onmessage=function(e){e=JSON.parse(e.data);if(e.type==="debug")b.log("CCW debug: "+e.msg);else{if(e.type==="error"){b.log("CCW failed: "+e.msg);d.n27d()}else d.quads=e;d.n199.call(d.n0c2,d.quads)}}}this.reset()}var n;if(typeof window==="undefined"){_=
require("../../../libs/underscore")._;Base=require("../../../libs/base").Base;n=require("./declare").tin;require("./hedge");require("./catmull")}else n=y.tin;var c=n.C.cube_size;k.prototype={reset:function(){this.heData={};this.data={};this.n281={};this.quads=[]},prepare:function(b,d){this.data[b]={n2a4:{},n28c:{},n207:[],n212:[]};this.n281[b]={smoothness:d,n2a4:{},faces:[]}},setn246Data:function(b,d){this.heData[b]=d},n204:function(b,d){var e=n.n29e(d);if(this.n281[b].n2a4[e]===undefined)this.n281[b].n2a4[e]=
n.v3.mul(d,1/c)},n27b:function(b,d,e){this.n281[b].faces.push({n269:d,rgba:e})},n13a:function(b){var d,e,g,h={};for(var j in b){var p={smoothness:b[j].smoothness,n2a4:{},n28c:{},n207:[],n212:[]};for(g in b[j].n2a4)p.n2a4[g]=new n.HE.Vertex(b[j].n2a4[g]);d=0;for(e=b[j].faces.length;d<e;d++){var o,s=b[j].faces[d],E=new n.HE.Face;E.rgba=s.rgba;for(o=0;o<4;o++){var w=p.n2a4[n.n29e(s.n269[o])],D=new n.HE.n246(E,null,null,w);w.n242=D;p.n212.push(D)}s=p.n212.length;for(o=s-4;o<s;o++){p.n212[o].next=o===
s-1?p.n212[s-4]:p.n212[o+1];g=f([p.n212[o].vertex.n2ad,p.n212[o].next.vertex.n2ad]);if(p.n28c[g]===undefined)p.n28c[g]=p.n212[o];else{p.n212[o].pair=p.n28c[g];p.n28c[g].pair=p.n212[o];delete p.n28c[g]}}E.n242=p.n212[s-1];p.n207.push(E)}h[j]=p}return h},run:function(b,d,e){this.for3D=e;if(this.ccworker){this.runAsync();this.n199=b;this.n0c2=d}else{this.n27d();b.call(d,this.quads)}},runAsync:function(){this.ccworker.postMessage(JSON.stringify({n281:this.n281,for3D:this.for3D}))},n27d:function(){this.data=
this.n13a(this.n281);this.quads={};for(var b in this.data){var d,e=this.data[b];this.quads[b]=[];for(d=0;d<this.data[b].smoothness;d++)this.iterate(b);if(this.for3D)this.quads[b]=n.autotex.n11d(e);else{d=0;for(l=e.n207.length;d<l;d++){for(var g=e.n207[d],h=g.n242,j=[],p=0;p<4;p++){j.push(h.vertex.n2ad);h=h.next}this.quads[b].push({vertices:j,rgba:g.rgba})}}}},iterate:function(b){var d,e,g,h,j={},p={},o=[],s=[];b=this.data[b];d=0;for(e=b.n207.length;d<e;d++){h=b.n207[d];h.n180=n.CC.n09c(h)}d=0;for(e=
b.n212.length;d<e;d++){h=b.n212[d];h.n172=h.pair.n172?h.pair.n172:n.CC.n0a0(h)}e={};for(g in b.n2a4){d=b.n2a4[g];if(d.n242)e[g]=d}b.n2a4=e;for(g in b.n2a4){d=b.n2a4[g];d.n219=n.CC.n083(d);j[n.n29e(d.n219)]=new n.HE.Vertex(d.n219)}d=0;for(e=b.n207.length;d<e;d++){h=b.n207[d];g=n.n29e(h.n180);var E=new n.HE.Vertex(h.n180);j[g]=E;for(var w=h.n242,D=0;D<4;D++){var B=new n.HE.Face;B.rgba=h.rgba;g=n.n29e(w.n172);var m=j[g];if(!m){m=new n.HE.Vertex(w.n172);j[g]=m}g=n.n29e(w.next.n172);var A=j[g];if(!A){A=
new n.HE.Vertex(w.next.n172);j[g]=A}g=j[n.n29e(w.next.vertex.n219)];var r=new n.HE.n246(B,null,null,E),v=new n.HE.n246(B,null,null,m),H=new n.HE.n246(B,null,null,g),t=new n.HE.n246(B,null,null,A);r.next=v;v.next=H;H.next=t;t.next=r;E.n242=r;m.n242=v;g.n242=H;A.n242=t;m=B.n242=r;for(A=0;A<4;A++){g=f([m.vertex.n2ad,m.next.vertex.n2ad]);if(p[g]===undefined)p[g]=m;else{m.pair=p[g];p[g].pair=m;delete p[g]}m=m.next}o.push(B);s.push(r);s.push(v);s.push(H);s.push(t);w=w.next}}delete b.n207;delete b.n212;
delete b.n2a4;b.n207=o;b.n212=s;b.n2a4=j;b.n28c=p}};n.n250=k})(framework);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){var f;if(typeof window==="undefined"){_=require("../../../libs/underscore")._;Base=require("../../../libs/base").Base;f=require("./declare").tin}else f=y.tin;var k=f.C.cube_size,n={position:[0,0,0],rgba:{r:255,g:0,b:0,a:100},offset:[0,0,0],isVirtual:false},c=Base.extend({constructor:function(b){_.extend(this,n,b);this.n1b7=[]},toString:function(){return"pos: "+this.position+", rgba: "+JSON.stringify(this.rgba)+", offset: "+this.offset+", isVirtual: "+this.isVirtual},moveTo:function(b){this.position=
b},translate:function(b){this.position=f.v3.add(this.position,b)},n28a:function(){return f.v3.mul(this.position,k)},n1f8:function(b){this.offset=b},n21e:function(b){var d=f.v3.add(this.position,this.offset);return f.v3.add(f.v3.mul(d,k),f.v3.mul(c.vertices[b],k/2))},getSidePositions:function(){var b=this.position;return[[b[0],b[1],b[2]-1],[b[0],b[1],b[2]+1],[b[0],b[1]+1,b[2]],[b[0],b[1]-1,b[2]],[b[0]+1,b[1],b[2]],[b[0]-1,b[1],b[2]]]},n22f:function(b){this.rgba={r:b.r,g:b.g,b:b.b,a:b.a}},fade:function(){this.rgba.a=
50},unfade:function(){this.rgba.a=100},getColor:function(){return{r:this.rgba.r,g:this.rgba.g,b:this.rgba.b,a:this.rgba.a}}});c.vertices=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]];c.faces=[[3,2,1,0],[4,5,6,7],[7,6,2,3],[5,4,0,1],[6,5,1,2],[4,7,3,0]];c.n274=[[0,0,-1],[0,0,1],[0,1,0],[0,-1,0],[1,0,0],[-1,0,0]];c.n105=function(b){return[1,0,3,2,5,4][b]};c.deltas=[[1,0,0],[-1,0,0],[0,+1,0],[0,-1,0],[0,0,1],[0,0,-1]];f.n24c=c})(framework);
(function(y){var f=y.tin,k=f.n24c.extend({clone:function(){return new k({position:this.position,rgba:{r:this.rgba.r,g:this.rgba.g,b:this.rgba.b,a:this.rgba.a}})},n093:function(n,c){for(var b=[],d,e=0;e<6;e++){var g=f.n24c.faces[e];if(d=f.n0b8(n.o,n.d,c.project(this.n21e(g[0])),c.project(this.n21e(g[1])),c.project(this.n21e(g[2]))))b.push({idx:e,d:f.v3.length(f.v3.sub(d,n.o))});else(d=f.n0b8(n.o,n.d,c.project(this.n21e(g[0])),c.project(this.n21e(g[2])),c.project(this.n21e(g[3]))))&&b.push({idx:e,d:f.v3.length(f.v3.sub(d,
n.o))})}b.sort(function(h,j){return h.d-j.d});return b.length>0?b[0].idx:-1},intersects:function(n,c){for(var b=0,d=f.n24c.faces.length;b<d;b++){var e=_(f.n24c.faces[b]).map(function(h){return c.project(this.n21e(h))},this),g=[e[0],e[1],e[2]];e=[e[0],e[2],e[3]];if(f.n0b8(n.o,n.d,g[0],g[1],g[2])||f.n0b8(n.o,n.d,e[0],e[1],e[2]))return true}return false}});f.n10a=k})(jQuery);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){function f(){return(new Date).getTime()+""+Math.round(Math.random()*1E3)}var k;if(typeof window!=="undefined")k=y.tin;else{_=require("../../../libs/underscore")._;Base=require("../../../libs/base").Base;k=require("./declare").tin;require("./vbostub")}var n=k.C.cube_size;n197=0;var c=Base.extend({constructor:function(b,d){this.mesh=b;this.isolated=true;this.form=k.C.model_form_solid;this.isHidden=this.isFaded=false;this.uid=_.isUndefined(d)?f():d;c.map[this.uid]=this},toString:function(){return"UID : "+
this.uid},setParent:function(b){this.parent=b},contains:function(b,d){return _(b).any(function(e){return _.isEqual(e.position,d)})},n1f8:function(){throw new Error(k.C.exception_not_implemented);},translate:function(){throw new Error(k.C.exception_not_implemented);},rotate:function(){throw new Error(k.C.exception_not_implemented);},flip:function(){throw new Error(k.C.exception_not_implemented);},findIntersection:function(b,d,e,g){return _(b).chain().select(function(h){if(!h)return false;h=g.project(h.n28a());
var j=k.v3.dot(d.d,k.v3.sub(h,d.o));j/=k.v3.n13d(d.d);j=k.v3.add(d.o,k.v3.mul(d.d,j));h=k.v3.sub(h,j);return k.v3.length(h)<e}).select(function(h){return h.intersects(d,g)}).max(function(h){return g.project(h.n28a())[2]}).value()},setForm:function(b){var d=this.form;this.form=b;d!=b&&_(this.mesh.faces).each(function(e){e.n185=this.form==k.C.model_form_wireframe},this)},n0db:function(){this.n1a9.view._jq.trigger("current_geom_extents",this.mesh.extents)},_prepare3D:function(b){b&&b()},prepare3D:function(b){this._prepare3D(b)},
prepare2D:function(b){this._prepare2D(b)},_prepare2D:function(b){this.isFaded?this.mesh.n1d7():this.mesh.n162();b&&b()},focus:function(b,d){this.focusColor=b;this.focusThickness=d||4},defocus:function(){this.focusColor=null},drawWireframe:function(b){var d=this.mesh.copy();d.n081();k.n2be.n174(this.focusThickness);this.mesh.surfaces?_(d.surfaces).each(function(e){k.n2bf.drawLines(e.n228,this.focusColor,b)},this):k.n2bf.drawLines(d.n228,this.focusColor,this.view);k.n2be.n174(1)},draw:function(b){if(this.mesh)if(this.mesh.surfaces)_(this.mesh.surfaces).each(function(d){k.n2bf.draw(d.n228,
b)},this);else this.mesh.n1ab&&_(this.mesh.n1ab).each(function(d){k.n2bf.drawColored(d.n228,b)},this)},n07c:function(b,d){try{_(b).each(function(g){if(g){g=this.n1a9.n1c9At(k.v3.add(g.position,d));if(_(g).any(function(h){return h.uid!==this.uid},this))throw"INTERSECTS";}},this)}catch(e){if(e==="INTERSECTS")return true;else throw e;}return false},get2dextents:function(b,d){var e=-Infinity,g=Infinity,h=-Infinity,j=Infinity;_([[(b.xmin-0.5)*n,(b.ymin-0.5)*n,(b.zmin-0.5)*n],[(b.xmax+0.5)*n,(b.ymin-0.5)*
n,(b.zmin-0.5)*n],[(b.xmax+0.5)*n,(b.ymax+0.5)*n,(b.zmin-0.5)*n],[(b.xmin-0.5)*n,(b.ymax+0.5)*n,(b.zmin-0.5)*n],[(b.xmin-0.5)*n,(b.ymin-0.5)*n,(b.zmax+0.5)*n],[(b.xmax+0.5)*n,(b.ymin-0.5)*n,(b.zmax+0.5)*n],[(b.xmax+0.5)*n,(b.ymax+0.5)*n,(b.zmax+0.5)*n],[(b.xmin-0.5)*n,(b.ymax+0.5)*n,(b.zmax+0.5)*n]]).chain().map(function(p){return k.n2c0.n17f(d.project(p),d)},this).each(function(p){e=Math.max(e,p[0]);g=Math.min(g,p[0]);h=Math.max(h,p[1]);j=Math.min(j,p[1])},this);return{xmax:e,xmin:g,ymax:h,ymin:j}}});
c.map={};k.Geometry=c})(framework);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){var f;if(typeof window!=="undefined")f=y.tin;else{_=require("../../../libs/underscore")._;f=require("./declare").tin;require("./geometry");require("./mesh")}var k=f.C.cube_size,n=f.C.center_align,c=f.C.min_align,b=f.C.max_align,d=f.Geometry.extend({constructor:function(e,g,h,j,p,o,s){if(typeof e=="string")if(o){this.alignment=o.alignment;this.base(o.mesh,s)}else{console.error("XXX");this.base(null,s)}else throw Error("Old template format");if(this.mesh){this.origmesh=this.mesh.copy();
this.mesh.n22f(j)}this.type=e;this.params=p;this.color=j;this.n1a9=g;this.accoffset=[0,0,0];this.transforms=[];this.view=h;this.isCSG=true;this.geomType=f.C.n14e},isAbstractCSG:function(){return this.isCSG&&typeof this.type=="string"&&!this.mesh},n153:function(e,g,h){this.origmesh=e;this.mesh=e.copy();this.mesh.n0fd();this.mesh.n22f(this.color);this.params=g;this.voxels=null;this.alignment=h;this.ren131s();this.view.draw()},ren131s:function(){var e=this.transforms;this.transforms=[];_(e).each(this.n131,
this)},dumpTransforms:function(){return _(this.transforms).map(function(e){var g=e.type;if(e.delta)g+=": "+e.delta;return g}).join(" | ")},getCubes:function(){return this.voxels},voxelize:function(e,g,h){function j(w,D,B){var m=[],A=B-D;A=f.precise(A);if(w==n){m.push(D+A/2);w=Math.ceil(f.precise(A/2-k/2)/k);_(w).times(function(r){m.push(D+A/2+(r+1)*k)});_(w).times(function(r){m.push(D+A/2-(r+1)*k)})}else if(w==c){w=Math.ceil(f.precise(A/k));_(w).times(function(r){m.push(D+k/2+r*k)})}else if(w==b){w=
Math.ceil(f.precise(A/k));_(w).times(function(r){m.push(B-k/2-r*k)})}return m}function p(w,D){var B=Math.floor(f.precise(w+k/2)/k);w=Math.ceil(f.precise(D-k/2)/k)-B+1;var m=[];_(w).times(function(A){m.push((B+A)*k)});return m}var o,s;if(h){h=p(e.extents.xmin,e.extents.xmax);o=p(e.extents.ymin,e.extents.ymax);s=p(e.extents.zmin,e.extents.zmax)}else{h=j(this.alignment.x,e.extents.xmin,e.extents.xmax);o=j(this.alignment.y,e.extents.ymin,e.extents.ymax);s=j(this.alignment.z,e.extents.zmin,e.extents.zmax)}if(g)this.dextents=
{xmin:Math.round(Math.min.apply(Math,h)/k),ymin:Math.round(Math.min.apply(Math,o)/k),zmin:Math.round(Math.min.apply(Math,s)/k),xmax:Math.round(Math.max.apply(Math,h)/k),ymax:Math.round(Math.max.apply(Math,o)/k),zmax:Math.round(Math.max.apply(Math,s)/k)};var E=[];_(h).each(function(w){_(o).each(function(D){_(s).each(function(B){E.push(new f.n10a({position:[Math.round(w/k),Math.round(D/k),Math.round(B/k)],isVirtual:true,group:this}))},this)},this)},this);return E},getBase:function(e){e=e||this.mesh;
var g=this.alignment,h=e.extents.xmin,j=e.extents.ymin,p=e.extents.zmin,o=e.extents.xmax,s=e.extents.ymax;e=e.extents.zmax;return[g.x==n?(h+o)/2:g.x==c?h:o,g.y==n?(j+s)/2:g.y==c?j:s,g.z==n?(p+e)/2:g.z==c?p:e]},n088:function(){var e=this.alignment;return[e.x==n?0:e.x==c?-0.5:0.5,e.y==n?0:e.y==c?-0.5:0.5,e.z==n?0:e.z==c?-0.5:0.5]},n11f:function(){return this.mesh.n11f()},n1d0:function(e){e=f.v3.add(e,this.n088());e=f.v3.mul(e,k);this.mesh.translate(f.v3.sub(e,this.getBase()),true);this.voxels=this.voxelize(this.mesh,
true)},n22f:function(e){this.mesh.n22f(e);this.color=e},getColor:function(){return this.color},findIntersection:function(e,g,h){return this.base(this.voxels,e,g,h)},n297:function(e){return _(this.voxels).select(function(g){return _.isEqual(g.position,e)})[0]},n1c1:function(){throw new Error(f.C.exception_not_implemented);},contains:function(e){var g=this.dextents;return e[0]>=g.xmin&&e[0]<=g.xmax&&e[1]>=g.ymin&&e[1]<=g.ymax&&e[2]>=g.zmin&&e[2]<=g.zmax},transform:function(){},n186:function(){var e=
this.mesh.extents;return[(e.xmin+e.xmax)/2,(e.ymin+e.ymax)/2,(e.zmin+e.zmax)/2]},getOffset:function(){return this.accoffset},addOffset:function(e){this.accoffset=f.v3.add(this.accoffset,f.v3.mul(e,k));this.mesh.translate(f.v3.mul(e,k),true);this.voxels=this.voxelize(this.mesh,true,true)},n1f8:function(e){var g=f.v3.sub(f.v3.mul(e,k),this.accoffset);this.accoffset=f.v3.mul(e,k);this.mesh.translate(g,true);this.voxels=this.voxelize(this.mesh,true,true)},alignToGrid:function(){},n131:function(e){this.isStackedTransform=
true;switch(e.type){case f.C.xform_translate:this.translate(e);break;case f.C.xform_rotate:this.rotate(e,false);break;case f.C.n1ac:this.scale(e,false);break;case f.C.n1c0:this.flip(e);break;case f.C.xform_shear:this.shear(e,false);break}this.isStackedTransform=false},undoTranslate:function(e){var g=_.clone(this.transforms.pop());g.delta=f.v3.mul(g.delta,-1);this.translateBase(g,true,e)},translate:function(e,g,h){this.translateBase(e,g,h);this.transforms.push(e)},translateBase:function(e,g,h){function j(){var D=
(new Date).getTime();if(D<E){D=f.ease((D-s)/p);o.mesh.translate(f.v3.mul(w,-k));w=f.v3.mul(e.delta,D);o.mesh.translate(f.v3.mul(w,k),true);o.view.draw();requestAnimationFrame(j)}else{f.v3.isZero(w)||o.mesh.translate(f.v3.mul(w,-k));if(e.v){o.mesh.translate(f.v3.mul(e.delta,k),true);o.voxels=o.voxelize(o.mesh,true,true)}else{D=[0,0,0];if(o.voxels)D=o.voxels[0].position;D=f.v3.add(D,e.delta);o.n1d0(D)}h&&h();o.isStackedTransform||o.view.draw()}}var p=g?300:0,o=this,s=g=(new Date).getTime(),E=g+p,w=
[0,0,0];j()},undoRotate:function(e){xform=_.clone(this.transforms.pop());xform.clockwise=!xform.clockwise;this.rotateBase(xform,true,e)},rotate:function(e,g,h){this.rotateBase(e,g,h);this.transforms.push(e)},rotateBase:function(e,g,h){function j(){var v=(new Date).getTime();if(v<D){v=f.ease((v-w)/E);var H=v*B-r;r=v*B;A.mesh.translate(m);v=f.m4.rotate(H,p,f.m4.I);A.mesh.transform(v,true,true);A.mesh.translate(s,true);A.view.draw();requestAnimationFrame(j)}else{A.mesh.translate(m);v=f.m4.rotate(B-r,
p,f.m4.I);A.mesh.transform(v,true,true);A.mesh.translate(s,true);if(e.v)A.voxels=A.voxelize(A.mesh,true,true);else{if(!A.voxels)A.voxels=A.voxelize(A.mesh,true);A.n1d0(A.voxels[0].position)}h&&h();A.view.draw()}}if(_.isUndefined(e.angle))e.angle=90;var p=[0,0,0];p[e.pivotAxis]=1;var o=this.mesh.extents,s=[(o.xmin+o.xmax)/2,(o.ymin+o.ymax)/2,(o.zmin+o.zmax)/2];if(e.axisOffset)s=f.v3.mul(e.axisOffset,k);else if(e.axisMemory)s=f.v3.mul(e.axisMemory,k);else e.axisMemory=f.v3.mul(s,1/k);var E=g?300:0;
var w=g=(new Date).getTime(),D=g+E,B=e.clockwise?-Math.PI*e.angle/180:Math.PI*e.angle/180,m=[-s[0],-s[1],-s[2]],A=this,r=0;j()},undoFlip:function(){var e=this.transforms.pop();this.mesh.flip(e.flipAxis,e.midpoint,true);this.voxels=this.voxelize(this.mesh,true,true)},flip:function(e){this.mesh.flip(e.flipAxis,e.midpoint,true);if(e.v)this.voxels=this.voxelize(this.mesh,true,true);else{if(!this.voxels)this.voxels=this.voxelize(this.mesh,true);this.n1d0(this.voxels[0].position)}this.transforms.push(e)},
undoScale:function(e){var g=_.clone(this.transforms.pop());g.scaleX=1/g.scaleX;g.scaleY=1/g.scaleY;g.scaleZ=1/g.scaleZ;this.scaleBase(g,true,e)},scale:function(e,g,h){this.scaleBase(e,g,h);this.transforms.push(e)},scaleBase:function(e,g,h){function j(v){return Math.log(v)/Math.LN10}function p(){var v=(new Date).getTime();if(v<D){v=f.ease((v-w)/E);if(v>0){B.mesh.translate(f.v3.mul(s,-1));var H=f.m4.scale(1/m,1/A,1/r,f.m4.I);B.mesh.transform(H,false,false);B.mesh.translate(s);m=Math.pow(10,v*j(e.scaleX));
A=Math.pow(10,v*j(e.scaleY));r=Math.pow(10,v*j(e.scaleZ));B.mesh.translate(f.v3.mul(s,-1));H=f.m4.scale(m,A,r,f.m4.I);B.mesh.transform(H,true,false);B.mesh.translate(s,true);B.view.draw()}requestAnimationFrame(p)}else{B.mesh.translate(f.v3.mul(s,-1));H=f.m4.scale(1/m,1/A,1/r,f.m4.I);B.mesh.transform(H,false,false);B.mesh.translate(s);B.mesh.translate(f.v3.mul(s,-1));H=f.m4.scale(e.scaleX,e.scaleY,e.scaleZ,f.m4.I);B.mesh.transform(H,true,false);B.mesh.translate(s,true);B.voxels=B.voxelize(B.mesh,true,
true);h&&h()}}var o=this.mesh.extents,s=[(o.xmin+o.xmax)/2,(o.ymin+o.ymax)/2,(o.zmin+o.zmax)/2];if(e.midpointOffset)s=f.v3.mul(e.midpointOffset,k);else if(e.midpointMemory)s=f.v3.mul(e.midpointMemory,k);else e.midpointMemory=f.v3.mul(s,1/k);var E=g?300:0;var w=g=(new Date).getTime(),D=g+E,B=this,m=1,A=1,r=1;p()},undoShear:function(e){var g=_.clone(this.transforms.pop());g.shearXY=-g.shearXY;g.shearYX=-g.shearYX;g.shearYZ=-g.shearYZ;g.shearZY=-g.shearZY;g.shearXZ=-g.shearXZ;g.shearZX=-g.shearZX;this.shearBase(g,
true,e)},shear:function(e,g,h){this.shearBase(e,g,h);this.transforms.push(e)},shearBase:function(e,g,h){function j(){var t=(new Date).getTime();if(t<w){t=f.ease((t-E)/s);D.mesh.translate(f.v3.mul(o,-1));var u=f.m4.shear(-B,-m,-A,-r,-v,-H,f.m4.I);D.mesh.transform(u,false,false);D.mesh.translate(o);B=t*e.shearXY;m=t*e.shearXZ;A=t*e.shearYX;r=t*e.shearYZ;v=t*e.shearZX;H=t*e.shearZY;D.mesh.translate(f.v3.mul(o,-1));u=f.m4.shear(B,m,A,r,v,H,f.m4.I);D.mesh.transform(u,true,false);D.mesh.translate(o,true);
D.view.draw();requestAnimationFrame(j)}else{D.mesh.translate(f.v3.mul(o,-1));u=f.m4.shear(-B,-m,-A,-r,-v,-H,f.m4.I);D.mesh.transform(u,false,false);D.mesh.translate(o);D.mesh.translate(f.v3.mul(o,-1));u=f.m4.shear(e.shearXY,e.shearXZ,e.shearYX,e.shearYZ,e.shearZX,e.shearZY,f.m4.I);D.mesh.transform(u,true,false);D.mesh.translate(o,true);D.voxels=D.voxelize(D.mesh,true,true);h&&h();D.view.draw()}}var p=this.mesh.extents,o=[(p.xmin+p.xmax)/2,(p.ymin+p.ymax)/2,(p.zmin+p.zmax)/2];if(e.midpointOffset)o=
f.v3.mul(e.midpointOffset,k);else if(e.midpointMemory)o=f.v3.mul(e.midpointMemory,k);else e.midpointMemory=f.v3.mul(o,1/k);var s=g?300:0;var E=g=(new Date).getTime(),w=g+s,D=this,B=0,m=0,A=0,r=0,v=0,H=0;j()},n07c:function(e,g){g=g||this.voxels;return this.base(g,e)},clone:function(e){var g=this;this.view.meshLoader.getMesh(this.type,this.params,function(h){var j=new f.Mesh3D(g.view);j.n196(h.surfaces);var p=new d(g.type,g.n1a9,g.view,g.color,g.params,{mesh:j,alignment:g.alignment});_(g.transforms).each(function(o){p.n131(_.clone(o))});
p.origuid=g.uid;e(p)},function(h){g.view.error(new Error(f.C.exception_geomcursorclone_failed),h)})},n0c9:function(){this.transforms=_(this.transforms).reject(function(e){if(e.type==f.C.xform_translate){this.mesh.translate(f.v3.mul(e.delta,-k),true);return true}else return false},this);_(this.transforms).each(function(e){if(e.axisMemory)e.axisMemory=null;if(e.midpointMemory)e.midpointMemory=null},this)},n1ad:function(){return{uid:this.uid,template_id:this.type,init_params:this.params,color:this.color,
alignment:this.alignment,transforms:this.transforms}},get2dextents:function(e){return this.base(this.dextents,e)}});d.n13f=function(e,g,h){g.view.meshLoader.getMesh(e.template_id,e.init_params,function(j){var p=new f.Mesh3D(g.view);p.n196(j.surfaces);j=new f.n18e(e.template_id,g,g.view,e.color,e.init_params,{mesh:p,alignment:e.alignment},e.uid);_(e.transforms).each(j.n131,j);h(j)})};d.getInstanceSignature=function(e,g){var h=e+"/";e=_(g).keys().sort();_(e).each(function(j){h+=j+g[j]});return h};f.n18e=
d})(framework);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){var f;if(typeof window!=="undefined")f=y.tin;else{_=require("../../../libs/underscore")._;f=require("./declare").tin;require("./geometry");require("./mesh")}var k=f.C.cube_size,n=f.Geometry.extend({constructor:function(c,b,d){this.cubes=[];this.cmap={};this.n1a9=c;this.smoothness=0;this.view=b;this.forceCubicle=false;this.smoothMeshCache=null;this.geomType=f.C.n0b2;this.base(null,d)},n26d:function(c){var b=c.position.join("_");if(this.cmap[b]===undefined){this.cmap[b]=this.cubes.length;
this.cubes.push(c);this.n10b(c,true);this.smoothMeshCache=this.mesh=null;c.group=this}},toString:function(){var c="UID "+this.uid+" ";c+="cmap: ";var b=_(this.cmap).keys();_(b).each(function(d){c+="["+d+" : "+this.cmap[d]+"]"},this);c+=" cubes: ";_(this.cubes).each(function(d,e){c+=d?"["+e+": "+d.position+"] ":"["+e+": "+d+"] "},this);return c},n1c1:function(c){var b=c.position.join("_"),d=this.cmap[b];this.cmap[b]=undefined;this.cubes[d]=undefined;c.group=null;this.isEmpty()||this.n071(c);this.smoothMeshCache=
this.mesh=null},removeAllCubes:function(){_(this.cubes).each(function(c){if(c){var b=c.position.join("_"),d=this.cmap[b];this.cmap[b]=undefined;this.cubes[d]=undefined;c.group=null}},this);this.smoothMeshCache=this.mesh=null},getCubes:function(){return this.cubes},isEmpty:function(){return!_(this.cubes).any()},isAbstractCSG:function(){return false},prepare:function(c){var b=this;if(this.forceCubicle){if(!this.mesh||this.mesh.smoothness>0)this.n14c();c&&c()}else if(this.smoothness>0)if(!this.mesh||
this.mesh.smoothness<=0)if(this.smoothMeshCache&&this.smoothMeshCache.smoothness==this.smoothness){this.mesh=this.smoothMeshCache;c&&c()}else{this.view._jq&&this.view._jq.trigger("smoothen_started");this.smoothen(function(d){b.n0ab(d[b.uid]);b.view._jq&&b.view._jq.trigger("smoothen_finished");c&&c()})}else c&&c();else{if(!this.mesh||this.mesh.smoothness>0)this.n14c();c&&c()}},prepare3D:function(c){var b=this;this.prepare(function(){b._prepare3D(c)})},prepare2D:function(c){var b=this;this.prepare(function(){b._prepare2D(c)})},
n071:function(c){c=c.getSidePositions();_(c).each(function(b){(b=this.n297(b))&&this.n10b(b,false)},this)},n10b:function(c,b){c.n1b7=[];var d=c.getSidePositions();_(d).each(function(e,g){if(e=this.n297(e)){c.n1b7.push(g);b&&this.n10b(e,false)}},this)},n297:function(c){c=this.cmap[c.join("_")];if(c===undefined)return null;return this.cubes[c]},contains:function(c){return this.n297(c)?true:false},findIntersection:function(c,b,d){return this.base(this.cubes,c,b,d)},n22f:function(c,b){c.n22f(b);this.n14c();
this.smoothMeshCache=null},n14c:function(){var c=this.view.n2bc?new f.Mesh3D(this.view):new f.Mesh(this.view);_(this.cubes).each(function(b){if(b)if(b.n1b7.length!==6){var d=c.n1d3(b.rgba),e=[];_(8).times(function(g){e.push(b.n21e(g))});_(e).each(function(g){c.n19a(g)},this);_(f.n24c.faces).each(function(g,h){if(!(b.n1b7.indexOf(h)>=0)){g=_(g).map(function(j){return e[j]});c.n20b(g,d)}},this)}},this);this.mesh=c;this.mesh.smoothness=0;this.view.n2bc&&c.generate_colored_n267()},n0ab:function(c){if(this.view.n2bc){this.mesh=
new f.Mesh3D(this.view);this.mesh.n196(c)}else{var b=new f.Mesh(this.view);_(c).each(function(d){var e=b.n1d3(d.rgba);d=_(d.vertices).map(function(g){return f.v3.mul(g,k)},this);_(d).each(b.n19a,b);b.n20b(d,e)},this);this.mesh=b}this.mesh.smoothness=this.smoothness;this.smoothMeshCache=this.mesh},n186:function(){return f.v3.mul(_(this.cubes).reduce(function(c,b){return b?f.v3.add(c,b.n28a()):c},[0,0,0],this),1/this.cubes.length)},setSmoothness:function(c,b){var d=this,e=this.smoothness;this.smoothness=
c;if(c!==e)if(c>0){this.n14c();this.view._jq&&this.view._jq.trigger("smoothen_started");this.smoothen(function(g){d.n0ab(g[d.uid]);d.view._jq&&d.view._jq.trigger("smoothen_finished");b&&b()})}else{this.n14c();b&&b()}},smoothen:function(c){if(this.view.ccengineSupport){f.ccengine.reset();f.ccengine.prepare(this.uid,this.smoothness);_(this.cubes).each(function(b){if(b)if(b.n1b7.length!==6){_(8).times(function(d){f.ccengine.n204(this.uid,b.n21e(d))},this);_(6).times(function(d){if(!(b.n1b7.indexOf(d)>=
0)){var e=f.n24c.faces[d],g=[];_(4).times(function(h){g.push(b.n21e(e[h]))});f.ccengine.n27b(this.uid,g,b.rgba)}},this)}},this);f.ccengine.run(c,this,this.view.n2bc)}},n1f8:function(c){var b=_(this.cubes).select(function(d){return d})[0].offset;_(this.cubes).each(function(d){d&&d.n1f8(c)},this);b=f.v3.sub(c,b);this.mesh.translate(f.v3.mul(b,k),true)},undoTranslate:function(c){c.delta=f.v3.mul(c.delta,-1);this.translate(c)},translate:function(c){_(this.cubes).each(function(b){b&&b.translate(c.delta)},
this);this.cmap={};_(this.cubes).each(function(b,d){if(b)this.cmap[b.position.join("_")]=d},this);_(this.cubes).each(function(b){b&&this.n10b(b,false)},this);this.mesh.translate(f.v3.mul(c.delta,k),true)},n2a2Separately:function(c){var b={};_(this.cubes).each(function(d){if(d){var e=d.position.join("_");d.translate(c[e]);e=f.v3.mul(c[e],-1);b[d.position.join("_")]=e}},this);this.cmap={};_(this.cubes).each(function(d,e){if(d)this.cmap[d.position.join("_")]=e},this);_(this.cubes).each(function(d){d&&
this.n10b(d,false)},this);return b},n092:function(){var c=this.n186();c=_(f.v3.mul(c,1/k)).map(function(g){return parseInt(g,10)});var b=[[1,0,0],[0,1,0],[0,0,1],[1,1,0],[0,1,1],[1,0,1],[1,1,1]],d=[];_(this.cubes).each(function(g){if(g){var h=f.v3.sub(g.position,c),j=f.v3.add(c,f.v3.mul(h,2));d.push(new f.n10a({position:j,rgba:{r:g.rgba.r,g:g.rgba.g,b:g.rgba.b,a:g.rgba.a}}));_(b).each(function(p){p=f.v3.add(j,p);d.push(new f.n10a({position:p,rgba:{r:g.rgba.r,g:g.rgba.g,b:g.rgba.b,a:g.rgba.a}}))},
this)}},this);var e=this.cubes.slice(0,this.cubes.length);return{n231:_(e).compact(),n255:d}},n23d:function(){var c=[1E6,1E6,1E6],b=[-1000000,-1000000,-1000000];_(this.cubes).each(function(d){d&&_(d.position).each(function(e,g){c[g]=Math.min(c[g],e);b[g]=Math.max(b[g],e)},this)},this);return[Math.round((c[0]+b[0])/2),Math.round((c[1]+b[1])/2),Math.round((c[2]+b[2])/2)]},intersectsAfterTransform:function(c){return this.n07c([0,0,0],_(this.cubes).map(function(b){if(b){var d=b.position.join("_");b=f.v3.add(b.position,
c[d]);return new f.n10a({position:b,group:this})}}))},rotate:function(c,b){function d(){var B=(new Date).getTime();if(B<o){B=(B-p)/j;var m=B*s-D;D=B*s;w.mesh.translate(E);B=f.m4.rotate(m,e,f.m4.I);w.mesh.transform(B,true);w.mesh.translate(h,true);w.view.draw();requestAnimationFrame(d)}else{w.mesh=null;w.smoothMeshCache=null;y(w.view.canvas).trigger("model_changed",w.view.model)}}var e=[0,0,0];e[c.pivotAxis]=1;var g=this.mesh.extents,h=[(g.xmin+g.xmax)/2,(g.ymin+g.ymax)/2,(g.zmin+g.zmax)/2],j=b?300:
0,p=b=(new Date).getTime(),o=b+j,s=c.clockwise?-Math.PI*c.angle/180:Math.PI*c.angle/180,E=[-h[0],-h[1],-h[2]],w=this,D=0;d();b=this.n06d(c.clockwise,c.pivotAxis,c.angle);c.offsets=this.n2a2Separately(b)},n06d:function(c,b,d){var e=this.n23d(),g=(b+1)%3,h=(b+2)%3,j={};_(this.cubes).each(function(p){if(p){var o=[];if(d==90)if(c){o[h]=-(p.position[g]-e[g]);o[g]=p.position[h]-e[h]}else{o[g]=-(p.position[h]-e[h]);o[h]=p.position[g]-e[g]}else{o[h]=-(p.position[h]-e[h]);o[g]=-(p.position[g]-e[g])}var s=
p.position.slice(0,3);s[g]=o[g]+e[g];s[h]=o[h]+e[h];j[p.position.join("_")]=f.v3.sub(s,p.position)}},this);return j},flip:function(c){var b=this.n080(c.flipAxis);c.offsets=this.n2a2Separately(b);this.smoothMeshCache=this.mesh=null},n080:function(c){var b=this.n23d(),d={};_(this.cubes).each(function(e){if(e){var g=e.position[c]-b[c],h=e.position.slice(0,3);h[c]=b[c]-g;d[e.position.join("_")]=f.v3.sub(h,e.position)}},this);return d},project:function(){},get2dextents:function(c){var b={xmin:Infinity,
xmax:-Infinity,ymin:Infinity,ymax:-Infinity,zmin:Infinity,zmax:-Infinity};_(this.cubes).each(function(d){if(d){b.xmin=Math.min(d.position[0]+d.offset[0],b.xmin);b.xmax=Math.max(d.position[0]+d.offset[0],b.xmax);b.ymin=Math.min(d.position[1]+d.offset[1],b.ymin);b.ymax=Math.max(d.position[1]+d.offset[1],b.ymax);b.zmin=Math.min(d.position[2]+d.offset[2],b.zmin);b.zmax=Math.max(d.position[2]+d.offset[2],b.zmax)}},this);return this.base(b,c)},n07c:function(c,b){b=b||this.cubes;return this.base(b,c)}});
f.n200=n})(framework);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){var f;if(typeof window!=="undefined")f=y.tin;else{_=require("../../../libs/underscore")._;f=require("./declare").tin;require("./geometry");require("./mesh")}var k=f.C.cube_size,n=f.Geometry.extend({constructor:function(c,b,d){this.n1a9=c;this.children=b||[];this.base(null,d);this.makeVoxels();this.calcExtents();this.geomType=f.C.n117},addChild:function(c){this.children.push(c)},getCubes:function(){return this.cubes},n1ad:function(){return{uid:this.uid,children:_(this.children).invoke("n1ad")}},
contains:function(c){var b=this.extents;return c[0]*k>=b.xmin&&c[0]*k<=b.xmax&&c[1]*k>=b.ymin&&c[1]*k<=b.ymax&&c[2]*k>=b.zmin&&c[2]*k<=b.zmax},n297:function(c){return _(this.cubes).select(function(b){return _.isEqual(b.position,c)})[0]},alignToGrid:function(){},calcExtents:function(){var c={xmin:Infinity,xmax:-Infinity,ymin:Infinity,ymax:-Infinity,zmin:Infinity,zmax:-Infinity};_(this.children).chain().map(function(b){return b.geomType==f.C.n117?b.extents:b.mesh.extents}).each(function(b){c.xmin=Math.min(b.xmin,
c.xmin);c.xmax=Math.max(b.xmax,c.xmax);c.ymin=Math.min(b.ymin,c.ymin);c.ymax=Math.max(b.ymax,c.ymax);c.zmin=Math.min(b.zmin,c.zmin);c.zmax=Math.max(b.zmax,c.zmax)});this.extents=c},n11f:function(){return f.Mesh.n11f(this.extents)},n0db:function(){this.n1a9.view._jq.trigger("current_geom_extents",this.extents)},makeVoxels:function(){this.cubes=[];_(this.children).each(function(c){_(c.getCubes()).each(function(b){this.cubes.push(new f.n10a({position:b.position,rgba:{},group:this}))},this)},this)},findIntersection:function(c,
b,d){return this.base(this.cubes,c,b,d)},get2dextents:function(c){return this.base(this.dextents,c)},n186:function(){var c=this.extents;return[(c.xmin+c.xmax)/2,(c.ymin+c.ymax)/2,(c.zmin+c.zmax)/2]},get2dextents:function(){var c=_(this.children).map(function(d){return d.get2dextents(this.n1a9.view)},this),b={xmin:Infinity,xmax:-Infinity,ymin:Infinity,ymax:-Infinity};_(c).each(function(d){b.xmin=Math.min(d.xmin,b.xmin);b.xmax=Math.max(d.xmax,b.xmax);b.ymin=Math.min(d.ymin,b.ymin);b.ymax=Math.max(d.ymax,
b.ymax)},this);return b},n22f:function(c){_.isArray(c)?_(this.children).each(function(b,d){b.n22f(c[d])},this):_(this.children).invoke("n22f",c)},getColor:function(){return _(this.children).invoke("getColor")},n1f8:function(c){_(this.children).invoke("n1f8",c);this.calcExtents()},addOffset:function(c){_(this.children).invoke("addOffset",c);this.calcExtents()},getOffset:function(){return _(this.children).first().getOffset()},isTemporary:function(){return this.uid==f.C.temp_group_uid},undoTranslate:function(c){var b=
this,d=_.after(this.children.length,function(){b.makeVoxels();b.calcExtents();c&&c()});_(this.children).invoke("undoTranslate",d)},translate:function(c,b,d){var e=this,g=_.after(this.children.length,function(){e.makeVoxels();e.calcExtents();d&&d()});_(this.children).invoke("translate",c,b,g)},undoRotate:function(c){var b=this,d=_.after(this.children.length,function(){b.makeVoxels();b.calcExtents();c&&c()});_(this.children).invoke("undoRotate",d)},rotate:function(c,b,d){if(!c.axisOffset)c.axisOffset=
f.v3.mul(this.n186(),1/k);var e=this,g=_.after(this.children.length,function(){e.makeVoxels();e.calcExtents();d&&d()});_(this.children).invoke("rotate",c,b,g)},scale:function(c,b,d){if(!c.midpointOffset)c.midpointOffset=f.v3.mul(this.n186(),1/k);var e=this,g=_.after(this.children.length,function(){e.makeVoxels();e.calcExtents();d&&d()});_(this.children).invoke("scale",c,b,g)},shear:function(c,b,d){if(!c.midpointOffset)c.midpointOffset=f.v3.mul(this.n186(),1/k);var e=this,g=_.after(this.children.length,
function(){e.makeVoxels();e.calcExtents();d&&d()});_(this.children).invoke("shear",c,b,g)},undoScale:function(c){var b=this,d=_.after(this.children.length,function(){b.makeVoxels();b.calcExtents();c&&c()});_(this.children).invoke("undoScale",d)},undoShear:function(c){var b=this,d=_.after(this.children.length,function(){b.makeVoxels();b.calcExtents();c&&c()});_(this.children).invoke("undoShear",d)},undoFlip:function(c){_(this.children).invoke("undoFlip",c);this.makeVoxels();this.calcExtents()},flip:function(c){if(!c.midpoint)c.midpoint=
this.n186();_(this.children).invoke("flip",c);this.makeVoxels();this.calcExtents()},clone:function(c){function b(j){h.push(j);if(++e>=g){j=new f.n14d(d.n1a9,h);j.origuid=d.uid;c(j)}else d.children[e].clone(b)}var d=this,e=0,g=this.children.length,h=[];this.children[e].clone(b)},n0c9:function(){this.translate({v:f.C.xformversion,type:f.C.xform_translate,delta:f.v3.mul(this.n186(),-1/k)})},focus:function(c,b){this.focusColor=c;_(this.children).invoke("focus",c,b)},defocus:function(){this.focusColor=
null;_(this.children).invoke("defocus")},prepare3D:function(c){_(this.children).invoke("prepare3D",c)},drawWireframe:function(c){_(this.children).invoke("drawWireframe",c)},draw:function(){_(this.children).invoke("draw",this.n1a9.view)}});n.n13f=function(c,b,d){var e=[],g=0,h=function(j){g++;e.push(j);g==c.children.length&&d(new n(b,e,c.uid))};_(c.children).each(function(j){j.children?f.n14d.n13f(j,b,h):f.n18e.n13f(j,b,h)},this)};f.n14d=n})(framework);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){var f=y.tin;y=f.n200.extend({n26d:function(k,n){this.base(k);this.prepare(n)},n1c1:function(k,n){this.base(k);this.prepare(n)},draw:function(k){f.n2be.n15b(false);f.n2be.n23b(true);this.base(k)}});f.Transientn200=y})(jQuery);
(function(y){var f=y.tin,k,n,c,b,d=false;f.n178={onDown:function(e){k=e.clientX;n=e.clientY;d=true;return false},onMove:function(e){if(d){var g=e.data.view;c=e.clientX;b=e.clientY;f.n0b7(g.selectcanvas,k,n,c,b);g._jq.trigger("select.update",{ymin:n,xmin:k,ymax:b,xmax:c})}},onUp:function(e){var g=e.data.view;g.selectcanvas.get(0).getContext("2d").clearRect(0,0,g.selectcanvas.width(),g.selectcanvas.height());c=e.clientX;b=e.clientY;d=false;g._jq.trigger("select.done",{ymin:n,xmin:k,ymax:b,xmax:c});
g.setAction(f.C.n177);return false}}})(jQuery);
(function(y){function f(A){var r=A.data.view,v=r.getX(A)-j>0;if(v!=o)E=r.getX(A);o=v;v=r.getY(A)-p>0;if(v!=s)w=r.getY(A);s=v;j=r.getX(A);p=r.getY(A);v=r.camera.n0e1();v.phi-=10*(r.getX(A)-E)/r.width;v.theta-=10*(r.getY(A)-w)/r.height;v.theta=Math.max(1,Math.min(179,v.theta));r.camera.n0e9(v)}function k(A){var r=A.data.view,v=r.getX(A);A=r.height-r.getY(A);pos=e.n078(v,A,r.width,r.height,r.project([0,0,0]),r);var H=e.v3.sub(r.n21b(D),r.n21b(pos));D=pos;r.camera.update({position:e.v3.add(r.camera.position,
H),target:e.v3.add(r.camera.target,H)});j=v;p=A}function n(A){m=true;var r=A.data.view;r.canvas.css({cursor:"col-resize"});var v=r.getX(A);A=r.height-r.getY(A);D=e.n078(v,A,r.width,r.height,r.project([0,0,0]),r)}function c(){B=true}function b(A){m=false;A.data.view.canvas.css({cursor:"move"})}function d(){B=false}var e=y.tin,g=e.C.cube_size,h=null,j,p,o=true,s=true,E,w,D,B=false,m=false;e.n192={onDown:function(A){var r=A.data.view;if(h)r._jq.trigger("geometry_clicked",{ev:A});else A.shiftKey?n(A):
c()},onMove:function(A){var r=A.data.view;if(B){f(A);return false}if(m){k(A);return false}r.model.n0a3();A=r.model.findIntersection(r.n268(A),g,r);r.n141=false;if(A){if(!h||h.uid!==A.group.uid){h=A.group;r.canvas.css("cursor","url("+r.cursorPath+"/hand-open.png), auto");A.group.focus({r:0,g:0,b:255});var v=A.group.get2dextents(r);v&&r._jq.trigger("geometry_focused",{geometry:A.group,extents:v});r.draw()}}else{r.canvas.css({cursor:"move"});if(h){r.model.n0a3();h=null;r._jq.trigger("geometry_defocused");
r.draw()}}},onUp:function(A){B&&d();m&&b(A)}}})(jQuery);
(function(y){var f=y.tin,k=null,n=null;f.n222={onDown:function(c){var b=c.data.view;if(b.geometry){b.n10e();c=f.n084(c);b.geometry.translate({type:f.C.xform_translate,delta:c,v:f.C.xformversion});b.model.addGeometry(b.geometry);k={type:f.C.n1c4,geomsign:b.geometry.n1ad()};b.draw();b.n19b.clear();b.geometry.clone(function(g){g.n0c9();g.alignToGrid();b.geometry=g})}else{var d=b.n10e();c=f.n084(c);if(!(b.model.n297(c)||b.n0bc&&b.n0bc.n297(c))){b.n0bc=new f.Transientn200(b.model,b);var e=new f.n10a({position:c,
rgba:{r:d.r,g:d.g,b:d.b,a:d.a}});n=e;e.fade();b.n0bc.n26d(e,function(){b.draw()});if(b.n260)if(c=f.n226.n12a(c))if(!b.model.n297(c)){d=new f.n10a({position:c,rgba:{r:d.r,g:d.g,b:d.b,a:d.a}});d.fade();b.n0bc.n26d(d)}}b.n141=false}},onMove:function(c){var b=c.data.view;if(!k){var d=b.n10e();c=b.model.n152(b.n268(c),n,b);if(!(b.model.n297(c)||b.n0bc&&b.n0bc.n297(c))){var e=new f.n10a({position:c,rgba:{r:d.r,g:d.g,b:d.b,a:d.a}});e.fade();b.n0bc.n26d(e,function(){b.draw()});if(b.n260)if(c=f.n226.n12a(c))if(!b.model.n297(c)){d=
new f.n10a({position:c,rgba:{r:d.r,g:d.g,b:d.b,a:d.a}});d.fade();b.n0bc.n26d(d,function(){b.draw()})}}}},onUp:function(c){var b=c.data.view;if(!k&&b.n0bc){var d=null;_(b.n0bc.cubes).each(function(g){g=_(g.getSidePositions()).chain().map(function(h){return b.model.n297(h)}).compact().select(function(h){return!h.isVirtual}).value();if(g.length>0)d=g[0].group});if(d){k={type:f.C.n16e,mod_type:"add",mods:[{cubeg_uid:d.uid,cubes:_(b.n0bc.cubes).map(function(g){g.unfade();return{position:g.position,rgba:{r:g.rgba.r,
g:g.rgba.g,b:g.rgba.b,a:g.rgba.a}}})}]};_(b.n0bc.cubes).map(function(g){d.n26d(g)});b.n0bc.cubes=[];b.n0bc=null}else{var e=new f.n200(b.model,b);_(b.n0bc.cubes).each(function(g){g.unfade();e.n26d(g)},this);b.n0bc.cubes=[];b.n0bc=null;b.model.addGeometry(e);k={type:f.C.n166,cubeg_uid:e.uid,cubes_added:_(e.cubes).map(function(g){return{position:g.position,rgba:{r:g.rgba.r,g:g.rgba.g,b:g.rgba.b,a:g.rgba.a}}})}}y(b.canvas).trigger("model_changed",b.model)}b.model.do_(k);n=k=null}}})(jQuery);
(function(y){var f=y.tin;f.n0f3={onDown:function(){throw new Error("unsupported");},onMove:function(k){var n=k.data.view;if(n.geometry){c=f.n084(k);n.n19b.clear();n.n19b.n22f(f.n107(n.geometry.getColor(),90));n.n19b.n18d(n.geometry,c)}else{var c=f.n084(k);if(!n.model.n297(c)){k=[c];if(n.n260)(c=f.n226.n12a(c))&&!n.model.n297(c)&&k.push(c);n.n19b.clear();n.n19b.n22f(f.n107(n.n10e(),50));n.n19b.n0fc(k)}}n.draw()},onUp:function(){throw new Error("unsupported");}}})(jQuery);
(function(y){function f(d,e){mod=_(d.mods).select(function(h){return h.cubeg_uid==e.group.uid});var g=e.rgba;mod.length>0?mod[0].cubes.push({position:e.position,rgba:{r:g.r,g:g.g,b:g.b,a:g.a}}):d.mods.push({cubeg_uid:e.group.uid,cubes:[{position:e.position,rgba:{r:g.r,g:g.g,b:g.b,a:g.a}}]})}var k=y.tin,n=k.C.cube_size,c=null,b=null;k.n1a4={onDown:function(d){var e=d.data.view;d=e.model.findIntersection(e.n268(d),n,e);e.n141=false;if(d){if(d.group.geomType!=k.C.n0b2){e.model.removeGeometry(d.group);
c={type:k.C.n1cd,geomsign:d.group.n1ad()}}else{b=d;var g=d.rgba;c={type:k.C.n16e,mod_type:"erase",mods:[{cubeg_uid:d.group.uid,cubes:[{position:d.position,rgba:{r:g.r,g:g.g,b:g.b,a:g.a}}]}]};d.group.n1c1(d);e.n0bc=new k.Transientn200(e.model,e);cubecopy=d.clone();cubecopy.fade();e.n0bc.n26d(cubecopy);if(e.n260)if(d=k.n226.n12a(d.position))if((d=e.model.n297(d))&&!d.isVirtual){f(c,d);d.group.n1c1(d);n1cacopy=d.clone();n1cacopy.fade();e.n0bc.n26d(n1cacopy)}}y(e.canvas).trigger("model_changed",e.model);
e.n19b.clear()}},onMove:function(d){var e=d.data.view;d=e.model.n152(e.n268(d),b,e);var g=e.model.n297(d);if(g&&g.group.geomType==k.C.n0b2){if(c.type==k.C.n16e){f(c,g);g.group.n1c1(g);cubecopy=g.clone();cubecopy.fade();e.n0bc.n26d(cubecopy);if(e.n260)if(d=k.n226.n12a(d))if((d=e.model.n297(d))&&!d.isVirtual){f(c,d);d.group.n1c1(d);n1cacopy=d.clone();n1cacopy.fade();e.n0bc.n26d(n1cacopy)}}y(e.canvas).trigger("model_changed",e.model)}},onUp:function(d){d=d.data.view;d.n0bc=null;d.model.do_(c);b=c=null}}})(jQuery);
(function(y){var f=y.tin,k=f.C.cube_size;f.n0cf={onDown:function(){throw new Error("unsupported");},onMove:function(n){var c=n.data.view,b=c.model.findIntersection(c.n268(n),k,c);c.model.n0a3();c.n141=false;c.n19b.clear();if(b)if(b.group.geomType!=f.C.n0b2)b.group.focus({r:255,g:0,b:0});else{c.n141=true;n=[b.position];if(c.n260)(b=f.n226.n12a(b.position))&&c.model.n297(b)&&n.push(b);c.n19b.n22f({r:255,g:0,b:0,a:0});c.n19b.n0fc(n)}c.draw()},onUp:function(){throw new Error("unsupported");}}})(jQuery);
(function(y){function f(e,g){return _(e.mods).any(function(h){return _(h.cubes).any(function(j){return j.position[0]==g.position[0]&&j.position[1]==g.position[1]&&j.position[2]==g.position[2]})})}function k(e,g,h,j){mod=_(e.mods).select(function(p){return p.cubeg_uid==g.group.uid});if(mod.length>0)f(e,g)||mod[0].cubes.push({position:g.position,oldcolor:h,newcolor:j});else f(e,g)||e.mods.push({cubeg_uid:g.group.uid,cubes:[{position:g.position,oldcolor:h,newcolor:j}]})}var n=y.tin,c=n.C.cube_size,b=
null,d=null;n.n1af={onDown:function(e){var g=e.data.view,h=g.model.findIntersection(g.n268(e),c,g);g.n141=false;if(h){e=g.n10e();var j=h.group;if(j.geomType!=n.C.n0b2){var p=j.getColor();j.n22f(e);b={type:n.C.n156,csg_uid:j.uid,oldcolor:p,newcolor:e}}else{p=h.getColor();j.n22f(h,e);d=h;n0e5=true;b={type:n.C.n16e,mod_type:"color",mods:[{cubeg_uid:j.uid,cubes:[{position:h.position,oldcolor:p,newcolor:e}]}]};if(g.n260)if(p=n.n226.n12a(h.position))if(h=g.model.n297(p)){p=h.getColor();h.group.n22f(h,e);
k(b,h,p,e)}}y(g.canvas).trigger("model_changed",g.model);g.n19b.clear()}},onMove:function(e){var g=e.data.view,h=g.model.n152(g.n268(e),d,g),j=g.model.n297(h);if(j&&!j.isVirtual)if(b.type==n.C.n16e){var p=j.getColor();e=g.n10e();j.group.n22f(j,e);k(b,j,p,e);if(g.n260)if(p=n.n226.n12a(h))if(h=g.model.n297(p)){p=h.getColor();h.group.n22f(h,e);k(b,h,p,e)}g.n19b.clear();y(g.canvas).trigger("model_changed",g.model)}},onUp:function(e){e.data.view.model.do_(b);d=b=null}}})(jQuery);
(function(y){var f=y.tin,k=f.C.cube_size;f.Previewn1af={onDown:function(){throw new Error("unsupported");},onMove:function(n){var c=n.data.view,b=c.model.findIntersection(c.n268(n),k,c);c.model.n0a3();c.n141=false;c.n19b.clear();if(b)if(b.group.geomType!=f.C.n0b2)b.group.focus(c.n10e());else{c.n141=true;n=[b.position];if(c.n260)(b=f.n226.n12a(b.position))&&c.model.n297(b)&&n.push(b);c.n19b.n22f(f.n107(c.n10e()));c.n19b.n0fc(n)}c.draw()},onUp:function(){throw new Error("unsupported");}}})(jQuery);
(function(y){y=y.tin;var f=y.C.cube_size;y.ColorPickAction={onDown:function(k){var n=k.data.view;if(k=n.model.findIntersection(n.n268(k),f,n)){k.group.isCSG?n.setCurrentColor(k.group.color):n.setCurrentColor(k.rgba);n._jq.trigger("color_changed",k.rgba)}},onMove:function(){throw new Error("unsupported");},onUp:function(){throw new Error("unsupported");}}})(jQuery);
(function(y){function f(b){var d=b.data.view,e=d.model.findIntersection(d.n268(b),n*1.414/2,d);b=d.model.n087(d.n268(b),n*1.414/2,d);if(!b)return null;var g=[Math.round(b.pos[0]/n),Math.round(b.pos[1]/n),Math.round(b.pos[2]/n)],h=k.n24c.n105(b.dir),j;switch(b.dir){case 0:j=[2,3,4,5];break;case 1:j=[2,3,4,5];break;case 2:j=[4,5,0,1];break;case 3:j=[4,5,0,1];break;case 4:j=[0,1,2,3];break;case 5:j=[0,1,2,3];break}n291=[];var p=function(s){for(var E=0,w=n291.length;E<w;E++){var D=n291[E];if(D[0]===s[0]&&
D[1]===s[1]&&D[2]===s[2])return true}return false},o=function(s,E){_(E).each(function(w){w=[s[0]+k.n24c.deltas[w][0],s[1]+k.n24c.deltas[w][1],s[2]+k.n24c.deltas[w][2]];if(d.model.n1cf(w,h))if(!p(w)&&!d.model.n297(w)){n291.push(w);o(w,E)}})};o(g,j);return{n113:e.group,n291:n291}}var k=y.tin,n=k.C.cube_size,c={onDown:function(){throw new Error("unsupported");},onMove:function(b){var d=b.data.view,e=f(b);d.n19b.clear();if(e&&e.n291&&e.n291.length>0){d.n141=true;d.n19b.n22f(k.n107(d.n10e(),50));d.n19b.n0fc(e.n291);
if(d.n260){b=k.n226.n12a(e.n291);b=_(b).select(function(g){return _(e.n291).select(function(h){return _.isEqual(h,g)},this).length===0},this);d.n19b.n0fc(b)}}else d.n141=false;d.draw()},onUp:function(){throw new Error("unsupported");}};k.n14b={onDown:function(b){var d,e=b.data.view;if((b=f(b))&&b.n291){var g,h=e.n10e();if(b.n113.isCSG){g=new k.n200(e.model,e);_(n291).each(function(j){j=new k.n10a({position:j,rgba:{r:h.r,g:h.g,b:h.b,a:h.a}});g.n26d(j)},this);d={type:k.C.n166,cubeg_uid:g.uid,cubes_added:_(n291).map(function(j){return{position:j,
rgba:{r:h.r,g:h.g,b:h.b,a:h.a}}})};e.model.addGeometry(g)}else{g=b.n113;_(n291).each(function(j){j=new k.n10a({position:j,rgba:{r:h.r,g:h.g,b:h.b,a:h.a}});g.n26d(j)},this);d={type:k.C.n16e,mod_type:"add",mods:[{cubeg_uid:g.uid,cubes:_(n291).map(function(j){return{position:j,rgba:{r:h.r,g:h.g,b:h.b,a:h.a}}})}]}}if(e.n260){b=k.n226.n12a(n291);b=_(b).select(function(j){return _(n291).select(function(p){return _.isEqual(p,j)},this).length===0},this);_(b).each(function(j){if(!e.model.n297(j)){j=new k.n10a({position:j,
rgba:h});g.n26d(j);if(d.type==k.C.n166)d.cubes_added.push({position:j.position,rgba:{r:h.r,g:h.g,b:h.b,a:h.a}});else d.type==k.C.n16e&&d.mods[0].cubes.push({position:j.position,rgba:{r:h.r,g:h.g,b:h.b,a:h.a}})}},this)}y(e.canvas).trigger("model_changed",e.model);e.model.do_(d)}d=null},onMove:function(){throw new Error("unsupported");},onUp:function(){throw new Error("unsupported");}};k.n09f=c})(jQuery);framework=typeof jQuery=="undefined"?{}:jQuery;
(function(y){function f(b){_.extend(this,c,b);this.n167()}var k;if(typeof window==="undefined"){_=require("../../../libs/underscore")._;k=require("./declare").tin}else k=y.tin;var n=k.C.cube_size,c={position:[5,25,20],target:[0,0,0],up:[0,1,0],view:null};f.defaults=c;f.prototype={toString:function(){return JSON.stringify({position:this.position,target:this.target})},fromString:function(b){this.update(y.parseJSON(b))},update:function(b){if(b.sph)this.position=this.n076(b.sph);if(b.position)this.position=
b.position;if(b.target)this.target=b.target;this.n167();this.view.canvas&&this.view.canvas.trigger("camera_changed")},n167:function(){this.matrix=k.m4.n28e(k.v3.mul(this.position,n),k.v3.mul(this.target,n),this.up)},n0e1:function(){var b=k.v3.sub(this.position,this.target),d=k.v3.length(b);return{r:d,theta:Math.acos(b[1]/d)*180/Math.PI,phi:Math.atan2(b[0],b[2])*180/Math.PI}},n076:function(b){var d=b.phi*Math.PI/180,e=b.theta*Math.PI/180;return k.v3.add(this.target,[b.r*Math.sin(e)*Math.sin(d),b.r*
Math.cos(e),b.r*Math.sin(e)*Math.cos(d)])},n0e9:function(b){this.position=this.n076(b);this.n167();this.view.canvas&&this.view.canvas.trigger("camera_changed")},adjustView:function(b,d){function e(){var o=(new Date).getTime(),s;s=d?(o-h.time)/(j.time-h.time):k.ease((o-h.time)/(j.time-h.time));s={r:g.r,phi:_.isUndefined(j.phi)?h.phi:h.phi+s*(j.phi-h.phi),theta:_.isUndefined(j.theta)?h.theta:h.theta+s*(j.theta-h.theta)};p.n0e9(s);if(o<j.time||d&&p.view.n0a7)requestAnimationFrame(e);else p.view.n0a7=
false}var g=this.n0e1(),h={time:(new Date).getTime(),phi:g.phi,theta:g.theta},j={time:h.time+1E3};switch(b){case k.C.cam_view_top:j.theta=1;break;case k.C.cam_view_bottom:j.theta=179;break;case k.C.cam_view_left:j.phi=-90;break;case k.C.cam_view_right:j.phi=90;break;case k.C.cam_view_front:j.phi=0;break;case k.C.cam_view_back:j.phi=180;break;case k.C.cam_view_delta_left:j.phi=h.phi-60;break;case k.C.cam_view_delta_right:j.phi=h.phi+60;break;case k.C.cam_view_delta_top:j.theta=Math.max(h.theta-60,
1);break;case k.C.cam_view_delta_bottom:j.theta=Math.min(h.theta+60,179);break}var p=this;this.view.n0a7=true;e()}};k.Camera=f})(framework);
(function(y){function f(e){return e.r+"_"+e.g+"_"+e.b+"_"+e.a}function k(e){return Math.sqrt(e.r*e.r+e.g*e.g+e.b*e.b)}function n(){this.map={}}function c(e,g,h,j){this.maxdim=h;this.thickness=Math.round((g-1)/2);var p=e.width/e.height;if(p>1){g=this.maxdim;h=g/p}else{h=this.maxdim;g=h*p}this.view=j;this.spectrum=new n;this.canvas=document.createElement("canvas");this.canvas.width=g;this.canvas.height=h;j=this.canvas.getContext("2d");j.drawImage(e,0,0,g,h);this.pixels=j.getImageData(0,0,g,h).data;
this.generate(function(o,s,E){return E.thickness},{thickness:this.thickness},true)}var b=y.tin,d=null;n.prototype={add:function(e){var g=f(e.color),h=this.map[g];if(h)h.push(e);else this.map[g]=[e]},n1c2:function(e){var g=_(this.map).keys().length,h=Math.round((g-10)/9);this.groupsize=Math.round(g/(10+(e-1)*h));this.allcolors=_(this.map).map(function(j){return{color:j[0].color,voxels:j,thickness:j[0].thickness}},this).sort(function(j,p){return k(j.color)-k(p.color)});this.summary=[];_(this.allcolors).each(function(j,
p){p=Math.round(p/this.groupsize);if(this.summary[p])this.summary[p].voxels=this.summary[p].voxels.concat(j.voxels);else this.summary[p]=y.extend({},j)},this);return this.summary},getVoxels:function(e){return _(this.summary).select(function(g){return _.isEqual(g.color,e)})[0].voxels}};c.prototype={generate:function(e,g,h){this.symmetric=h;this.view.model.removeAll();d=new b.n200(this.view.model,this.view);_(this.canvas.height).times(function(j){_(this.canvas.width).times(function(p){var o=4*(this.canvas.width*
j+p);o={r:this.pixels[o],g:this.pixels[o+1],b:this.pixels[o+2],a:this.pixels[o+3]};p=this.maxdim/2-1-p;var s=this.maxdim/2-1-j,E=e(p,s,g);this.spectrum.add({color:o,position:[0,s,p],thickness:E});var w=new b.n10a({position:[0,s,p],rgba:o});d.n26d(w);for(var D=1;D<=E;D++){w=[D,s,p];w=new b.n10a({position:w,rgba:o});d.n26d(w);w=[-D,s,p];if(h){w=new b.n10a({position:w,rgba:o});d.n26d(w)}}},this)},this);this.view.model.addGeometry(d)},n1a5:function(){return this.spectrum.n1c2(1)},removeColor:function(e){var g=
this.view.model;e=this.spectrum.getVoxels(e);_(e).each(function(h){var j=g.n297(h.position);j&&d.n1c1(j);for(var p=1;p<=this.thickness;p++){pos=b.v3.add(h.position,[p,0,0]);(j=g.n297(pos))&&d.n1c1(j);if(this.symmetric){pos=b.v3.add(h.position,[-p,0,0]);(j=g.n297(pos))&&d.n1c1(j)}}},this);y(this.view.canvas).trigger("model_changed",g)},addColor:function(e){var g=this.view.model;e=this.spectrum.getVoxels(e);var h,j;_(e).each(function(p){if(!g.n297(p.position)){h=new b.n10a({position:p.position,rgba:p.color});
d.n26d(h)}for(var o=1;o<=this.thickness;o++){j=b.v3.add(p.position,[o,0,0]);if(!g.n297(j)){h=new b.n10a({position:j,rgba:p.color});d.n26d(h)}if(this.symmetric){j=b.v3.add(p.position,[-o,0,0]);if(!g.n297(j)){h=new b.n10a({position:j,rgba:p.color});d.n26d(h)}}}},this);y(this.view.canvas).trigger("model_changed",g)}};b.n218=c})(jQuery);
(function(y){var f=y.tin,k=f.C.cube_size,n={projection:f.C.proj_perspective,near:0.1,far:100,ymax:5,zoom:60,n1a8:[0,25,25],camTarn19f:[0,0,0],up:[0,1,0],n261:null,n17d:[{r:255,g:86,b:86,a:100},{r:127,g:255,b:0,a:100},{r:0,g:127,b:255,a:100},{r:255,g:255,b:86,a:100},{r:125,g:127,b:127,a:100}],mode:f.C.mode_cubicle,geometry:null,selectcanvas:null,action:f.C.n1db,n175:{r:255,g:86,b:86,a:100},top_:0,left_:0,height:600,width:800,n0a7:false,ambientLightColor:{r:50,g:50,b:50},dirLightColor:{r:220,g:220,
b:220},pointLightColor:{r:0,g:0,b:0},dirLightDirection:[-5,-5,-10],pointLightPosition:[7*k,7*k,7*k],backgroundColor:{r:255,g:255,b:255},modelClass:null,meshLoader:null,ccengineSupport:true,cursorPath:"/_cursors",log:function(){},error:function(){},user_warning:function(){},user_alert:function(){},numCubesLimit:0,drawableSpaceBoundary:null,n260:false,gridOn:true,snapToGrid:true,mouseInteractionEnabled:true,forceSyncSmoothing:false},c=function(b){y.extend(this,n,b);try{this.n0f6();this.canvas=this.canvas3d;
f.n2be.init(this.canvas);this.n2bc=true;this.model=this.modelClass?new this.modelClass:new f.n0d2}catch(d){this.n101();this.canvas=this.canvas2d;f.n2c0.init(this.canvas);this.n2bc=false;this.model=new f.n0dd}this.model.n286(this);this.height=this.canvas.height();this.width=this.canvas.width();this.aspect=this.width/(1*this.height);this.camera=new f.Camera({view:this});this.n08c(this.projection);this.grid=new f.Grid(this.n2bc,this);this.n19b=new f.n1a6(this);this.n141=false;this.n0bc=null;var e=this;
this.mouseInteractionEnabled&&this.n214();y(this.canvas).bind("model_changed",function(g,h){h.prepare(function(){e.draw()})});y(this.canvas).bind("camera_changed",function(){e.n12f();e.n0b6();y(e.canvas).trigger("view_changed",e);e.draw()});if(this.selectcanvas){this.selectcanvas.css({top:"0px",left:"0px",width:this.width+"px",height:this.height+"px",position:"absolute"});this.selectcanvas.get(0).height=this.height;this.selectcanvas.get(0).width=this.width}if(this.ccengineSupport)f.ccengine=new f.n250({forceSync:this.forceSyncSmoothing,
log:this.log});this.setAction(f.C.n177)};c.prototype={n0f6:function(){this.canvas3d.css({top:this.top_+"px",left:this.left_+"px",height:this.height+"px",width:this.width+"px",position:"absolute",zIndex:"0"}).hide();this.canvas3d.get(0).height=this.height;this.canvas3d.get(0).width=this.width},n101:function(){this.canvas2d=y("<canvas></canvas>").css({top:this.top_+"px",left:this.left_+"px",height:this.height+"px",width:this.width+"px",position:"absolute",zIndex:"0"}).hide();this.canvas2d.get(0).height=
this.height;this.canvas2d.get(0).width=this.width;this.canvas2d.attr("class",this.canvas3d.attr("class"));this.canvas2d.attr("id",this.canvas3d.attr("id"));y("body").prepend(this.canvas2d)},n12f:function(){this.n27f=this.projection==f.C.proj_perspective?f.m4.perspective(this.zoom,this.aspect,this.near,this.far):f.m4.orthographic(-this.xmax,this.xmax,-this.ymax,this.ymax,this.near,this.far);this.n261=this.camera.matrix;this.n27e=f.m4.n26b(this.n261);this.n27e=f.m4.n22b(this.n27e);this.n159()},n0b6:function(){var b=
f.v3.sub(this.camera.target,this.camera.position),d=_(b).map(Math.abs);this.n1b5=d.indexOf(_(d).max());this.alignedDir=b[this.n1b5]/Math.abs(b[this.n1b5]);b=this.n21b([0,0,0]);d=f.v3.sub(this.n21b([0,1,0]),b);d=_(d).map(Math.abs);this.n265=d.indexOf(_(d).max());b=f.v3.sub(this.n21b([1,0,0]),b);b=_(b).map(Math.abs);this.n23a=b.indexOf(_(b).max())},setSnapToGrid:function(b){this.snapToGrid=b},getSnapToGrid:function(){return this.snapToGrid},n08c:function(b){this._jq&&this._jq.trigger("projection_changed",
b);this.setProjection(b)},performProjection:function(b){this.model.do_({type:f.C.n0a1,oldprojection:this.projection,newprojection:b});this.setProjection(b)},setProjection:function(b){this.ymax=b===f.C.proj_perspective?this.near*Math.tan(this.zoom*Math.PI/360):5;this.xmax=this.ymax*this.aspect;this.update({projection:b})},getProjection:function(){return this.projection},n061:function(b,d){this.setDirectionalLightDirection(b,d);this._jq.trigger("dirlight_dir_changed",{newdir:b})},n062:function(b){this.model.do_({type:f.C.n0cb,
mod_type:"direction",mod:{olddirection:this.dirLightDirection,newdirection:b}});this.setDirectionalLightDirection(b,true)},setDirectionalLightDirection:function(b,d){this.dirLightDirection=b;this.setModelDirty(d);this.draw()},getDirectionalLightDirection:function(){return this.dirLightDirection},n065:function(b,d){this.setPointLightPosition(b,d);this._jq.trigger("pointlight_pos_changed",{newpos:b})},n06a:function(b){this.model.do_({type:f.C.n0a6,mod_type:"position",mod:{oldposition:this.getPointLightPosition(),
newposition:b}});this.setPointLightPosition(b,true)},setPointLightPosition:function(b,d){this.pointLightPosition=f.v3.mul(b,k);this.setModelDirty(d);this.draw()},getPointLightPosition:function(){return _(f.v3.mul(this.pointLightPosition,1/k)).map(Math.round)},showLightPosition:function(){this.n19b.clear();this.n19b.isSolid=false;this.n19b.n0fc([this.getPointLightPosition()]);this.n141=true;this.draw()},hideLightPosition:function(){this.n19b.clear();this.n141=false;this.draw()},n06b:function(b,d){this.setBackgroundColor(b,
d);this._jq.trigger("background_col_changed",{newcol:b})},n074:function(b){this.model.do_({type:f.C.n082,oldcolor:this.backgroundColor,newcolor:b});this.setBackgroundColor(b,true)},setBackgroundColor:function(b,d){this.backgroundColor=b;this.setModelDirty(d);this.draw()},getBackgroundColor:function(){return this.backgroundColor},n08f:function(b,d,e){this.setLightColor(b,d,e);var g;switch(b){case f.C.lighttype_directional:g="dirlight_col_changed";break;case f.C.lighttype_point:g="pointlight_col_changed";
break;case f.C.lighttype_ambient:g="amblight_col_changed";break}this._jq.trigger(g,{newcol:d})},n0a8:function(b,d){var e={mod_type:"color",mod:{newcolor:d}};switch(b){case f.C.lighttype_directional:e.type=f.C.n0cb;e.mod.oldcolor=this.dirLightColor;break;case f.C.lighttype_point:e.type=f.C.n0a6;e.mod.oldcolor=this.pointLightColor;break;case f.C.lighttype_ambient:e.type=f.C.n0bb;e.mod.oldcolor=this.ambientLightColor;break}this.model.do_(e);this.setLightColor(b,d,true)},setLightColor:function(b,d,e){switch(b){case f.C.lighttype_directional:this.dirLightColor=
d;break;case f.C.lighttype_point:this.pointLightColor=d;break;case f.C.lighttype_ambient:this.ambientLightColor=d;break}this.setModelDirty(e);this.draw()},getLightColor:function(b){switch(b){case f.C.lighttype_directional:return this.dirLightColor;case f.C.lighttype_point:return this.pointLightColor;case f.C.lighttype_ambient:return this.ambientLightColor;default:return null}},getBackend:function(){return this.n2bc?"WebGL":"Canvas2D"},update:function(b){y.extend(this,b);if(b.projection||b.ymax||b.xmax||
b.zoom){this.n12f();this.n0b6();y(this.canvas).trigger("view_changed",this);this.draw()}},importPNG:function(b,d,e){this.voxelizer=new f.n218(b,d,e,this);y(this.canvas).trigger("model_changed",this.model);this.adjustView(f.C.cam_view_right);this.setAction(f.C.n177);this.setGridOn(false);this.setMirrorOn(true)},n0e7:function(b){for(var d=true,e=this.n17d.length,g=0;g<e;g++){var h=this.n17d[g];if(h.r===b.r&&h.g===b.g&&h.b===b.b&&h.a===b.a){d=false;break}}if(d){this.n17d.splice(0,0,b);this.n17d.length>
f.C.n102&&this.n17d.pop()}},setCurrentColor:function(b){this.n175=typeof b==="number"?this.n17d[b]:b;this.n0e7(this.n175);this.geometry&&this.geometry.n22f(this.n175)},n10e:function(){return this.n175},getColorPalette:function(){return this.n17d},getX:function(b){return b.clientX-this.left_},getY:function(b){return b.clientY-this.top_},n268:function(b){var d=this.getX(b);b=this.height-this.getY(b);d=f.n0c1(d,b,this.width,this.height,this);return new f.Ray(d[0],d[1])},n19f:function(b){b=this.xzn2a9.n1fd(this.n268(b));
if(!b)throw new Error(f.C.n073);return this.n21b(b)},n159:function(){var b=f.m4.n2b4(this.n261,[0,0,0]),d=f.m4.n2b4(this.n261,[1,0,0]),e=f.m4.n2b4(this.n261,[0,0,1]);this.xzn2a9=new f.n2a9([b,e,d])},project:function(b){return f.m4.n2b4(this.n261,b)},n21b:function(b){var d=f.m4.n26b(this.n261);return f.m4.n2b4(d,b)},n0c3:function(){this.tmpGridFlag=this.gridOn;this.n141=this.gridOn=false;this.draw()},n0aa:function(){this.gridOn=this.tmpGridFlag;this.draw()},setAction:function(b){this.model&&this.model.unfadeAllGeometries();
this.selectcanvas.hide();switch(b){case f.C.n1d1:this.model.forceCubicle();this.n141=true;this.n19b.isSolid=true;this.model.setForm(f.C.model_form_solid);this.canvas.css({cursor:"crosshair"});break;case f.C.n136:this.model.forceCubicle();this.n141=true;this.n19b.isSolid=true;this.model.setForm(f.C.model_form_solid);this.canvas.css({cursor:"crosshair"});break;case f.C.n165:this.model.forceCubicle();this.n141=false;this.n19b.isSolid=false;this.model.setForm(f.C.model_form_solid);this.canvas.css({cursor:"crosshair"});
break;case f.C.n16b:this.model.forceCubicle();this.n141=false;this.n19b.isSolid=false;this.model.setForm(f.C.model_form_solid);this.canvas.css({cursor:"crosshair"});break;case f.C.n148:this.n141=false;this.selectcanvas.show();this.canvas.css({cursor:"crosshair"});break;case f.C.n0f0:this.model.forceCubicle();this.n141=true;this.n19b.isSolid=false;this.model.setForm(f.C.model_form_solid);this.canvas.css({cursor:"crosshair"});break;case f.C.n145:break;case f.C.action_manifold_review:break;case f.C.n177:this.model&&
this.model.unforceCubicle();this.n141=false;this.model.setForm(f.C.model_form_solid);this.canvas.css({cursor:"move"});break;case f.C.n1db:this.n141=false;this.canvas.css({cursor:"auto"});break;default:throw"tin.E.invalid_action";}this.action=b;y(this.canvas).trigger("model_changed",this.model)},n0af:function(){return!this.n2bc&&this.model.n1c9.length<100||this.n2bc&&this.model.n1c9.length<500},draw:function(){f.AxisDial.update(this);if(this.n2bc){f.n2be.clear({dirLightDirection:this.dirLightDirection,
pointLightPosition:f.m4.n2b4(this.n261,this.pointLightPosition),ambientLightColor:this.ambientLightColor,dirLightColor:this.dirLightColor,pointLightColor:this.pointLightColor,backgroundColor:this.backgroundColor});this.gridOn&&this.grid&&this.grid.draw();this.model&&this.model.draw();this.n0bc&&this.n0bc.draw(this);this.n141&&this.n19b.draw()}else{f.n2c0.clear(this.canvas);this.gridOn&&this.grid&&this.grid.draw();if(this.model)this.model.draw(this.n141?this.n19b:null,this.n0bc)}},setModelDirty:function(b){this.model.n278=
b},isModelDirty:function(){return this.model&&this.model.n278},getModelCenter:function(){return this.model?this.model.getCenter():[0,0,0]},n214:function(){this.canvas.bind("mousewheel",{view:this},f.Controller.onMouseWheel);this.canvas.mouseup({view:this},f.Controller.onMouseUp);this.canvas.mousedown({view:this},f.Controller.onMouseDown);this.canvas.mousemove({view:this},f.Controller.onMouseMove);if(this.selectcanvas){this.selectcanvas.mouseup({view:this},f.Controller.onMouseUp);this.selectcanvas.mousedown({view:this},
f.Controller.onMouseDown);this.selectcanvas.mousemove({view:this},f.Controller.onMouseMove)}},setMirrorOn:function(b){this.n260=b;this.draw()},isMirrorOn:function(){return this.n260},setGridOn:function(b){this.gridOn=b;this.draw()},isGridOn:function(){return this.gridOn},setCurrentGeometry:function(b,d,e){if(_.isNull(b))this.geometry=null;else if(typeof b=="number"){this.geometry=new f.n18e(b,this.model,this,this.n175,d);this.geometry.translate([0,0,0])}else if(typeof b=="string"){var g=f.C.min_align;
this.geometry=new f.n18e(b,this.model,this,this.n175,d,{mesh:e,alignment:{x:g,y:g,z:g}});this.geometry.alignToGrid()}},n079:function(b){this.model.n0a3();var d=this.model.get2dExtentsInfo();d=_(d).chain().select(function(e){return e.xmin>b.xmin&&e.xmax<b.xmax&&e.ymin>b.ymin&&e.ymax<b.ymax&&e.geometry.geomType!=f.C.n0b2},this).map(function(e){return e.geometry}).value();_(d).invoke("focus",{r:0,g:0,b:255});this.draw();return d},createTempn14d:function(b){return this.model.n11c(b,f.C.temp_group_uid)},
destroyTempn14d:function(b){this.model.n115(b)},undo:function(){try{this.model.undo()}catch(b){this.error(b,"Undo")}y(this.canvas).trigger("model_changed",this.model)},redo:function(){try{this.model.redo()}catch(b){this.error(b,"Redo")}y(this.canvas).trigger("model_changed",this.model)},adjustView:function(b,d){this.camera.adjustView(b,d)},modelToString:function(){return this.model.toString()},modelFromString:function(b,d){var e=this;try{var g=y.parseJSON(b)}catch(h){this.error(h,"Corrupt Document");
throw new Error(f.C.exception_corrupt_file);}this._jq.trigger("sketchelem_load_started");this.model.preprocessJSON(g,function(j){if(j)d&&d(j);else e.model.fromJSON(g,function(){y(e.canvas).trigger("model_changed",e.model);d&&d()})})},resetModel:function(){this.model=this.modelClass?new this.modelClass:this.n2bc?new f.n0d2:new f.n0dd;this.model.n286(this);this.mode=n.mode;y(this.canvas).trigger("model_changed",this.model)},ren286:function(){this.n08c(n.projection);this.setLightColor(f.C.lighttype_directional,
n.dirLightColor,false);this.setLightColor(f.C.lighttype_point,n.pointLightColor,false);this.setLightColor(f.C.lighttype_ambient,n.ambientLightColor,false);this.setDirectionalLightDirection(n.dirLightDirection,false);this.setPointLightPosition(n.pointLightPosition,false);this.setBackgroundColor(n.backgroundColor,false)},resetState:function(){this.setAction(f.C.n177);this.model.n0a3();this.draw()},getThumbnail:function(b,d){return this.getScreenshot(b,d,false,"image/jpeg")},getScreenshot:function(b,
d,e,g){b=b||this.canvas.width();d=d||this.canvas.height();var h=document.createElement("canvas");h.width=b;h.height=d;var j=h.getContext("2d"),p;if(e){p=this.backgroundColor;this.backgroundColor={r:0,g:0,b:0,a:0}}this.n0c3();j.drawImage(this.canvas.get(0),0,0,b,d);this.n0aa();if(e)this.backgroundColor=p;return h.toDataURL(g?g:"image/png")},zoomIn:function(){f.Controller.n1b3(this)},zoomOut:function(){f.Controller.n171(this)},getSmoothness:function(){return this.model.smoothness},getCameraPosition:function(){return this.camera.position},
getCameraTarget:function(){return this.camera.target},setCameraPosition:function(b){this.camera.update({position:b})},setCameraTarget:function(b){this.camera.update({target:b})},resetCamera:function(){var b=this,d=f.v3.sub(f.Camera.defaults.target,this.camera.target);this.animateCamera({dposition:f.v3.sub(f.Camera.defaults.position,this.camera.position),dtarget:d,interval:1E3},function(){b.resetZoom()})},resetZoom:function(){function b(){var s=(new Date).getTime(),E=(s-e)/g;if(d.projection===f.C.proj_orthographic){E=
h+E*j;var w=E*d.aspect;d.update({ymax:E,xmax:w})}else{var D=p+E*o;E=d.near*Math.tan(d.zoom*Math.PI/360);w=d.ymax*d.aspect;d.update({zoom:D,ymax:E,xmax:w})}s-e<g&&setTimeout(b,f.C.n0d7)}var d=this,e=(new Date).getTime(),g=1E3;if(d.projection===f.C.proj_orthographic)var h=this.ymax,j=n.ymax-h;else var p=this.zoom,o=n.zoom-p;b()},animateCamera:function(b,d){function e(){var o={},s=(new Date).getTime(),E=(s-j.time)/b.interval;if(b.dtarget)o.target=f.v3.add(j.target,f.v3.mul(b.dtarget,E));if(b.dposition)o.position=
f.v3.add(j.position,f.v3.mul(b.dposition,E));o.sph={r:j.r,phi:j.phi,theta:j.theta};if(b.dphi)o.sph.phi=j.phi+E*b.dphi;if(b.dtheta)o.sph.theta=j.theta+E*b.dtheta;g.update(o);if(p.n0a7&&(b.infinite||s-j.time<b.interval))requestAnimationFrame(e);else{p.n0a7=false;d&&d()}}var g=this.camera,h=g.n0e1(),j={time:(new Date).getTime(),position:g.position,target:g.target,r:h.r,phi:h.phi,theta:h.theta},p=this;this.n0a7=true;e()},stopAnimation:function(){this.n0a7=false}};y.fn.tin=function(b){return y(this).each(function(){y.extend(b,
{canvas3d:y(this)});var d=new c(b);y(this).data("instance",d);d._jq=y(this);d.draw();f.Controller.bind(y(this))})}})(jQuery);

