otsdaq_utilities  v2_05_02_indev
JSRootGeoPainter.min.js
1 (function(a){if(typeof define==="function"&&define.amd){define(["d3","JSRootPainter","JSRoot3DPainter","ThreeCSG"],a)}else{if(typeof JSROOT=="undefined"){throw new Error("JSROOT is not defined","JSRootGeoPainter.js")}if(typeof JSROOT.Painter!="object"){throw new Error("JSROOT.Painter is not defined","JSRootGeoPainter.js")}if(typeof d3=="undefined"){throw new Error("d3 is not defined","JSRootGeoPainter.js")}if(typeof THREE=="undefined"){throw new Error("THREE is not defined","JSRootGeoPainter.js")}a(d3,JSROOT)}}(function(b,a){if(typeof define==="function"&&define.amd){a.loadScript("$$$style/JSRootGeoPainter.css")}a.GEO={};a.GEO.createCube=function(d){var f=new THREE.Geometry();f.vertices.push(new THREE.Vector3(d.fDX,d.fDY,d.fDZ));f.vertices.push(new THREE.Vector3(d.fDX,d.fDY,-d.fDZ));f.vertices.push(new THREE.Vector3(d.fDX,-d.fDY,d.fDZ));f.vertices.push(new THREE.Vector3(d.fDX,-d.fDY,-d.fDZ));f.vertices.push(new THREE.Vector3(-d.fDX,d.fDY,-d.fDZ));f.vertices.push(new THREE.Vector3(-d.fDX,d.fDY,d.fDZ));f.vertices.push(new THREE.Vector3(-d.fDX,-d.fDY,-d.fDZ));f.vertices.push(new THREE.Vector3(-d.fDX,-d.fDY,d.fDZ));var i=[0,2,1,2,3,1,4,6,5,6,7,5,4,5,1,5,0,1,7,6,2,6,3,2,5,7,0,7,2,0,1,3,4,3,6,4];var g=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1];var c=new THREE.Color();var e=null;for(var j=0;j<i.length;j+=3){if(j%6===0){e=new THREE.Vector3(g[j/2],g[j/2+1],g[j/2+2])}var h=new THREE.Face3(i[j],i[j+1],i[j+2],e,c,0);f.faces.push(h)}return f};a.GEO.createPara=function(h){var d=h.fTxy,c=h.fTxz,l=h.fTyz;var k=[-h.fZ*c-d*h.fY-h.fX,-h.fY-h.fZ*l,-h.fZ,-h.fZ*c+d*h.fY-h.fX,h.fY-h.fZ*l,-h.fZ,-h.fZ*c+d*h.fY+h.fX,h.fY-h.fZ*l,-h.fZ,-h.fZ*c-d*h.fY+h.fX,-h.fY-h.fZ*l,-h.fZ,h.fZ*c-d*h.fY-h.fX,-h.fY+h.fZ*l,h.fZ,h.fZ*c+d*h.fY-h.fX,h.fY+h.fZ*l,h.fZ,h.fZ*c+d*h.fY+h.fX,h.fY+h.fZ*l,h.fZ,h.fZ*c-d*h.fY+h.fX,-h.fY+h.fZ*l,h.fZ];var e=[4,6,5,4,7,6,0,3,7,7,4,0,4,5,1,1,0,4,6,2,1,1,5,6,7,3,2,2,6,7,1,2,3,3,0,1];var j=new THREE.Geometry();for(var g=0;g<k.length;g+=3){j.vertices.push(new THREE.Vector3(k[g],k[g+1],k[g+2]))}var f=new THREE.Color();for(var g=0;g<e.length;g+=3){j.faces.push(new THREE.Face3(e[g],e[g+1],e[g+2],null,f,0))}j.computeFaceNormals();return j};a.GEO.createTrapezoid=function(e){var h,g;if(e._typename=="TGeoTrd1"){h=g=e.fDY}else{h=e.fDy1;g=e.fDy2}var c=[-e.fDx1,h,-e.fDZ,e.fDx1,h,-e.fDZ,e.fDx1,-h,-e.fDZ,-e.fDx1,-h,-e.fDZ,-e.fDx2,g,e.fDZ,e.fDx2,g,e.fDZ,e.fDx2,-g,e.fDZ,-e.fDx2,-g,e.fDZ];var k=[4,6,5,4,7,6,0,3,7,7,4,0,4,5,1,1,0,4,6,2,1,1,5,6,7,3,2,2,6,7,1,2,3,3,0,1];var j=new THREE.Geometry();for(var f=0;f<24;f+=3){j.vertices.push(new THREE.Vector3(c[f],c[f+1],c[f+2]))}var d=new THREE.Color();for(var f=0;f<36;f+=3){j.faces.push(new THREE.Face3(k[f],k[f+1],k[f+2],null,d,0))}j.computeFaceNormals();return j};a.GEO.createArb8=function(h){var n=[h.fXY[0][0],h.fXY[0][1],-h.fDZ,h.fXY[1][0],h.fXY[1][1],-h.fDZ,h.fXY[2][0],h.fXY[2][1],-h.fDZ,h.fXY[3][0],h.fXY[3][1],-h.fDZ,h.fXY[4][0],h.fXY[4][1],h.fDZ,h.fXY[5][0],h.fXY[5][1],h.fDZ,h.fXY[6][0],h.fXY[6][1],h.fDZ,h.fXY[7][0],h.fXY[7][1],h.fDZ];var e=[];var d=[4,6,5,4,7,6,0,3,7,7,4,0,4,5,1,1,0,4,6,2,1,1,5,6,7,3,2,2,6,7,1,2,3,3,0,1];var l=new THREE.Geometry();for(var g=0;g<8;++g){var o=g*3;if((g>0)&&(n[o]===n[o-3])&&(n[o+1]===n[o-2])&&(n[o+2]===n[o-1])){e[g]=e[g-1];continue}e[g]=l.vertices.length;l.vertices.push(new THREE.Vector3(n[o],n[o+1],n[o+2]))}var f=new THREE.Color();for(var g=0;g<36;g+=3){var m=e[d[g]],k=e[d[g+1]],j=e[d[g+2]];if((m!==k)&&(k!==j)&&(m!==j)){l.faces.push(new THREE.Face3(m,k,j,null,f,0))}}l.computeFaceNormals();return l};a.GEO.createSphere=function(e,o){var z=e.fRmax;var m=e.fRmin;var s=e.fPhi1+180;var w=e.fPhi2-e.fPhi1;var g=e.fTheta1;var t=e.fTheta2-e.fTheta1;var f=e.fNseg;var r=e.fNz;var c=(m<=0);if(o!==undefined){var d=(c?2:4)*f*r/o;if(d>1){f=Math.round(f/Math.sqrt(d));r=Math.round(r/Math.sqrt(d))}}var l=new THREE.SphereGeometry(z,f,r,s*Math.PI/180,w*Math.PI/180,g*Math.PI/180,t*Math.PI/180);l.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2));var h=new THREE.Geometry();var B=new THREE.Color();for(var u=0;u<l.vertices.length;++u){h.vertices.push(l.vertices[u])}for(var u=0;u<l.faces.length;++u){var p=l.faces[u];h.faces.push(new THREE.Face3(p.a,p.b,p.c,null,B,0))}var E=h.vertices.length;if(c){if((t===180)&&(w===360)){h.computeFaceNormals();return h}h.vertices.push(new THREE.Vector3(0,0,0))}else{var A=m/z;for(var u=0;u<l.vertices.length;++u){var q=l.vertices[u];h.vertices.push(new THREE.Vector3(A*q.x,A*q.y,A*q.z))}for(var u=0;u<l.faces.length;++u){var p=l.faces[u];h.faces.push(new THREE.Face3(E+p.b,E+p.a,E+p.c,null,B,0))}}if(t!==180){for(var D=0;D<f;++D){if(c){h.faces.push(new THREE.Face3(D+0,D+1,E,null,B,0))}else{h.faces.push(new THREE.Face3(D+0,D+1,D+E,null,B,0));h.faces.push(new THREE.Face3(D+1,D+E+1,D+E,null,B,0))}}var F=l.vertices.length-f-1;for(var D=F;D<F+f;++D){if(c){h.faces.push(new THREE.Face3(D+0,D+1,E,null,B,0))}else{h.faces.push(new THREE.Face3(D+1,D+0,D+E,null,B,0));h.faces.push(new THREE.Face3(D+E+1,D+1,D+E,null,B,0))}}}if(w!==360){for(var C=0;C<r;C++){var y=C*(f+1);var x=(C+1)*(f+1);if(c){h.faces.push(new THREE.Face3(y,x,E,null,B,0))}else{h.faces.push(new THREE.Face3(x,y,y+E,null,B,0));h.faces.push(new THREE.Face3(x+E,x,y+E,null,B,0))}}for(var C=0;C<r;C++){var y=(C+1)*(f+1)-1;var x=(C+2)*(f+1)-1;if(c){h.faces.push(new THREE.Face3(y,x,E,null,B,0))}else{h.faces.push(new THREE.Face3(y,x,y+E,null,B,0));h.faces.push(new THREE.Face3(x,x+E,y+E,null,B,0))}}}h.computeFaceNormals();return h};a.GEO.createTube=function(e){var g,A,f,z;if((e._typename=="TGeoCone")||(e._typename=="TGeoConeSeg")){g=e.fRmax2;A=e.fRmin2;f=e.fRmax1;z=e.fRmin1}else{g=f=e.fRmax;A=z=e.fRmin}var l=(A>0)||(z>0);if(l){if(A<=0){A=1e-7;console.warn("zero inner radius1 in tube - not yet supported")}if(z<=0){z=1e-7;console.warn("zero inner radius1 in tube - not yet supported")}}var k=0,q=360;if((e._typename=="TGeoConeSeg")||(e._typename=="TGeoTubeSeg")||(e._typename=="TGeoCtub")){k=e.fPhi1;q=e.fPhi2-e.fPhi1}var t=Math.floor(q/6);if(t<4){t=4}var h=(q<360)?1:0;var p=t+h;var B=k*Math.PI/180,d=q/t*Math.PI/180;var j=new Float32Array(p),o=new Float32Array(p);for(var y=0;y<p;++y){o[y]=Math.cos(B+y*d);j[y]=Math.sin(B+y*d)}var m=new THREE.Geometry();if(l){for(var y=0;y<p;++y){m.vertices.push(new THREE.Vector3(A*o[y],A*j[y],e.fDZ))}for(var y=0;y<p;++y){m.vertices.push(new THREE.Vector3(z*o[y],z*j[y],-e.fDZ))}}else{m.vertices.push(new THREE.Vector3(0,0,e.fDZ));m.vertices.push(new THREE.Vector3(0,0,-e.fDZ))}var w=m.vertices.length;for(var y=0;y<p;++y){m.vertices.push(new THREE.Vector3(g*o[y],g*j[y],e.fDZ))}for(var y=0;y<p;++y){m.vertices.push(new THREE.Vector3(f*o[y],f*j[y],-e.fDZ))}if(e._typename=="TGeoCtub"){for(var r=0;r<m.vertices.length;++r){var x=m.vertices[r];if(x.z<0){x.z=-e.fDz-(x.x*e.fNlow[0]+x.x*e.fNlow[1])/e.fNlow[2]}else{x.z=e.fDz-(x.y*e.fNhigh[0]+x.y*e.fNhigh[1])/e.fNhigh[2]}}}var u=new THREE.Color();if(l){for(var y=0;y<t;++y){var c=(h===1)?(y+1):(y+1)%t;m.faces.push(new THREE.Face3(p+y,y,c,null,u,0));m.faces.push(new THREE.Face3(p+y,c,p+c,null,u,0))}}for(var y=0;y<t;++y){var c=(h===1)?(y+1):(y+1)%t;m.faces.push(new THREE.Face3(w+y,w+p+y,w+c,null,u,0));m.faces.push(new THREE.Face3(w+p+y,w+p+c,w+c,null,u,0))}for(var v=0;v<t;++v){var s=(h===1)?(v+1):(v+1)%t;if(l){m.faces.push(new THREE.Face3(v,v+w,s,null,u,0));m.faces.push(new THREE.Face3(v+w,s+w,s,null,u,0))}else{m.faces.push(new THREE.Face3(0,v+w,s+w,null,u,0))}}for(var v=0;v<t;++v){var s=(h===1)?(v+1):(v+1)%t;if(l){m.faces.push(new THREE.Face3(p+v+w,p+v,p+s,null,u,0));m.faces.push(new THREE.Face3(p+v+w,p+s,p+s+w,null,u,0))}else{m.faces.push(new THREE.Face3(p+v+w,1,p+s+w,null,u,0))}}if(h===1){if(l){m.faces.push(new THREE.Face3(0,p,w+p,null,u,0));m.faces.push(new THREE.Face3(0,w+p,w,null,u,0))}else{m.faces.push(new THREE.Face3(0,1,w+p,null,u,0));m.faces.push(new THREE.Face3(0,w+p,w,null,u,0))}if(l){m.faces.push(new THREE.Face3(t,w+2*t+1,2*t+1,null,u,0));m.faces.push(new THREE.Face3(t,w+t,w+2*t+1,null,u,0))}else{m.faces.push(new THREE.Face3(0,w+2*t+1,1,null,u,0));m.faces.push(new THREE.Face3(0,w+t,w+2*t+1,null,u,0))}}m.computeFaceNormals();return m};a.GEO.createEltu=function(h){var j=new THREE.Geometry();var d=Math.floor(360/6);var k=new Float32Array(d),i=new Float32Array(d);for(var f=0;f<d;++f){var g=f/d*2*Math.PI;k[f]=h.fRmin*Math.cos(g);i[f]=h.fRmax*Math.sin(g)}for(var f=0;f<d;++f){j.vertices.push(new THREE.Vector3(k[f],i[f],-h.fDZ))}j.vertices.push(new THREE.Vector3(0,0,-h.fDZ));for(var f=0;f<d;++f){j.vertices.push(new THREE.Vector3(k[f],i[f],+h.fDZ))}j.vertices.push(new THREE.Vector3(0,0,h.fDZ));var e=new THREE.Color();for(var f=0;f<d;++f){var l=(f+1)%d;j.faces.push(new THREE.Face3(f+d+1,f,l,null,e,0));j.faces.push(new THREE.Face3(f+d+1,l,l+d+1,null,e,0))}for(var f=0;f<d;++f){j.faces.push(new THREE.Face3(f,d,(f+1)%d,null,e,0))}var c=d+1;for(var f=0;f<d;++f){j.faces.push(new THREE.Face3(c+f,c+(f+1)%d,c+d,null,e,0))}j.computeFaceNormals();return j};a.GEO.createTorus=function(d,k){var f=d.fR;var z=d.fRmin;var y=d.fRmax;var i=d.fDphi-d.fPhi1;var s=d.fPhi1;var e=30;var m=Math.floor(i/6);if(m<8){m=8}var g=z>0,w=i!==360;if(k!==undefined){var c=(g?4:2)*(e+1)*m/k;if(c>1){e=Math.round(e/Math.sqrt(c));m=Math.round(m/Math.sqrt(c))}}var h=new THREE.Geometry();var t=new THREE.Color();var x=new THREE.TorusGeometry(f,y,e,m,i*Math.PI/180);x.applyMatrix(new THREE.Matrix4().makeRotationZ(s*Math.PI/180));for(var p=0;p<x.vertices.length;++p){h.vertices.push(x.vertices[p])}for(var p=0;p<x.faces.length;++p){var l=x.faces[p];h.faces.push(new THREE.Face3(l.a,l.b,l.c,null,t,0))}var v=h.vertices.length;if(g){var o=new THREE.TorusGeometry(f,z,e,m,i*Math.PI/180);o.applyMatrix(new THREE.Matrix4().makeRotationZ(s*Math.PI/180));for(var p=0;p<o.vertices.length;++p){h.vertices.push(o.vertices[p])}for(var p=0;p<o.faces.length;++p){var l=o.faces[p];h.faces.push(new THREE.Face3(v+l.a,v+l.c,v+l.b,null,t,0))}}else{if(w){h.vertices.push(new THREE.Vector3(f*Math.cos(s*Math.PI/180),f*Math.sin(s*Math.PI/180),0));h.vertices.push(new THREE.Vector3(f*Math.cos((s+i)*Math.PI/180),f*Math.sin((s+i)*Math.PI/180),0))}}if(i!==360){for(var u=0;u<e;u++){var r=u*(m+1);var q=(u+1)*(m+1);if(g){h.faces.push(new THREE.Face3(q,r+v,r,null,t,0));h.faces.push(new THREE.Face3(q,q+v,r+v,null,t,0))}else{h.faces.push(new THREE.Face3(v,r,q,null,t,0))}}for(var u=0;u<e;u++){var r=(u+1)*(m+1)-1;var q=(u+2)*(m+1)-1;if(g){h.faces.push(new THREE.Face3(q,r,r+v,null,t,0));h.faces.push(new THREE.Face3(q,r+v,q+v,null,t,0))}else{h.faces.push(new THREE.Face3(v+1,q,r,null,t,0))}}}h.computeFaceNormals();return h};a.GEO.createPolygon=function(k){var p=k.fPhi1,v=k.fDphi;var w=60;if(k._typename=="TGeoPgon"){w=k.fNedges}else{w=Math.floor(v/6);if(w<4){w=4}}var q=new THREE.Geometry();var x=new THREE.Color();var K=p*Math.PI/180,h=v/w*Math.PI/180;var n=new Float32Array(w+1),r=new Float32Array(w+1);for(var A=0;A<=w;++A){r[A]=Math.cos(K+A*h);n[A]=Math.sin(K+A*h)}var I=[[],[]],u=null,m=null;var O=w;if(v!==360){u=[];m=[];O+=1}var L,J,H,E,D;for(var l=0;l<2;++l){var t=(l===0)?"fRmax":"fRmin";var s=q.vertices.length;for(var N=0;N<k.fNz;++N){I[l][N]=q.vertices.length;var o=k.fZ[N],M=k[t][N];if((N>0)&&(N<k.fNz-1)){if(((k.fZ[N-1]===o)&&(k[t][N-1]===M))||((k[t][N+1]===M)&&(k[t][N-1]===M))){I[l][N]=I[l][N-1];continue}}if(M<=0){M=0.000001}var z=q.vertices.length;for(var A=0;A<O;++A){q.vertices.push(new THREE.Vector3(M*r[A],M*n[A],o))}if(u!==null){if(l===0){u.push(new THREE.Vector2(M,o));m.push(z)}else{if(M<k.fRmax[N]){u.unshift(new THREE.Vector2(M,o));m.unshift(z)}}}if(N>0){for(var A=0;A<w;++A){var g=(A+1)%O;q.faces.push(new THREE.Face3(s+A,(l===0)?(s+g):(z+A),z+g,null,x,0));q.faces.push(new THREE.Face3(s+A,z+g,(l===0)?(z+A):s+g,null,x,0))}}s=z}}for(var N=0;N<k.fNz;N+=(k.fNz-1)){if(k.fRmin[N]>=k.fRmax[N]){continue}var C=I[1][N],G=I[0][N];for(var A=0;A<w;++A){var g=(A+1)%O;q.faces.push(new THREE.Face3(G+A,(N===0)?(C+A):(G+g),C+g,null,x,0));q.faces.push(new THREE.Face3(G+A,C+g,(N===0)?(G+g):(C+A),null,x,0))}}if(u!==null){var j=[];if(u.length===k.fNz*2){for(var N=k.fNz-1;N>0;--N){if(k.fZ[N]===k.fZ[N-1]){continue}var F=2*k.fNz-1-N;j.push([F,N-1,N]);j.push([F,F+1,N-1])}}else{j=THREE.ShapeUtils.triangulateShape(u,[])}for(var y=0;y<j.length;++y){var B=j[y];q.faces.push(new THREE.Face3(m[B[0]],m[B[1]],m[B[2]],null,x,0))}for(var y=0;y<j.length;++y){var B=j[y];q.faces.push(new THREE.Face3(m[B[0]]+w,m[B[2]]+w,m[B[1]]+w,null,x,0))}}q.computeFaceNormals();return q};a.GEO.createXtru=function(l){var o=new THREE.Geometry();var m=new THREE.Color();var f=0,p=0;for(var k=0;k<l.fNz;++k){var c=l.fZ[k],e=l.fScale[k];f=p;p=o.vertices.length;for(var j=0;j<l.fNvert;++j){o.vertices.push(new THREE.Vector3(e*l.fX[j],e*l.fY[j],c))}if(k>0){for(var j=0;j<l.fNvert;++j){var n=(j+1)%l.fNvert;o.faces.push(new THREE.Face3(f+j,p+j,p+n,null,m,0));o.faces.push(new THREE.Face3(f+j,p+n,f+n,null,m,0))}}}var g=[];for(var j=0;j<l.fNvert;++j){g.push(new THREE.Vector2(l.fX[j],l.fY[j]))}var d=THREE.ShapeUtils.triangulateShape(g,[]);for(var h=0;h<d.length;++h){face=d[h];o.faces.push(new THREE.Face3(face[1],face[0],face[2],null,m,0));o.faces.push(new THREE.Face3(face[0]+p,face[1]+p,face[2]+p,null,m,0))}o.computeFaceNormals();return o};a.GEO.createParaboloid=function(f,n){var t=Math.round(360/6),p=30;if(n!==undefined){var e=2*(t+1)*(p+1)/n;if(e>1){t=Math.round(t/Math.sqrt(e));p=Math.round(p/Math.sqrt(e))}}var g=new Float32Array(t),m=new Float32Array(t);for(var w=0;w<t;++w){m[w]=Math.cos(w/t*2*Math.PI);g[w]=Math.sin(w/t*2*Math.PI)}var l=new THREE.Geometry();var j=new THREE.Color();var x=-f.fDZ,z=f.fDZ,s=f.fRlo,u=f.fRhi;if(f.fA>=0){if(f.fB>x){x=f.fB}}else{if(f.fB<z){z=f.fB}}var q=Math.atan2(x,s),r=Math.atan2(z,u);var o=0,i=0;for(var A=0;A<=p+1;++A){var h=z,k=0;if((A===p+1)&&(i===0)){break}switch(A){case 0:h=x;k=s;break;case p:h=z;k=u;break;case p+1:h=z;k=0;break;default:var d=Math.tan(q+(r-q)*A/p);var y=d*d-4*f.fA*f.fB;k=0.5*(d+Math.sqrt(y))/f.fA;if(k<0.000001){k=0}h=k*d}var v=l.vertices.length;if(k===0){l.vertices.push(new THREE.Vector3(0,0,h))}else{for(var w=0;w<t;++w){l.vertices.push(new THREE.Vector3(k*m[w],k*g[w],h))}}if(A>0){for(var w=0;w<t;++w){var c=(w+1)%t;if(i===0){l.faces.push(new THREE.Face3(o,v+c,v+w,null,j,0))}else{if(k==0){l.faces.push(new THREE.Face3(o+w,o+c,v,null,j,0))}else{l.faces.push(new THREE.Face3(o+w,v+c,v+w,null,j,0));l.faces.push(new THREE.Face3(o+w,o+c,v+c,null,j,0))}}}}i=k;o=v}l.computeFaceNormals();return l};a.GEO.createHype=function(e,n){if((e.fTin===0)&&(e.fTout===0)){return a.GEO.createTube(e)}var q=Math.round(360/6),p=30;if(n!==undefined){var d=((e.fRmin<=0)?2:4)*(q+1)*(p+2)/n;if(d>1){q=Math.round(q/Math.sqrt(d));p=Math.round(p/Math.sqrt(d))}}var g=new Float32Array(q),l=new Float32Array(q);for(var t=0;t<q;++t){l[t]=Math.cos(t/q*2*Math.PI);g[t]=Math.sin(t/q*2*Math.PI)}var k=new THREE.Geometry();var h=new THREE.Color();var m=[[],[]];for(var f=0;f<2;++f){if((f===0)&&(e.fRmin<=0)){m[f][0]=k.vertices.length;k.vertices.push(new THREE.Vector3(0,0,-e.fDz));m[f][p]=k.vertices.length;k.vertices.push(new THREE.Vector3(0,0,e.fDz));continue}var o=0;var s=(f===0)?e.fRmin:e.fRmax;var w=(f===0)?e.fTinsq:e.fToutsq;for(var x=0;x<=p;++x){var i=-e.fDz+x/p*2*e.fDz;var j=Math.sqrt(s*s+w*i*i);var r=k.vertices.length;m[f][x]=r;for(var t=0;t<q;++t){k.vertices.push(new THREE.Vector3(j*l[t],j*g[t],i))}if(x>0){for(var t=0;t<q;++t){var c=(t+1)%q;k.faces.push(new THREE.Face3(o+t,(f===0)?(r+t):(o+c),r+c,null,h,0));k.faces.push(new THREE.Face3(o+t,r+c,(f===0)?(o+c):(r+t),null,h,0))}}o=r}}for(var x=0;x<=p;x+=p){var u=m[0][x],v=m[1][x];for(var t=0;t<q;++t){var c=(t+1)%q;if(e.fRmin<=0){k.faces.push(new THREE.Face3(u,v+(x===0?c:t),v+(x===0?t:c),null,h,0))}else{k.faces.push(new THREE.Face3(u+t,(x===0)?(u+c):(v+t),v+c,null,h,0));k.faces.push(new THREE.Face3(u+t,v+c,(x===0)?(v+t):(u+c),null,h,0))}}}k.computeFaceNormals();return k};a.GEO.createMatrix=function(d){if(d===null){return null}var f=null,c=null;if(d._typename=="TGeoTranslation"){f=d.fTranslation}else{if(d._typename=="TGeoRotation"){c=d.fRotationMatrix}else{if(d._typename=="TGeoCombiTrans"){f=d.fTranslation;if(d.fRotation!==null){c=d.fRotation.fRotationMatrix}}else{if(d._typename!=="TGeoIdentity"){console.log("unsupported matrix "+d._typename)}}}}if((f===null)&&(c===null)){return null}var e=new THREE.Matrix4();if(c!==null){e.set(c[0],c[1],c[2],0,c[3],c[4],c[5],0,c[6],c[7],c[8],0,0,0,0,1)}if(f!==null){e.setPosition(new THREE.Vector3(f[0],f[1],f[2]))}return e};a.GEO.createComposite=function(g,j){if(j===undefined){j=10000}var k=a.GEO.createGeometry(g.fNode.fLeft,j/2);k.computeVertexNormals();var c=a.GEO.createMatrix(g.fNode.fLeftMat);if(c!==null){if(c.determinant()<-0.9){console.warn("Axis reflection in composite shape - not supported")}k.applyMatrix(c)}var i=a.GEO.createGeometry(g.fNode.fRight,j/2);i.computeVertexNormals();var l=a.GEO.createMatrix(g.fNode.fRightMat);if(l!==null){if(l.determinant()<-0.9){console.warn("Axis reflection in composite shape - not supported")}i.applyMatrix(l)}var e=new ThreeBSP(k);var d=new ThreeBSP(i);var f=null;if(g.fNode._typename==="TGeoIntersection"){f=e.intersect(d)}else{if(g.fNode._typename==="TGeoUnion"){f=e.union(d)}else{if(g.fNode._typename==="TGeoSubtraction"){f=e.subtract(d)}}}if(f===null){console.warn("unsupported bool operation "+g.fNode._typename+", use first geom");return k}var h=f.toGeometry();return h};a.GEO.createGeometry=function(d,c){switch(d._typename){case"TGeoBBox":return a.GEO.createCube(d);case"TGeoPara":return a.GEO.createPara(d);case"TGeoTrd1":case"TGeoTrd2":return a.GEO.createTrapezoid(d);case"TGeoArb8":case"TGeoTrap":case"TGeoGtra":return a.GEO.createArb8(d);case"TGeoSphere":return a.GEO.createSphere(d,c);case"TGeoCone":case"TGeoConeSeg":case"TGeoTube":case"TGeoTubeSeg":case"TGeoCtub":return a.GEO.createTube(d);case"TGeoEltu":return a.GEO.createEltu(d);case"TGeoTorus":return a.GEO.createTorus(d,c);case"TGeoPcon":case"TGeoPgon":return a.GEO.createPolygon(d);case"TGeoXtru":return a.GEO.createXtru(d);case"TGeoParaboloid":return a.GEO.createParaboloid(d,c);case"TGeoHype":return a.GEO.createHype(d,c);case"TGeoCompositeShape":return a.GEO.createComposite(d,c);case"TGeoShapeAssembly":return new THREE.Geometry()}return null};a.EGeoVisibilityAtt={kVisOverride:a.BIT(0),kVisNone:a.BIT(1),kVisThis:a.BIT(2),kVisDaughters:a.BIT(3),kVisOneLevel:a.BIT(4),kVisStreamed:a.BIT(5),kVisTouched:a.BIT(6),kVisOnScreen:a.BIT(7),kVisContainers:a.BIT(12),kVisOnly:a.BIT(13),kVisBranch:a.BIT(14),kVisRaytrace:a.BIT(15)};a.TestGeoAttBit=function(c,d){if(!("fGeoAtt" in c)){return false}return(c.fGeoAtt&d)!==0};a.ToggleGeoAttBit=function(c,d){if(!("fGeoAtt" in c)){return false}c.fGeoAtt=c.fGeoAtt^(d&16777215)};a.TGeoPainter=function(c){if((c!==null)&&(c._typename.indexOf("TGeoVolume")===0)){c={_typename:"TGeoNode",fVolume:c,fName:"TopLevel"}}a.TObjectPainter.call(this,c);this.Cleanup(true)};a.TGeoPainter.prototype=Object.create(a.TObjectPainter.prototype);a.TGeoPainter.prototype.CreateToolbar=function(d){if(this._toolbar!==null){return}var c=this;var e=[{name:"toImage",title:"Save as PNG",icon:a.ToolbarIcons.camera,click:function(){var g=c._renderer.domElement.toDataURL("image/png");g.replace("image/png","image/octet-stream");var f=document.createElement("a");if(typeof f.download==="string"){document.body.appendChild(f);f.download="geometry.png";f.href=g;f.click();document.body.removeChild(f)}}}];this._toolbar=new a.Toolbar(this.select_main(),[e])};a.TGeoPainter.prototype.decodeOptions=function(d){var c={_grid:false,_bound:false,_debug:false,_full:false,maxlvl:-1,_axis:false,scale:new THREE.Vector3(1,1,1)};var e=a.GetUrlOption("_grid");if(e!==null&&e=="true"){c._grid=true}var e=a.GetUrlOption("_debug");if(e!==null&&e=="true"){c._debug=true;c._grid=true}if(e!==null&&e=="bound"){c._debug=true;c._grid=true;c._bound=true}if(e!==null&&e=="full"){c._debug=true;c._grid=true;c._full=true;c._bound=true}d=d.toLowerCase();if(d.indexOf("all")>=0){c.maxlvl=9999;d=d.replace("all"," ")}if(d.indexOf("limit")>=0){c.maxlvl=1111;d=d.replace("limit"," ")}if(d.indexOf("invx")>=0){c.scale.x=-1;d=d.replace("invx"," ")}if(d.indexOf("invy")>=0){c.scale.y=-1;d=d.replace("invy"," ")}if(d.indexOf("invz")>=0){c.scale.z=-1;d=d.replace("invz"," ")}var f=d.indexOf("maxlvl");if(f>=0){c.maxlvl=parseInt(d.substr(f+6,1));d=d.replace("maxlvl"+c.maxlvl," ")}if(d.indexOf("d")>=0){c._debug=true}if(d.indexOf("g")>=0){c._grid=true}if(d.indexOf("b")>=0){c._bound=true}if(d.indexOf("f")>=0){c._full=true}if(d.indexOf("a")>=0){c._axis=true;c._yup=false}if(d.indexOf("y")>=0){c._yup=true}if(d.indexOf("z")>=0){c._yup=false}return c};a.TGeoPainter.prototype.addControls=function(){if(this._controls!==null){return}var d=this;this.select_main().property("flex_block_drag",true);this._controls=new THREE.OrbitControls(this._camera,this._renderer.domElement);this._controls.enableDamping=false;this._controls.dampingFactor=0.25;this._controls.enableZoom=true;this._controls.target.copy(this._lookat);this._controls.update();this._controls.addEventListener("change",function(){d.Render3D(0)});if(this.options._debug||this.options._grid){this._tcontrols=new THREE.TransformControls(this._camera,this._renderer.domElement);this._scene.add(this._tcontrols);this._tcontrols.attach(this._toplevel);window.addEventListener("keydown",function(h){switch(h.keyCode){case 81:d._tcontrols.setSpace(d._tcontrols.space==="local"?"world":"local");break;case 17:d._tcontrols.setTranslationSnap(Math.ceil(d._overall_size)/50);d._tcontrols.setRotationSnap(THREE.Math.degToRad(15));break;case 84:d._tcontrols.setMode("translate");break;case 82:d._tcontrols.setMode("rotate");break;case 83:d._tcontrols.setMode("scale");break;case 187:case 107:d._tcontrols.setSize(d._tcontrols.size+0.1);break;case 189:case 109:d._tcontrols.setSize(Math.max(d._tcontrols.size-0.1,0.1));break}});window.addEventListener("keyup",function(h){switch(h.keyCode){case 17:d._tcontrols.setTranslationSnap(null);d._tcontrols.setRotationSnap(null);break}});this._tcontrols.addEventListener("change",function(){d.Render3D(0)})}var e=new THREE.Raycaster(),c=null;function f(j){e.setFromCamera(j,d._camera);var m=e.intersectObjects(d._scene.children,true);if(m.length>0){var l=null;for(var k=0;k<m.length;++k){if("emissive" in m[k].object.material){l=m[k].object;break}}if(l&&c!=l){c=l;var h=c.name;var n=c.parent;while((n!==undefined)&&(n!==null)){if("name" in n){h=n.name+"/"+h}n=n.parent}}}else{}}function g(k){var i=("offsetX" in k)?k.offsetX:k.layerX;var h=("offsetY" in k)?k.offsetY:k.layerY;var j={x:(i/d._renderer.domElement.width)*2-1,y:-(h/d._renderer.domElement.height)*2+1};f(j);k.preventDefault()}this._renderer.domElement.addEventListener("mousemove",g)};a.TGeoPainter.prototype.accountClear=function(){this._num_geom=0;this._num_vertices=0;this._num_faces=0;this._num_meshes=0};a.TGeoPainter.prototype.accountGeom=function(e,d){if(e===null){if(!("unsupported_shapes" in this)){this.unsupported_shapes=[]}if((d!==undefined)&&(this.unsupported_shapes.indexOf(d)<0)){this.unsupported_shapes.push(d);console.warn("Not supported "+d)}return}this._num_geom++;if(("vertices" in e)&&("faces" in e)){this._num_vertices+=e.vertices.length;this._num_faces+=e.faces.length}else{var c=e.getAttribute("position")}};a.TGeoPainter.prototype.accountMesh=function(c){if(c!==null){this._num_meshes++}};a.TGeoPainter.prototype.checkFlipping=function(q,p,j,o,c){var h=new THREE.Matrix4();h.multiplyMatrices(q.matrixWorld,p);if(h.determinant()>-0.9){return o}if(c){return null}var g=0,i=new THREE.Vector3(1,1,1);if(h.elements[0]===-1&&h.elements[1]===0&&h.elements[2]===0){i.x=-1;g++}if(h.elements[4]===0&&h.elements[5]===-1&&h.elements[6]===0){i.y=-1;g++}if(h.elements[8]===0&&h.elements[9]===0&&h.elements[10]===-1){i.z=-1;g++}if((g===0)||(g===2)){i.set(1,1,1);g=0;if(h.elements[0]+h.elements[1]+h.elements[2]===-1){i.x=-1;g++}if(h.elements[4]+h.elements[5]+h.elements[6]===-1){i.y=-1;g++}if(h.elements[8]+h.elements[9]+h.elements[10]===-1){i.z=-1;g++}if((g===0)||(g===2)){i.z=-i.z}}p.scale(i);var e="_geom";if(i.x<0){e+="X"}if(i.y<0){e+="Y"}if(i.z<0){e+="Z"}if(e in j){return j[e]}o=o.clone();o.scale(i.x,i.y,i.z);var l,k;for(var f=0;f<o.faces.length;++f){l=o.faces[f];k=l.b;l.b=l.c;l.c=k}o.computeFaceNormals();j[e]=o;this.accountGeom(o);return o};a.TGeoPainter.prototype.getNodeProperties=function(h,g){var k=h.fVolume;var d={shape:k.fShape,matrix:null};if(("fMatrix" in h)&&(h.fMatrix!==null)){d.matrix=a.GEO.createMatrix(h.fMatrix)}else{if((h._typename=="TGeoNodeOffset")&&(h.fFinder!==null)){if((h.fFinder._typename==="TGeoPatternX")||(h.fFinder._typename==="TGeoPatternY")||(h.fFinder._typename==="TGeoPatternZ")){var i=h.fFinder.fStart+(h.fIndex+0.5)*h.fFinder.fStep;d.matrix=new THREE.Matrix4();switch(h.fFinder._typename.charAt(11)){case"X":d.matrix.setPosition(new THREE.Vector3(i,0,0));break;case"Y":d.matrix.setPosition(new THREE.Vector3(0,i,0));break;case"Z":d.matrix.setPosition(new THREE.Vector3(0,0,i));break}}else{if(h.fFinder._typename==="TGeoPatternCylPhi"){var l=(Math.PI/180)*(h.fFinder.fStart+(h.fIndex+0.5)*h.fFinder.fStep);var e=Math.cos(l),n=Math.sin(l);d.matrix=new THREE.Matrix4();d.matrix.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1)}else{console.warn("Unsupported pattern type "+h.fFinder._typename)}}}}d.material=null;if(g){var m=false,j=1;if((k.fFillColor>1)&&(k.fLineColor==1)){d.fillcolor=a.Painter.root_colors[k.fFillColor]}else{if(k.fLineColor>=0){d.fillcolor=a.Painter.root_colors[k.fLineColor]}}if(("fMedium" in k)&&(k.fMedium!==null)&&("fMaterial" in k.fMedium)&&(k.fMedium.fMaterial!==null)){var c=k.fMedium.fMaterial.fFillStyle;var f=(c<3000||c>3100)?0:c-3000;if(f>0){m=true;j=(100-f)/100}if(d.fillcolor===undefined){d.fillcolor=a.Painter.root_colors[k.fMedium.fMaterial.fFillColor]}}if(d.fillcolor===undefined){d.fillcolor="lightgrey"}d.material=new THREE.MeshLambertMaterial({transparent:m,opacity:j,wireframe:false,color:d.fillcolor,side:THREE.FrontSide,vertexColors:THREE.NoColors,overdraw:0})}return d};a.TGeoPainter.prototype.getEveNodeProperties=function(e,f){var g={shape:e.fShape};g.material=null;if(f){var d=false,c=1;if(e.fRGBA[3]<1){d=true;c=e.fRGBA[3]}g.fillcolor=new THREE.Color(e.fRGBA[0],e.fRGBA[1],e.fRGBA[2]);g.material=new THREE.MeshLambertMaterial({transparent:d,opacity:c,wireframe:false,color:g.fillcolor,side:THREE.FrontSide,vertexColors:THREE.NoColors,overdraw:0})}g.matrix=new THREE.Matrix4();if(e.fTrans!==null){g.matrix.set(e.fTrans[0],e.fTrans[4],e.fTrans[8],0,e.fTrans[1],e.fTrans[5],e.fTrans[9],0,e.fTrans[2],e.fTrans[6],e.fTrans[10],0,0,0,0,1);g.matrix.setPosition({x:e.fTrans[12],y:e.fTrans[13],z:e.fTrans[14]})}return g};a.TGeoPainter.prototype.drawNode=function(){if((this._stack==null)||(this._stack.length==0)){return false}var j=this._stack[this._stack.length-1];var g=this.NodeKind(j.node);if(g<0){return false}var k=null;if(g===0){k=(j.node.fVolume.fNodes!==null)?j.node.fVolume.fNodes.arr:null}else{k=(j.node.fElements!==null)?j.node.fElements.arr:null}if("nchild" in j){if((k===null)||(k.length<=j.nchild)){this._stack.pop()}else{this._stack.push({toplevel:(j.mesh?j.mesh:j.toplevel),node:k[j.nchild++]})}return true}var c=null;if(g===0){c=this.getNodeProperties(j.node,j.node._visible)}else{c=this.getEveNodeProperties(j.node,j.node._visible)}var h=null;if(c.matrix===null){c.matrix=new THREE.Matrix4()}if((c.shape===null)&&j.node._visible){j.node._visible=false}if(j.node._visible){if(typeof c.shape._geom==="undefined"){c.shape._geom=a.GEO.createGeometry(c.shape);this.accountGeom(c.shape._geom,c.shape._typename)}h=c.shape._geom}else{if(this._dummy_material===undefined){this._dummy_material=new THREE.MeshLambertMaterial({transparent:true,opacity:0,wireframe:false,color:"white",vertexColors:THREE.NoColors,overdraw:0,depthWrite:false,depthTest:false,visible:false})}c.material=this._dummy_material}var d=(k!==null)&&(k.length>0);var i=false;if(j.main&&(this.options.scale!==null)){if((this.options.scale.x<0)||(this.options.scale.y<0)||(this.options.scale.z<0)){c.matrix.scale(this.options.scale)}}if(j.node._visible&&(h!==null)){h=this.checkFlipping(j.toplevel,c.matrix,c.shape,h,d);i=d&&(h===null)}if(h===null){h=new THREE.Geometry()}var m=new THREE.Mesh(h,c.material);m.applyMatrix(c.matrix);this.accountMesh(m);m.name=j.node.fName;j.toplevel.add(m);m.updateMatrixWorld();if(i){a.console("perform workaroud for flipping mesh with childs");c.matrix.identity();h=this.checkFlipping(m,c.matrix,c.shape,c.shape._geom,false);var f=new THREE.Mesh(h,c.material);f.applyMatrix(c.matrix);f.name="..";m.add(f);f.updateMatrixWorld()}if(this.options._debug&&(j.node._visible||this.options._full)){var e=new THREE.WireframeHelper(m);e.material.color.set(c.fillcolor);e.material.linewidth=("fVolume" in j.node)?j.node.fVolume.fLineWidth:1;j.toplevel.add(e)}if(this.options._bound&&(j.node._visible||this.options._full)){var l=new THREE.BoxHelper(m);j.toplevel.add(l)}j.mesh=m;if((k===null)||(k.length==0)){this._stack.pop()}else{j.nchild=0}return true};a.TGeoPainter.prototype.NodeKind=function(c){if((c===undefined)||(c===null)||(typeof c!=="object")){return -1}return("fShape" in c)&&("fTrans" in c)?1:0};a.TGeoPainter.prototype.CountGeoVolumes=function(k,d,f){var h=this.NodeKind(k);if(h<0){return 0}if(f===undefined){f=0;if(!d){d={erase:true}}if(!("map" in d)){d.map=[]}d.viscnt=0;if(!("clear" in d)){d.clear=function(){for(var i=0;i<this.map.length;++i){delete this.map[i]._refcnt;delete this.map[i]._numchld;delete this.map[i]._visible}this.map=[];this.viscnt=0}}}var c=null,e=null,j=false;if(h===0){if((k.fVolume===undefined)||(k.fVolume===null)){return 0}e=k.fVolume.fShape;c=(k.fVolume.fNodes!==null)?k.fVolume.fNodes.arr:null;j=a.TestGeoAttBit(k.fVolume,a.EGeoVisibilityAtt.kVisOnScreen)||((f<d.maxlvl)&&a.TestGeoAttBit(k.fVolume,a.EGeoVisibilityAtt.kVisThis))}else{if(k.fShape===undefined){return 0}e=k.fShape;c=(k.fElements!==null)?k.fElements.arr:null;j=k.fRnrSelf}if("cnt" in d){if(d.cnt[f]===undefined){d.cnt[f]=0}d.cnt[f]+=1}if("_refcnt" in k){k._refcnt++}else{k._refcnt=1;k._numchld=0;d.map.push(k);if(j&&!("_visible" in k)&&(e!==null)){k._visible=true;d.viscnt++}if(c!==null){for(var g=0;g<c.length;++g){k._numchld+=this.CountGeoVolumes(c[g],d,f+1)}}}if((f===0)&&d.erase){d.clear()}return 1+k._numchld};a.TGeoPainter.prototype.SameMaterial=function(e,c){if((e===null)||(c===null)){return e===c}if(e.fVolume.fLineColor>=0){return(e.fVolume.fLineColor===c.fVolume.fLineColor)}var f=(e.fVolume.fMedium!==null)?e.fVolume.fMedium["fMaterial"]:null;var d=(c.fVolume.fMedium!==null)?c.fVolume.fMedium["fMaterial"]:null;if(f===d){return true}if((f===null)||(d===null)){return false}return(f.fFillStyle===d.fFillStyle)&&(f.fFillColor===d.fFillColor)};a.TGeoPainter.prototype.ScanUniqueVisVolumes=function(g,l,m){if((g===undefined)||(g===null)||(typeof g!=="object")||(g.fVolume===undefined)||(g.fVolume==null)){return 0}if(l===0){m.master=null;m.vis_unique=true;m.vis_master=null;m.same_material=true}var k=g._visible?1:0;if(g._refcnt>1){m.vis_unique=false}if(m.master!==null){if(!this.SameMaterial(m.master,g)){m.same_material=false}}var h=m.vis_unique;m.vis_unique=true;var c=m.master,e=m.same_material;m.master=g._visible?g:null;m.same_material=true;var j=(g.fVolume.fNodes!==null)?g.fVolume.fNodes.arr:null;var d=0;if(j!==null){for(var f=0;f<j.length;++f){d+=this.ScanUniqueVisVolumes(j[f],l+1,m)}}g._numvis=d;g._visunique=m.vis_unique;g._samematerial=m.same_material;if(g._samematerial){if(e&&(c!=null)&&(m.master!==null)){m.same_material=this.SameMaterial(c,m.master)}else{m.same_material=e}if(c!==null){m.master=c}}else{m.master=null;m.same_material=false}m.vis_unique=h&&g._visunique;return k+d};a.TGeoPainter.prototype.createScene=function(g,c,f,e){this._scene=new THREE.Scene();this._scene.fog=new THREE.Fog(16777215,500,300000);this._scene_width=c;this._scene_height=f;this._camera=new THREE.PerspectiveCamera(25,c/f,1,100000);this._renderer=g?new THREE.WebGLRenderer({antialias:true,logarithmicDepthBuffer:true,preserveDrawingBuffer:true}):new THREE.CanvasRenderer({antialias:true});this._renderer.setPixelRatio(e);this._renderer.setClearColor(16777215,1);this._renderer.setSize(c,f);var d=new THREE.PointLight(15724527);this._camera.add(d);d.position.set(10,10,10);this._camera.up=this.options._yup?new THREE.Vector3(0,1,0):new THREE.Vector3(0,0,1);this._scene.add(this._camera);this._toplevel=new THREE.Object3D();this._scene.add(this._toplevel);this._overall_size=10};a.TGeoPainter.prototype.startDrawGeometry=function(){if(this.MatchObjectType("TGeoNode")){this._nodedraw=true;this._stack=[{toplevel:this._toplevel,node:this.GetObject(),main:true}]}else{if(this.MatchObjectType("TEveGeoShapeExtract")){this._nodedraw=false;this._stack=[{toplevel:this._toplevel,node:this.GetObject(),main:true}]}}this.accountClear()};a.TGeoPainter.prototype.adjustCameraPosition=function(){var h=new THREE.Box3().setFromObject(this._toplevel);var e=h.max.x-h.min.x,c=h.max.y-h.min.y,i=h.max.z-h.min.z,g=(h.max.x+h.min.x)/2,f=(h.max.y+h.min.y)/2,d=(h.max.z+h.min.z)/2;this._overall_size=2*Math.max(e,c,i);this._camera.near=this._overall_size/500;this._camera.far=this._overall_size*500;this._camera.updateProjectionMatrix();if(this.options._yup){this._camera.position.set(g-2*Math.max(e,i),f+2*c,d-2*Math.max(e,i))}else{this._camera.position.set(g-2*Math.max(e,c),f-2*Math.max(e,c),d+2*i)}this._lookat=new THREE.Vector3(g,f,d);this._camera.lookAt(this._lookat);if(this._controls!==null){this._controls.target.copy(this._lookat);this._controls.update()}};a.TGeoPainter.prototype.completeScene=function(){if(this.options._debug||this.options._grid){if(this.options._full){var c=new THREE.BoxHelper(this._toplevel);this._scene.add(c)}this._scene.add(new THREE.AxisHelper(2*this._overall_size));this._scene.add(new THREE.GridHelper(Math.ceil(this._overall_size),Math.ceil(this._overall_size)/50));this.helpText("<font face='verdana' size='1' color='red'><center>Transform Controls<br>'T' translate | 'R' rotate | 'S' scale<br>'+' increase size | '-' decrease size<br>'W' toggle wireframe/solid display<br>keep 'Ctrl' down to snap to grid</center></font>")}};a.TGeoPainter.prototype.drawCount=function(){var e=new Date();var d={cnt:[],maxlvl:-1};var h=this.CountGeoVolumes(this.GetObject(),d);var g="Total number: "+h+"<br/>";for(var f=0;f<d.cnt.length;++f){if(d.cnt[f]!==0){g+=(" lvl"+f+": "+d.cnt[f]+"<br/>")}}g+="Unique volumes: "+d.map.length+"<br/>";if(d.viscnt===0){d.clear();d.maxlvl=9999;h=this.CountGeoVolumes(this.GetObject(),d)}g+="Visible volumes: "+d.viscnt+"<br/>";if(h<200000){this.ScanUniqueVisVolumes(this.GetObject(),0,d);for(var i=0;i<d.map.length;++i){if(d.map[i]._refcnt>1){g+=(d.map[i]._visible?"vis":"map")+i+" "+d.map[i].fName+" nref:"+d.map[i]._refcnt+" chld:"+d.map[i]._numvis+"("+d.map[i]._numchld+") unique:"+d.map[i]._visunique+" same:"+d.map[i]._samematerial;if(d.map[i]._samematerial){if(d.map[i]._visunique&&(d.map[i]._numvis>0)){g+=" (can merge with childs in Worker)"}else{if((d.map[i]._refcnt>4)&&(d.map[i]._numvis>1)){g+=" (make sense merge in main thread)"}}}g+="<br/>"}}}var c=new Date();g+="Elapsed time: "+(c.getTime()-e.getTime())+"ms <br/>";this.select_main().style("overflow","auto").html(g);return this.DrawingReady()};a.TGeoPainter.prototype.DrawGeometry=function(e){if(typeof e!=="string"){e=""}if(e==="count"){return this.drawCount()}var d=this.size_for_3d();this.options=this.decodeOptions(e);if(!("_yup" in this.options)){this.options._yup=this.svg_canvas().empty()}this._webgl=a.Painter.TestWebGL();this._data={cnt:[],maxlvl:this.options.maxlvl};var g=this.CountGeoVolumes(this.GetObject(),this._data);if((g>0)&&(this._data.viscnt==0)&&(this.options.maxlvl<0)){this._data.clear();this._data.maxlvl=1111;g=this.CountGeoVolumes(this.GetObject(),this._data)}var h=this._webgl?10000000:10000;if((this._data.maxlvl===1111)&&(g>h)){var f=0;for(var c=1;c<this._data.cnt.length;++c){f+=this._data.cnt.cnt[c];if(f>h){this._data.maxlvl=c-1;this._data.clear();this.CountGeoVolumes(this.GetObject(),this._data);break}}}this.createScene(this._webgl,d.width,d.height,window.devicePixelRatio);this.add_3d_canvas(d,this._renderer.domElement);this.startDrawGeometry();this._startm=new Date().getTime();this._drawcnt=0;this.CreateToolbar({container:this.select_main().node()});return this.continueDraw()};a.TGeoPainter.prototype.continueDraw=function(){var f=new Date().getTime();var e="";while(true){if(this.drawNode()){this._drawcnt++;e="Creating meshes "+this._drawcnt}else{break}var c=new Date().getTime();if(c-f>300){a.progress(e);setTimeout(this.continueDraw.bind(this),0);return this}if(c-this._startm>100000){break}}var d=new Date().getTime();a.console("Create tm = "+(d-this._startm)+" geom "+this._num_geom+" vertices "+this._num_vertices+" faces "+this._num_faces+" meshes "+this._num_meshes);if(d-this._startm>300){a.progress("Rendering geometry");setTimeout(this.completeDraw.bind(this,true),0);return this}return this.completeDraw()};a.TGeoPainter.prototype.Render3D=function(e){if(e===undefined){e=5}if(e<=0){if("render_tmout" in this){clearTimeout(this["render_tmout"])}var d=new Date();this._renderer.render(this._scene,this._camera);var c=new Date();delete this["render_tmout"];if(this.first_render_tm===0){this.first_render_tm=c.getTime()-d.getTime();a.console("First render tm = "+this.first_render_tm);this.addControls()}return}if("render_tmout" in this){return}this["render_tmout"]=setTimeout(this.Render3D.bind(this,0),e)};a.TGeoPainter.prototype.completeDraw=function(c){this.adjustCameraPosition();this.completeScene();if(this.options._axis){var e=a.Create("TNamed");e._typename="TAxis3D";e._main=this;a.draw(this.divid,e)}this.Render3D();if(c){a.progress()}this._data.clear();var d=this;var f=this.select_main().node();if(f!==null){f.tabIndex=0;f.focus();f.onkeypress=function(g){if(!g){g=event}switch(g.keyCode){case 87:case 119:d.toggleWireFrame(d._scene);break}};f.onclick=function(g){f.focus()}}return this.DrawingReady()};a.TGeoPainter.prototype.Cleanup=function(c){if(c===undefined){this.helpText();if(this._scene!==null){this.deleteChildren(this._scene)}if(this._tcontrols!==null){this._tcontrols.dispose()}if(this._controls!==null){this._controls.dispose()}}this._scene=null;this._scene_width=0;this._scene_height=0;this._renderer=null;this._toplevel=null;this._stack=null;this._camera=null;this.first_render_tm=0;this._controls=null;this._tcontrols=null;this._toolbar=null};a.TGeoPainter.prototype.helpText=function(c){a.progress(c)};a.TGeoPainter.prototype.CheckResize=function(){var d=this.pad_painter();if(d){if(!d.CheckCanvasResize(size,a.browser.isFirefox?false:true)){return false}}var c=this.size_for_3d();if((this._scene_width===c.width)&&(this._scene_height===c.height)){return false}if((c.width<10)||(c.height<10)){return}this._scene_width=c.width;this._scene_height=c.height;this._camera.aspect=this._scene_width/this._scene_height;this._camera.updateProjectionMatrix();this._renderer.setSize(this._scene_width,this._scene_height);this.Render3D();return true};a.TGeoPainter.prototype.ownedByTransformControls=function(d){var c=d.parent;while(c&&!(c instanceof THREE.TransformControls)){c=c.parent}return(c&&(c instanceof THREE.TransformControls))};a.TGeoPainter.prototype.toggleWireFrame=function(e){var c=this;var d=function(f){if(f.hasOwnProperty("material")&&!(f instanceof THREE.GridHelper)){if(!c.ownedByTransformControls(f)){f.material.wireframe=!f.material.wireframe}}};e.traverse(d);this.Render3D()};a.TGeoPainter.prototype.deleteChildren=function(g){if((typeof g.children!="undefined")&&(g.children instanceof Array)){for(var d=g.children.length-1;d>=0;d--){var c=g.children[d];this.deleteChildren(c);try{g.remove(g.children[d])}catch(f){}try{c.geometry.dispose();c.geometry=null}catch(f){}try{c.material.dispose();c.material=null}catch(f){}try{c.texture.dispose();c.texture=null}catch(f){}c=null;g.children[d]=null}g.children=null}g=null};a.Painter.drawGeometry=function(e,d,c){a.extend(this,new a.TGeoPainter(d));this.SetDivId(e,5);return this.DrawGeometry(c)};a.Painter.drawGeoObject=function(f,e,c){if(e===null){return this.DrawingReady()}var d=null;if(("fShapeBits" in e)&&("fShapeId" in e)){d=a.Create("TEveGeoShapeExtract");a.extend(d,{fTrans:null,fShape:e,fRGBA:[0,1,0,1],fElements:null,fRnrSelf:true})}else{if((e._typename==="TGeoVolumeAssembly")||(e._typename==="TGeoVolume")){d=e}}if(d!==null){a.extend(this,new a.TGeoPainter(d));this.SetDivId(f,5);return this.DrawGeometry(c)}return this.DrawingReady()};a.Painter.drawAxis3D=function(f,e,d){var c=new a.TObjectPainter(e);if(!("_main" in e)){c.SetDivId(f)}c.Draw3DAxis=function(){var g=this.main_painter();if((g===null)&&("_main" in this.GetObject())){g=this.GetObject()._main}if((g===null)||(g._toplevel===undefined)){return console.warn("no geo object found for 3D axis drawing")}var h=new THREE.Box3().setFromObject(g._toplevel);this.xmin=h.min.x;this.xmax=h.max.x;this.ymin=h.min.y;this.ymax=h.max.y;this.zmin=h.min.z;this.zmax=h.max.z;this.options={Logx:false,Logy:false,Logz:false};this.size3d=0;this["DrawXYZ"]=a.Painter.HPainter_DrawXYZ;this.toplevel=g._toplevel;this.DrawXYZ();g.adjustCameraPosition();g.Render3D()};c.Draw3DAxis();return c.DrawingReady()};a.expandGeoList=function(d,c){if((c==null)||!("arr" in c)||(c.arr.length==0)){return}d._more=true;d._geolst=c;d._get=function(e,g,f){if("_geolst" in e){a.CallBack(f,e,e._geolst)}if("_geoobj" in e){return a.CallBack(f,e,e._geoobj)}a.CallBack(f,e,null)};d._expand=function(g,e){if(!("arr" in e)){return false}g._childs=[];for(var i in e.arr){var h=e.arr[i];var f={_kind:"ROOT."+h._typename,_name:h.fName,_title:h.fTitle,_parent:g,_geoobj:h};if(h._typename=="TGeoMaterial"){f._icon="img_geomaterial"}else{if(h._typename=="TGeoMedium"){f._icon="img_geomedium"}else{if(h._typename=="TGeoMixture"){f._icon="img_geomixture"}}}g._childs.push(f)}return true}};a.provideGeoVisStyle=function(d){var c="";if(a.TestGeoAttBit(d,a.EGeoVisibilityAtt.kVisThis)){c+=" geovis_this"}if(a.TestGeoAttBit(d,a.EGeoVisibilityAtt.kVisDaughters)){c+=" geovis_daughters"}return c};a.provideGeoMenu=function(g,d,e){if(!("_volume" in d)){return false}g.add("separator");var c=d._volume;function f(h){a.ToggleGeoAttBit(c,h);d._icon=d._icon.split(" ")[0]+a.provideGeoVisStyle(c);e.UpdateTreeNode(d)}g.addchk(a.TestGeoAttBit(c,a.EGeoVisibilityAtt.kVisNone),"Invisible",a.EGeoVisibilityAtt.kVisNone,f);g.addchk(a.TestGeoAttBit(c,a.EGeoVisibilityAtt.kVisThis),"Visible",a.EGeoVisibilityAtt.kVisThis,f);g.addchk(a.TestGeoAttBit(c,a.EGeoVisibilityAtt.kVisDaughters),"Daughters",a.EGeoVisibilityAtt.kVisDaughters,f);g.addchk(a.TestGeoAttBit(c,a.EGeoVisibilityAtt.kVisOneLevel),"1lvl daughters",a.EGeoVisibilityAtt.kVisOneLevel,f);return true};a.geoIconClick=function(c){if((c==null)||(c._volume==null)){return false}a.ToggleGeoAttBit(c._volume,a.EGeoVisibilityAtt.kVisDaughters);c._icon=c._icon.split(" ")[0]+a.provideGeoVisStyle(c._volume);return true};a.getGeoShapeIcon=function(c){switch(c._typename){case"TGeoArb8":return"img_geoarb8";break;case"TGeoCone":return"img_geocone";break;case"TGeoConeSeg":return"img_geoconeseg";break;case"TGeoCompositeShape":return"img_geocomposite";break;case"TGeoTube":return"img_geotube";break;case"TGeoTubeSeg":return"img_geotubeseg";break;case"TGeoPara":return"img_geopara";break;case"TGeoParaboloid":return"img_geoparab";break;case"TGeoPcon":return"img_geopcon";break;case"TGeoPgon":return"img_geopgon";break;case"TGeoShapeAssembly":return"img_geoassembly";break;case"TGeoSphere":return"img_geosphere";break;case"TGeoTorus":return"img_geotorus";break;case"TGeoTrd1":return"img_geotrd1";break;case"TGeoTrd2":return"img_geotrd2";break;case"TGeoXtru":return"img_geoxtru";break;case"TGeoTrap":return"img_geotrap";break;case"TGeoGtra":return"img_geogtra";break;case"TGeoEltu":return"img_geoeltu";break;case"TGeoHype":return"img_geohype";break;case"TGeoCtub":return"img_geoctub";break}return"img_geotube"};a.expandGeoShape=function(d,c,f){var e={_kind:"ROOT."+c._typename,_name:f,_title:c._typename,_icon:a.getGeoShapeIcon(c),_parent:d,_shape:c,_get:function(g,i,h){if((g!==null)&&("_shape" in g)){return a.CallBack(h,g,g._shape)}a.CallBack(h,g,null)}};if(!("_childs" in d)){d._childs=[]}d._childs.push(e);return true};a.expandGeoVolume=function(f,h,c){if((f==null)||(h==null)){return false}if("_childs" in f){for(var i=0;i<f._childs.length;++i){if(h===f._childs[i]._volume){return true}}}var g={_kind:"ROOT.TGeoVolume",_name:(c!=null)?c:h.fName,_title:h.fTitle,_parent:f,_volume:h,_more:(h.fNodes!==undefined)&&(h.fNodes!==null),_menu:a.provideGeoMenu,_icon_click:a.geoIconClick,_get:function(j,l,k){if((j!=null)&&("_volume" in j)){return a.CallBack(k,j,j._volume)}a.CallBack(k,j,null)}};if(g._more){g._expand=function(k,m){var l=m.fNodes.arr;for(var j in l){a.expandGeoVolume(k,l[j].fVolume)}return true}}else{if((h.fShape!==null)&&(h.fShape._typename==="TGeoCompositeShape")&&(h.fShape.fNode!==null)){g._more=true;g._expand=function(j,k){a.expandGeoShape(j,k.fShape.fNode.fLeft,"Left");a.expandGeoShape(j,k.fShape.fNode.fRight,"Right");return true}}}if(g._title==""){if(h._typename!="TGeoVolume"){g._title=h._typename}}if(h.fShape!==null){if(g._title==""){g._title=h.fShape._typename}g._icon=a.getGeoShapeIcon(h.fShape)}if(!("_childs" in f)){f._childs=[]}if(!("_icon" in g)){g._icon=g._more?"img_geocombi":"img_geobbox"}g._icon+=a.provideGeoVisStyle(h);for(var e=0;e<1000000;e++){var d=g._name;if(d.length==0){d="item"}if(e>0){d+="_"+e}for(var i in f._childs){if(f._childs[i]["_name"]==d){d="";break}}if(d.length>0){if(e>0){g._name=d}break}}f._childs.push(g);return true};a.expandGeoManagerHierarchy=function(f,g){if((f==null)||(g==null)){return false}f._childs=[];var e={_name:"Materials",_kind:"Folder",_title:"list of materials"};a.expandGeoList(e,g.fMaterials);f._childs.push(e);var d={_name:"Media",_kind:"Folder",_title:"list of media"};a.expandGeoList(d,g.fMedia);f._childs.push(d);var c={_name:"Tracks",_kind:"Folder",_title:"list of tracks"};a.expandGeoList(c,g.fTracks);f._childs.push(c);a.expandGeoVolume(f,g.fMasterVolume,"Volume");return true};a.addDrawFunc({name:"TGeoVolumeAssembly",icon:"img_geoassembly",func:a.Painter.drawGeometry,expand:"JSROOT.expandGeoVolume",opt:"all;count;limit;maxlvl2"});a.addDrawFunc({name:"TAxis3D",func:a.Painter.drawAxis3D});return a.Painter}));