/** X3DOM Runtime, http://www.x3dom.org/ 1.7.0 - f33e92d248a2f25d52fa63ede8ffee570c8a6304 - Wed Jun 17 09:49:25 2015 +0200 */
x3dom.registerNodeType("Patch","BVHRefiner",defineClass(x3dom.nodeTypes.X3DSpatialGeometryNode,function(ctx){x3dom.nodeTypes.Patch.superClass.call(this,ctx);this.addField_SFVec2f(ctx,'size',2,2);this.addField_SFVec2f(ctx,'subdivision',1,1);this.addField_SFVec3f(ctx,'center',0,0,0);this.addField_MFString(ctx,'primType',['TRIANGLES']);var sx=this._vf.size.x,sy=this._vf.size.y;var subx=this._vf.subdivision.x,suby=this._vf.subdivision.y;this._indexBufferTriangulationParts=[];var x=0,y=0;var xstep=sx/subx/2;var ystep=sy/suby/2;sx/=2;sy/=2;var countX=subx*2+1;var countY=suby*2+1;for(y=0;y<=suby*2;y++){for(x=0;x<=subx*2;x++){this._mesh._positions[0].push(this._vf.center.x+x*xstep-sx);this._mesh._positions[0].push(this._vf.center.y+y*ystep-sy);this._mesh._positions[0].push(this._vf.center.z);this._mesh._normals[0].push(0);this._mesh._normals[0].push(0);this._mesh._normals[0].push(1);this._mesh._texCoords[0].push(x/(subx*2));this._mesh._texCoords[0].push(y/(suby*2));}}
for(y=0;y<countY-2;y+=2){for(x=0;x<countX-2;x+=2){this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);}}
this._indexBufferTriangulationParts.push({offset:0,count:subx*suby*6});for(y=0;y<countY-2;y+=2){for(x=0;x<2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=0;y<countY-2;y+=2){for(x=2;x<countX-2;x+=2){this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);}}
this._indexBufferTriangulationParts.push({offset:this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].offset+
this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].count*2,count:subx*suby*6+suby*9});for(y=0;y<countY-2;y+=2){for(x=countX-3;x<countX-2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=0;y<countY-2;y+=2){for(x=0;x<countX-4;x+=2){this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);}}
this._indexBufferTriangulationParts.push({offset:this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].offset+
this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].count*2,count:subx*suby*6+suby*9});for(y=2;y<countY-2;y+=2){for(x=0;x<countX-2;x+=2){this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);}}
for(y=0;y<2;y+=2){for(x=0;x<countX-2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+1)+y*countX);this._mesh._indices[0].push((x+1)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
this._indexBufferTriangulationParts.push({offset:this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].offset+
this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].count*2,count:subx*suby*6+subx*9});for(y=countY-3;y<countY-2;y+=2){for(x=0;x<countX-2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=0;y<countY-4;y+=2){for(x=0;x<countX-2;x+=2){this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);}}
this._indexBufferTriangulationParts.push({offset:this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].offset+
this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].count*2,count:subx*suby*6+subx*9});for(y=countY-3;y<countY-2;y+=2){for(x=countX-3;x<countX-2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=0;y<countY-4;y+=2){for(x=0;x<countX-4;x+=2){this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);}}
for(y=0;y<countY-4;y+=2){for(x=countX-3;x<countX-2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=countY-3;y<countY-2;y+=2){for(x=0;x<countX-4;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
this._indexBufferTriangulationParts.push({offset:this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].offset+
this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].count*2,count:subx*suby*6+subx*9+(suby-1)*9+3});for(y=countY-3;y<countY-2;y+=2){for(x=0;x<2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=0;y<countY-4;y+=2){for(x=2;x<countX-2;x+=2){this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);}}
for(y=countY-3;y<countY-2;y+=2){for(x=2;x<countX-2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=0;y<countY-4;y+=2){for(x=0;x<2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
this._indexBufferTriangulationParts.push({offset:this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].offset+
this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].count*2,count:subx*suby*6+subx*9+(suby-1)*9+3});for(y=0;y<2;y+=2){for(x=0;x<2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+1)+y*countX);this._mesh._indices[0].push((x+1)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=2;y<countY-2;y+=2){for(x=2;x<countX-2;x+=2){this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);}}
for(y=2;y<countY-2;y+=2){for(x=0;x<2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=0;y<2;y+=2){for(x=2;x<countX-2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+1)+y*countX);this._mesh._indices[0].push((x+1)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
this._indexBufferTriangulationParts.push({offset:this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].offset+
this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].count*2,count:subx*suby*6+subx*9+(suby-1)*9+3});for(y=0;y<2;y+=2){for(x=countX-3;x<countX-2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+1)+y*countX);this._mesh._indices[0].push((x+1)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=2;y<countY-2;y+=2){for(x=0;x<countX-4;x+=2){this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);}}
for(y=2;y<countY-2;y+=2){for(x=countX-3;x<countX-2;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+1)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
for(y=0;y<2;y+=2){for(x=0;x<countX-4;x+=2){this._mesh._indices[0].push((x)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+2)+(y+2)*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+2)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x+1)+y*countX);this._mesh._indices[0].push((x+1)+y*countX);this._mesh._indices[0].push((x+1)+(y+1)*countX);this._mesh._indices[0].push((x)+y*countX);}}
this._indexBufferTriangulationParts.push({offset:this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].offset+
this._indexBufferTriangulationParts[this._indexBufferTriangulationParts.length-1].count*2,count:subx*suby*6+subx*9+(suby-1)*9+3});this._mesh._invalidate=true;this._mesh._numFaces=this._mesh._indices[0].length/3;this._mesh._numCoords=this._mesh._positions[0].length/3;},{hasIndexOffset:function(){return true;},getTriangulationAttributes:function(triangulationIndex){return this._indexBufferTriangulationParts[triangulationIndex];}}));x3dom.registerNodeType("BVHRefiner","BVHRefiner",defineClass(x3dom.nodeTypes.X3DLODNode,function(ctx){x3dom.nodeTypes.BVHRefiner.superClass.call(this,ctx);this.addField_SFFloat(ctx,'factor',1.0);this.addField_SFInt32(ctx,'maxDepth',3);this.addField_SFInt32(ctx,'minDepth',0);this.addField_SFInt32(ctx,'smoothLoading',1);this.addField_SFInt32(ctx,'interactionDepth',this._vf.maxDepth);this.addField_SFVec2f(ctx,'size',1,1);this.addField_SFVec3f(ctx,'octSize',1,1,1);this.addField_SFVec2f(ctx,'subdivision',1,1);this.addField_SFString(ctx,'url',"");this.addField_SFString(ctx,'elevationUrl',"");this.addField_SFString(ctx,'textureUrl',"");this.addField_SFString(ctx,'normalUrl',"");this.addField_SFString(ctx,'mode',"3d");this.addField_SFString(ctx,'subMode',"wmts");this.addField_SFString(ctx,'elevationFormat',"png");this.addField_SFString(ctx,'textureFormat',"png");this.addField_SFString(ctx,'normalFormat',"png");this.addField_SFFloat(ctx,'maxElevation',1.0);this.addField_SFBool(ctx,'useNormals',true);this.addField_SFBool(ctx,'lit',true);this.addField_SFInt32(ctx,'bvhCount',8);this.creationSmooth=0;this.togglePoints=true;this.nodeProducer=new NodeProducer();var nodeListSize=0;for(var x=0;x<=this._vf.maxDepth;x++){nodeListSize+=Math.pow(4,x);}
this.nodeList=new Array(nodeListSize);if(this._vf.mode==="bin"){this.rootNode=new QuadtreeNodeBin(ctx,this,0,0,0,null);}
else if(this._vf.mode==="3d"||this._vf.mode==="2d"){var geometry=new x3dom.nodeTypes.Plane(ctx);geometry._vf.subdivision.setValues(this._vf.subdivision);geometry.fieldChanged("subdivision");geometry._vf.size.setValues(this._vf.size);if(this._vf.mode==="2d"){if(this._vf.subMode==="wmts"){this.rootNode=new QuadtreeNode2dWMTS(ctx,this,0,0,x3dom.fields.SFMatrix4f.identity(),0,0,geometry);}
else{this.rootNode=new QuadtreeNode2D(ctx,this,0,0,x3dom.fields.SFMatrix4f.identity(),0,0,geometry,"/",1);}}
else{if(this._vf.subMode==="32bit"){this.rootNode=new QuadtreeNode3D_32bit(ctx,this,0,0,x3dom.fields.SFMatrix4f.identity(),0,0,geometry);}
else{geometry=new x3dom.nodeTypes.Patch(ctx);this.rootNode=new QuadtreeNode3D(ctx,this,0,0,x3dom.fields.SFMatrix4f.identity(),0,0,geometry);}}}
else if(this._vf.mode==="bvh"){this.rootNode=new BVHNode(ctx,this,0,"/",1,this._vf.bvhCount);}
else{x3dom.debug.logError("Error attribute mode. Value: '"+this._vf.mode+"' isn't conform. Please use type 'bin', '2d' or '3d'");}},{visitChildren:function(transform,drawableCollection,singlePath,invalidateCache,planeMask){var x3dElement=this._nameSpace.doc._x3dElem;if(this._vf.mode==="oct"){if(x3dElement.runtime.isReady&&this.togglePoints){x3dElement.runtime.togglePoints();this.togglePoints=false;this.view=drawableCollection.viewarea;}
this.creationSmooth++;singlePath=false;invalidateCache=true;this.rootNode.collectDrawables(transform,drawableCollection,singlePath,invalidateCache,planeMask);if(!this.view.isMovingOrAnimating()&&((this.creationSmooth%this._vf.smoothLoading)===0)){this.nodeProducer.CreateNewNode();}}
else{if(x3dElement.runtime.isReady&&this.togglePoints){this.view=x3dElement.runtime.canvas.doc._viewarea;this.togglePoints=false;}
this.createChildren=0;this.creationSmooth++;singlePath=false;invalidateCache=true;this.rootNode.collectDrawables(transform,drawableCollection,singlePath,invalidateCache,planeMask);if(!this.view.isMovingOrAnimating()&&((this.creationSmooth%this._vf.smoothLoading)===0)){this.nodeProducer.CreateNewNode();}}},getVolume:function()
{var vol=this._graph.volume;if(!this.volumeValid()&&this._vf.render)
{var childVol=this.rootNode.getVolume();if(childVol&&childVol.isValid())
vol.extendBounds(childVol.min,childVol.max);}
return vol;}}));function NodeProducer()
{var nextNode=null;var nearestDistance=1000000;var smallestDepth=1000000;this.AddNewNode=function(node,distance){if(node.Level()<smallestDepth){smallestDepth=node.Level();nextNode=node;}
if(node.Level()===smallestDepth){if(distance<nearestDistance){distance=nearestDistance;nextNode=node;}}};this.CreateNewNode=function(){if(nextNode!==null){nextNode.CreateChildren();}
nextNode=null;smallestDepth=1000;};}
function QuadtreeNode2dWMTS(ctx,bvhRefiner,level,nodeNumber,nodeTransformation,columnNr,rowNr,geometry)
{var children=[];var shape=new x3dom.nodeTypes.Shape();var position=null;var readyState=false;var childrenReadyState=false;var url=bvhRefiner._vf.textureUrl+"/"+level+"/"+columnNr+"/"+rowNr+"."+(bvhRefiner._vf.textureFormat).toLowerCase();var resizeFac=(bvhRefiner._vf.size.x+bvhRefiner._vf.size.y)/2.0;var cullObject={};function initialize(){var appearance=new x3dom.nodeTypes.Appearance(ctx);var texture=new x3dom.nodeTypes.ImageTexture(ctx);shape._nameSpace=bvhRefiner._nameSpace;var texProp=new x3dom.nodeTypes.TextureProperties(ctx);texProp._vf.boundaryModeS="CLAMP_TO_EDGE";texProp._vf.boundaryModeT="CLAMP_TO_EDGE";texProp._vf.boundaryModeR="CLAMP_TO_EDGE";texProp._vf.minificationFilter="LINEAR";texProp._vf.magnificationFilter="LINEAR";texture.addChild(texProp,"textureProperties");texture.nodeChanged();texture._nameSpace=bvhRefiner._nameSpace;texture._vf.url[0]=url;position=nodeTransformation.e3();appearance.addChild(texture);texture.nodeChanged();shape.addChild(appearance);appearance.nodeChanged();shape.addChild(geometry);geometry.nodeChanged();bvhRefiner.addChild(shape);shape.nodeChanged();cullObject.boundedNode=shape;cullObject.volume=shape.getVolume();}
this.CreateChildren=function(){create();};function create(){var deltaR=Math.sqrt(Math.pow(4,level));var deltaR1=Math.sqrt(Math.pow(4,level+1));var lt=Math.floor(nodeNumber/deltaR)*4*deltaR+
(nodeNumber%deltaR)*2;var rt=lt+1;var lb=lt+deltaR1;var rb=lb+1;var s=(bvhRefiner._vf.size).multiply(0.25);children.push(new QuadtreeNode2dWMTS(ctx,bvhRefiner,(level+1),lt,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2),(rowNr*2),geometry));children.push(new QuadtreeNode2dWMTS(ctx,bvhRefiner,(level+1),rt,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2+1),(rowNr*2),geometry));children.push(new QuadtreeNode2dWMTS(ctx,bvhRefiner,(level+1),lb,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,-s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2),(rowNr*2+1),geometry));children.push(new QuadtreeNode2dWMTS(ctx,bvhRefiner,(level+1),rb,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,-s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2+1),(rowNr*2+1),geometry));}
this.Shape=function(){return shape;};this.Ready=function(){if(shape._webgl!==undefined&&shape._webgl.texture!==undefined){return ready();}
return false;};function ready(){readyState=true;for(var i=0;i<shape._webgl.texture.length;i++){if(!shape._webgl.texture[i].texture.ready){readyState=false;}}
return readyState;}
function updateLoadingState(drawableCollection,transform){childrenReadyState=true;for(var i=0;i<children.length;i++){if(!children[i].Ready()){childrenReadyState=false;}}
if(children.length<4){childrenReadyState=false;}
else if(childrenReadyState){for(var i=0;i<children.length;i++){children[i].Shape()._vf.render=true;}}
if(shape._webgl===undefined||shape._webgl.texture===undefined){drawableCollection.context.setupShape(drawableCollection.gl,{shape:shape,transform:transform},drawableCollection.viewarea);}
else{ready();}}
this.collectDrawables=function(transform,drawableCollection,singlePath,invalidateCache,planeMask){cullObject.localMatrix=nodeTransformation;planeMask=drawableCollection.cull(nodeTransformation,cullObject,singlePath,planeMask);if(!readyState||!childrenReadyState)
updateLoadingState(drawableCollection,nodeTransformation);if(readyState&&planeMask>0){var mat_view=drawableCollection.viewMatrix;var vPos=mat_view.multMatrixPnt(nodeTransformation.multMatrixPnt(position));var distanceToCamera=Math.sqrt(Math.pow(vPos.x,2)+Math.pow(vPos.y,2)+Math.pow(vPos.z,2));if((distanceToCamera<Math.pow((bvhRefiner._vf.maxDepth-level),2)*resizeFac/bvhRefiner._vf.factor)||level<bvhRefiner._vf.minDepth){if(bvhRefiner.view.isMovingOrAnimating()&&children.length===0||bvhRefiner.view.isMovingOrAnimating()&&level>=bvhRefiner._vf.interactionDepth){shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else{if(children.length===0){bvhRefiner.nodeProducer.AddNewNode(that,distanceToCamera);shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else{if(childrenReadyState){for(var i=0;i<children.length;i++){children[i].collectDrawables(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);}}
else{shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);for(var i=0;i<children.length;i++){children[i].collectDrawables(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);children[i].Shape()._vf.render=false;}}}}}
else{shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}}};this.getVolume=function(){return shape.getVolume();};this.Level=function(){return level;};var that=this;initialize();}
function QuadtreeNode2D(ctx,bvhRefiner,level,nodeNumber,nodeTransformation,columnNr,rowNr,geometry,path,imgNumber)
{var children=[];var shape=new x3dom.nodeTypes.Shape();var position=null;var readyState=false;var childrenReadyState=false;var exists=true;var url=bvhRefiner._vf.textureUrl+path+imgNumber+"."+bvhRefiner._vf.textureFormat;var resizeFac=(bvhRefiner._vf.size.x+bvhRefiner._vf.size.y)/2.0;var cullObject={};function initialize(){var appearance=new x3dom.nodeTypes.Appearance(ctx);var texture=new x3dom.nodeTypes.ImageTexture(ctx);shape._nameSpace=bvhRefiner._nameSpace;var texProp=new x3dom.nodeTypes.TextureProperties(ctx);texProp._vf.boundaryModeS="CLAMP_TO_EDGE";texProp._vf.boundaryModeT="CLAMP_TO_EDGE";texProp._vf.boundaryModeR="CLAMP_TO_EDGE";texProp._vf.minificationFilter="LINEAR";texProp._vf.magnificationFilter="LINEAR";texture.addChild(texProp,"textureProperties");texture.nodeChanged();texture._nameSpace=bvhRefiner._nameSpace;texture._vf.url[0]=url;position=nodeTransformation.e3();appearance.addChild(texture);texture.nodeChanged();shape.addChild(appearance);appearance.nodeChanged();shape.addChild(geometry);geometry.nodeChanged();bvhRefiner.addChild(shape);shape.nodeChanged();cullObject.boundedNode=shape;cullObject.volume=shape.getVolume();}
this.CreateChildren=function(){create();};function create(){var deltaR=Math.sqrt(Math.pow(4,level));var deltaR1=Math.sqrt(Math.pow(4,level+1));var lt=Math.floor(nodeNumber/deltaR)*4*deltaR+
(nodeNumber%deltaR)*2;var rt=lt+1;var lb=lt+deltaR1;var rb=lb+1;var s=(bvhRefiner._vf.size).multiply(0.25);children.push(new QuadtreeNode2D(ctx,bvhRefiner,(level+1),lt,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2),(rowNr*2),geometry,path+imgNumber+"/",1));children.push(new QuadtreeNode2D(ctx,bvhRefiner,(level+1),rt,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2+1),(rowNr*2),geometry,path+imgNumber+"/",3));children.push(new QuadtreeNode2D(ctx,bvhRefiner,(level+1),lb,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,-s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2),(rowNr*2+1),geometry,path+imgNumber+"/",2));children.push(new QuadtreeNode2D(ctx,bvhRefiner,(level+1),rb,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,-s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2+1),(rowNr*2+1),geometry,path+imgNumber+"/",4));}
this.Shape=function(){return shape;};this.Ready=function(){if(shape._webgl!==undefined&&shape._webgl.texture!==undefined){return ready();}
return false;};function ready(){readyState=true;for(var i=0;i<shape._webgl.texture.length;i++){if(!shape._webgl.texture[i].texture.ready){readyState=false;}}
return readyState;}
function updateLoadingState(drawableCollection,transform){childrenReadyState=true;for(var i=0;i<children.length;i++){if(!children[i].Ready()){childrenReadyState=false;}}
if(children.length<4){childrenReadyState=false;}
else if(childrenReadyState){for(var i=0;i<children.length;i++){children[i].Shape()._vf.render=true;}}
if(shape._webgl===undefined||shape._webgl.texture===undefined){drawableCollection.context.setupShape(drawableCollection.gl,{shape:shape,transform:transform},drawableCollection.viewarea);}
else{ready();}}
this.collectDrawables=function(transform,drawableCollection,singlePath,invalidateCache,planeMask){cullObject.localMatrix=nodeTransformation;if(!readyState||!childrenReadyState){updateLoadingState(drawableCollection,nodeTransformation);}
if(readyState&&(planeMask=drawableCollection.cull(nodeTransformation,cullObject,singlePath,planeMask))>0){var mat_view=drawableCollection.viewMatrix;var vPos=mat_view.multMatrixPnt(nodeTransformation.multMatrixPnt(position));var distanceToCamera=Math.sqrt(Math.pow(vPos.x,2)+Math.pow(vPos.y,2)+Math.pow(vPos.z,2));if((distanceToCamera<Math.pow((bvhRefiner._vf.maxDepth-level),2)*resizeFac/bvhRefiner._vf.factor)||level<bvhRefiner._vf.minDepth){if(bvhRefiner.view.isMovingOrAnimating()&&children.length===0||bvhRefiner.view.isMovingOrAnimating()&&level>=bvhRefiner._vf.interactionDepth){shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else{if(children.length===0){bvhRefiner.nodeProducer.AddNewNode(that,distanceToCamera);shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else{if(childrenReadyState){for(var i=0;i<children.length;i++){children[i].collectDrawables(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);}}
else{shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);for(var i=0;i<children.length;i++){children[i].collectDrawables(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);children[i].Shape()._vf.render=false;}}}}}
else{shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}}};this.getVolume=function(){return shape.getVolume();};this.Level=function(){return level;};var that=this;initialize();}
function QuadtreeNode3D(ctx,bvhRefiner,level,nodeNumber,nodeTransformation,columnNr,rowNr,geometry)
{var children=[];var neighbors=[];var shape=new x3dom.nodeTypes.Shape();var position=null;var imageAddressColor=bvhRefiner._vf.textureUrl+"/"+level+"/"+
columnNr+"/"+rowNr+"."+
(bvhRefiner._vf.textureFormat).toLowerCase();var imageAddressHeight=bvhRefiner._vf.elevationUrl+"/"+level+"/"+
columnNr+"/"+rowNr+"."+
(bvhRefiner._vf.elevationFormat).toLowerCase();if(bvhRefiner._vf.normalUrl!=="")
var imageAddressNormal=bvhRefiner._vf.normalUrl+"/"+level+"/"+
columnNr+"/"+rowNr+"."+
(bvhRefiner._vf.normalFormat).toLowerCase();var readyState=false;var childrenReadyState=false;var resizeFac=(bvhRefiner._vf.size.x+bvhRefiner._vf.size.y)/2.0;var cullObject={};var lastIndice=0;var triangulationAttributes=null;function initialize(){var appearance=new x3dom.nodeTypes.Appearance(ctx);var textures=new x3dom.nodeTypes.MultiTexture(ctx);var colorTexture=new x3dom.nodeTypes.ImageTexture(ctx);var heightTexture=new x3dom.nodeTypes.ImageTexture(ctx);var normalTexture=new x3dom.nodeTypes.ImageTexture(ctx);var composedShader=new x3dom.nodeTypes.ComposedShader(ctx);shape._nameSpace=bvhRefiner._nameSpace;position=nodeTransformation.e3();position.z=bvhRefiner._vf.maxElevation/2;var vertexShader=new x3dom.nodeTypes.ShaderPart(ctx);vertexShader._vf.type='vertex';vertexShader._vf.url[0]=createVertexShader();var fragmentShader=new x3dom.nodeTypes.ShaderPart(ctx);fragmentShader._vf.type='fragment';fragmentShader._vf.url[0]=createFragmentShader();composedShader.addChild(vertexShader,'parts');composedShader.addChild(fragmentShader,'parts');var colorTexProp=new x3dom.nodeTypes.TextureProperties(ctx);colorTexProp._vf.boundaryModeS="CLAMP_TO_EDGE";colorTexProp._vf.boundaryModeT="CLAMP_TO_EDGE";colorTexProp._vf.boundaryModeR="CLAMP_TO_EDGE";colorTexProp._vf.minificationFilter="LINEAR";colorTexProp._vf.magnificationFilter="LINEAR";colorTexture.addChild(colorTexProp,"textureProperties");colorTexture.nodeChanged();colorTexture._nameSpace=bvhRefiner._nameSpace;colorTexture._vf.url[0]=imageAddressColor;colorTexture._vf.repeatT=false;colorTexture._vf.repeatS=false;textures.addChild(colorTexture,'texture');colorTexture.nodeChanged();var colorTextureField=new x3dom.nodeTypes.Field(ctx);colorTextureField._vf.name='texColor';colorTextureField._vf.type='SFInt32';colorTextureField._vf.value=0;composedShader.addChild(colorTextureField,'fields');colorTextureField.nodeChanged();var heightTexProp=new x3dom.nodeTypes.TextureProperties(ctx);heightTexProp._vf.boundaryModeS="CLAMP_TO_EDGE";heightTexProp._vf.boundaryModeT="CLAMP_TO_EDGE";heightTexProp._vf.boundaryModeR="CLAMP_TO_EDGE";heightTexProp._vf.minificationFilter="NEAREST";heightTexProp._vf.magnificationFilter="NEAREST";heightTexture.addChild(heightTexProp,"textureProperties");heightTexture.nodeChanged();heightTexture._nameSpace=bvhRefiner._nameSpace;heightTexture._vf.url[0]=imageAddressHeight;heightTexture._vf.repeatT=false;heightTexture._vf.repeatS=false;heightTexture._vf.scale=false;textures.addChild(heightTexture,'texture');heightTexture.nodeChanged();var heightTextureField=new x3dom.nodeTypes.Field(ctx);heightTextureField._vf.name='texHeight';heightTextureField._vf.type='SFInt32';heightTextureField._vf.value=1;composedShader.addChild(heightTextureField,'fields');heightTextureField.nodeChanged();if(bvhRefiner._vf.normalUrl!==""){var normalTexProp=new x3dom.nodeTypes.TextureProperties(ctx);normalTexProp._vf.boundaryModeS="CLAMP_TO_EDGE";normalTexProp._vf.boundaryModeT="CLAMP_TO_EDGE";normalTexProp._vf.boundaryModeR="CLAMP_TO_EDGE";normalTexProp._vf.minificationFilter="LINEAR";normalTexProp._vf.magnificationFilter="LINEAR";normalTexture.addChild(normalTexProp,"textureProperties");normalTexture.nodeChanged();normalTexture._nameSpace=bvhRefiner._nameSpace;normalTexture._vf.url[0]=imageAddressNormal;normalTexture._vf.repeatT=false;normalTexture._vf.repeatS=false;textures.addChild(normalTexture,'texture');normalTexture.nodeChanged();var normalTextureField=new x3dom.nodeTypes.Field(ctx);normalTextureField._vf.name='texNormal';normalTextureField._vf.type='SFInt32';normalTextureField._vf.value=2;composedShader.addChild(normalTextureField,'fields');normalTextureField.nodeChanged();}
var maxHeight=new x3dom.nodeTypes.Field(ctx);maxHeight._vf.name='maxElevation';maxHeight._vf.type='SFFloat';maxHeight._vf.value=bvhRefiner._vf.maxElevation;composedShader.addChild(maxHeight,'fields');maxHeight.nodeChanged();appearance.addChild(textures);textures.nodeChanged();appearance.addChild(composedShader);composedShader.nodeChanged();shape.addChild(appearance);appearance.nodeChanged();shape.addChild(geometry);bvhRefiner.addChild(shape);shape.nodeChanged();cullObject.boundedNode=shape;cullObject.volume=shape.getVolume();cullObject.volume.max.z=bvhRefiner._vf.maxElevation;cullObject.volume.min.z=0;cullObject.volume.center=cullObject.volume.min.add(cullObject.volume.max).multiply(0.5);cullObject.volume.transform(nodeTransformation);calculateNeighborhood();}
function calculateNeighborhood(){var levelStartID=0;for(var i=0;i<level;i++){levelStartID+=Math.pow(4,i);}
var sid=levelStartID+nodeNumber;bvhRefiner.nodeList[sid]=that;var c=Math.sqrt(Math.pow(4,level));neighbors[0]=levelStartID+(Math.ceil(((nodeNumber+1)/c)-1)*c+((nodeNumber+(c-1))%c));neighbors[1]=levelStartID+(Math.ceil(((nodeNumber+1)/c)-1)*c+((nodeNumber+1)%c));neighbors[3]=levelStartID+(nodeNumber+(c*(c-1)))%(Math.pow(4,level));neighbors[2]=levelStartID+(nodeNumber+c)%(Math.pow(4,level));if(columnNr===0){neighbors[0]=-1;}
if(rowNr===0){neighbors[3]=-1;}
if(columnNr===c-1){neighbors[1]=-1;}
if(rowNr===c-1){neighbors[2]=-1;}}
function createVertexShader(){if(bvhRefiner._vf.normalUrl!=="")
return"attribute vec3 position;\n"+"attribute vec3 texcoord;\n"+"uniform mat4 modelViewMatrix;\n"+"uniform mat4 modelViewProjectionMatrix;\n"+"uniform sampler2D texColor;\n"+"uniform sampler2D texHeight;\n"+"uniform float maxElevation;\n"+"uniform sampler2D texNormal;\n"+"varying vec2 texC;\n"+"varying vec3 vLight;\n"+"const float shininess = 32.0;\n"+"\n"+"void main(void) {\n"+"    vec3 uLightPosition = vec3(160.0, -9346.0, 4806.0);\n"+"    vec4 colr = texture2D(texColor, vec2(texcoord[0], 1.0-texcoord[1]));\n"+"    vec3 uAmbientMaterial = vec3(1.0, 1.0, 0.9);"+"    vec3 uAmbientLight = vec3(0.5, 0.5, 0.5);"+"    vec3 uDiffuseMaterial = vec3(0.7, 0.7, 0.7);"+"    vec3 uDiffuseLight = vec3(1.0, 1.0, 1.0);"+"    vec4 vertexPositionEye4 = modelViewMatrix * vec4(position, 1.0);"+"    vec3 vertexPositionEye3 = vec3((modelViewMatrix * vec4(vertexPositionEye4.xyz, 1.0)).xyz);"+"    vec3 vectorToLightSource = normalize(uLightPosition - vertexPositionEye3);"+"    vec4 height = texture2D(texHeight, vec2(texcoord[0], 1.0 - texcoord[1]));\n"+"    vec4 normalEye = 2.0 * texture2D(texNormal, vec2(texcoord[0], 1.0-texcoord[1])) - 1.0;\n"+"    float diffuseLightWeighting = max(dot(normalEye.xyz, vectorToLightSource), 0.0);"+"    texC = vec2(texcoord[0], 1.0-texcoord[1]);\n"+"    vec3 diffuseReflectance = uDiffuseMaterial * uDiffuseLight * diffuseLightWeighting;"+"    vec3 uSpecularMaterial = vec3(0.0, 0.0, 0.0);"+"    vec3 uSpecularLight = vec3(1.0, 1.0, 1.0);"+"    vec3 reflectionVector = normalize(reflect(-vectorToLightSource, normalEye.xyz));"+"    vec3 viewVectorEye = -normalize(vertexPositionEye3);"+"    float rdotv = max(dot(reflectionVector, viewVectorEye), 0.0);"+"    float specularLightWeight = pow(rdotv, shininess);"+"    vec3 specularReflection = uSpecularMaterial * uSpecularLight * specularLightWeight;"+"    vLight = vec4(uAmbientMaterial * uAmbientLight + diffuseReflectance + specularReflection, 1.0).xyz;"+"    gl_Position = modelViewProjectionMatrix * vec4(position.xy, height.x * maxElevation, 1.0);\n"+"}\n";else
return"attribute vec3 position;\n"+"attribute vec3 texcoord;\n"+"uniform mat4 modelViewProjectionMatrix;\n"+"uniform sampler2D texHeight;\n"+"uniform float maxElevation;\n"+"varying vec2 texC;\n"+"\n"+"void main(void) {\n"+"    vec4 height = texture2D(texHeight, vec2(texcoord[0], 1.0 - texcoord[1]));\n"+"    texC = vec2(texcoord[0], 1.0-texcoord[1]);\n"+"    gl_Position = modelViewProjectionMatrix * vec4(position.xy, height.x * maxElevation, 1.0);\n"+"}\n";}
function createFragmentShader(){if(bvhRefiner._vf.normalUrl!=="")
return"#ifdef GL_ES\n"+"precision highp float;\n"+"#endif\n"+"uniform sampler2D texColor;\n"+"uniform sampler2D texNormal;\n"+"varying vec2 texC;\n"+"varying vec3 vLight;\n"+"\n"+"\n"+"void main(void) {\n"+"    vec4 normal = 2.0 * texture2D(texNormal, texC) - 1.0;\n"+"    vec4 colr = texture2D(texColor, texC);\n"+"    gl_FragColor = vec4(colr.xyz * vLight, colr.w);\n"+"}\n";else
return"#ifdef GL_ES\n"+"precision highp float;\n"+"#endif\n"+"uniform sampler2D texColor;\n"+"varying vec2 texC;\n"+"\n"+"\n"+"void main(void) {\n"+"    gl_FragColor = texture2D(texColor, texC);\n"+"}\n";}
this.CreateChildren=function(){create();};function create(){var deltaR=Math.sqrt(Math.pow(4,level));var deltaR1=Math.sqrt(Math.pow(4,level+1));var lt=Math.floor(nodeNumber/deltaR)*4*deltaR+
(nodeNumber%deltaR)*2;var rt=lt+1;var lb=lt+deltaR1;var rb=lb+1;var s=(bvhRefiner._vf.size).multiply(0.25);children.push(new QuadtreeNode3D(ctx,bvhRefiner,(level+1),lt,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2),(rowNr*2),geometry));children.push(new QuadtreeNode3D(ctx,bvhRefiner,(level+1),rt,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2+1),(rowNr*2),geometry));children.push(new QuadtreeNode3D(ctx,bvhRefiner,(level+1),lb,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,-s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2),(rowNr*2+1),geometry));children.push(new QuadtreeNode3D(ctx,bvhRefiner,(level+1),rb,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,-s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2+1),(rowNr*2+1),geometry));}
this.Shape=function(){return shape;};this.ChildrenReady=function(){return childrenReadyState;};this.Ready=function(){if(shape._webgl!==undefined&&shape._webgl.texture!==undefined){return ready();}
return false;};function ready(){readyState=true;for(var i=0;i<shape._webgl.texture.length;i++){if(!shape._webgl.texture[i].texture.ready){readyState=false;}}
return readyState;}
function updateLoadingState(drawableCollection,transform){childrenReadyState=true;for(var i=0;i<children.length;i++){if(!children[i].Ready()){childrenReadyState=false;}}
if(children.length<4){childrenReadyState=false;}
else if(childrenReadyState){for(var i=0;i<children.length;i++){children[i].Shape()._vf.render=true;}}
if(shape._webgl===undefined||shape._webgl.texture===undefined){drawableCollection.context.setupShape(drawableCollection.gl,{shape:shape,transform:transform},drawableCollection.viewarea);}
else{ready();}}
this.collectDrawables=function(transform,drawableCollection,singlePath,invalidateCache,planeMask){drawableCollection.frustumCulling=false;cullObject.localMatrix=nodeTransformation;if(!readyState||!childrenReadyState){updateLoadingState(drawableCollection,nodeTransformation);}
var mat_view=drawableCollection.viewMatrix;var vPos=mat_view.multMatrixPnt(nodeTransformation.multMatrixPnt(position));var distanceToCamera=Math.sqrt(Math.pow(vPos.x,2)+Math.pow(vPos.y,2)+Math.pow(vPos.z,2));if(readyState&&vPos.z-(cullObject.volume.diameter/2)<0){if((distanceToCamera<Math.pow((bvhRefiner._vf.maxDepth-level),2)*resizeFac/bvhRefiner._vf.factor)||level<bvhRefiner._vf.minDepth){if(bvhRefiner.view.isMovingOrAnimating()&&(children.length==0||level>=bvhRefiner._vf.interactionDepth)){render(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);}
else{if(children.length===0){bvhRefiner.nodeProducer.AddNewNode(that,distanceToCamera);render(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);}
else{if(childrenReadyState){for(var i=0;i<children.length;i++){children[i].collectDrawables(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);}}
else{render(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);for(var i=0;i<children.length;i++){children[i].collectDrawables(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);children[i].Shape()._vf.render=false;}}}}}
else{render(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);}}};this.hasHigherRenderLevel=function(drawableCollection){var mat_view=drawableCollection.viewMatrix;var vPos=mat_view.multMatrixPnt(nodeTransformation.multMatrixPnt(position));var distanceToCamera=Math.sqrt(Math.pow(vPos.x,2)+Math.pow(vPos.y,2)+Math.pow(vPos.z,2));if(distanceToCamera<Math.pow((bvhRefiner._vf.maxDepth-level),2)*resizeFac/bvhRefiner._vf.factor){return true;}
return false;};function render(transform,drawableCollection,singlePath,invalidateCache,planeMask){var hasNeighborHigherResolution=[];for(var i=0;i<neighbors.length;i++){if(bvhRefiner.nodeList[neighbors[i]]!==undefined){if(bvhRefiner.nodeList[neighbors[i]].ChildrenReady()&&bvhRefiner.nodeList[neighbors[i]].hasHigherRenderLevel(drawableCollection))
hasNeighborHigherResolution.push(true);else
hasNeighborHigherResolution.push(false);}
else{hasNeighborHigherResolution.push(false);}}
var indiceNumber=0;if(hasNeighborHigherResolution[3]){if(hasNeighborHigherResolution[1]){indiceNumber=5;}
else if(hasNeighborHigherResolution[0]){indiceNumber=6;}
else{indiceNumber=4;}}
else if(hasNeighborHigherResolution[2]){if(hasNeighborHigherResolution[1]){indiceNumber=8;}
else if(hasNeighborHigherResolution[0]){indiceNumber=7;}
else{indiceNumber=3;}}
else if(hasNeighborHigherResolution[0]){indiceNumber=1;}
else if(hasNeighborHigherResolution[1]){indiceNumber=2;}
if(lastIndice!==indiceNumber||triangulationAttributes===null){triangulationAttributes=shape._cf.geometry.node.getTriangulationAttributes(indiceNumber);lastIndice=indiceNumber;}
shape._tessellationProperties=[triangulationAttributes];shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
this.getVolume=function(){return shape.getVolume();};this.Level=function(){return level;};var that=this;initialize();}
function QuadtreeNodeBin(ctx,bvhRefiner,level,columnNr,rowNr,resizeFac)
{var cullObject={};var mat_view;var vPos;var distanceToCamera;var fac=((1/4*Math.pow(level,2)+1.5)*0.1)*bvhRefiner._vf.factor;var children=[];var childrenExist=false;var readyState=false;var childrenReadyState=false;var path=bvhRefiner._vf.url+"/"+level+"/"+columnNr+"/";var file=path+rowNr+".x3d";var position=new x3dom.fields.SFVec3f(0.0,0.0,0.0);var exists=false;var shape=new x3dom.nodeTypes.Shape(ctx);var xhr=new XMLHttpRequest();xhr.open("GET",file,false);try{xhr.send();var xmlDoc=xhr.responseXML;if(xmlDoc!==null){var replacer=new RegExp("\"","g");createGeometry(shape);initialize();exists=true;}}
catch(exp){x3dom.debug.logException("Error loading file '"+file+"': "+exp);}
this.Exists=function(){return exists;};this.Shape=function(){return shape;};function createGeometry(parent){this._nameSpace=new x3dom.NodeNameSpace("",bvhRefiner._nameSpace.doc);this._nameSpace.setBaseURL(bvhRefiner._nameSpace.baseURL+path);var tempShape=xmlDoc.getElementsByTagName("Shape")[0];shape=this._nameSpace.setupTree(tempShape);if(!bvhRefiner._vf.useNormals){var appearance=new x3dom.nodeTypes.Appearance(ctx);var material=new x3dom.nodeTypes.Material(ctx);appearance.addChild(material);shape._cf.appearance=appearance;}
position=x3dom.fields.SFVec3f.copy(shape._cf.geometry.node._vf.position);}
function initialize(){cullObject.boundedNode=shape;cullObject.volume=shape.getVolume();}
this.CreateChildren=function(){create();};function create(){children.push(new QuadtreeNodeBin(ctx,bvhRefiner,(level+1),(columnNr*2),(rowNr*2),resizeFac));children.push(new QuadtreeNodeBin(ctx,bvhRefiner,(level+1),(columnNr*2+1),(rowNr*2),resizeFac));children.push(new QuadtreeNodeBin(ctx,bvhRefiner,(level+1),(columnNr*2),(rowNr*2+1),resizeFac));children.push(new QuadtreeNodeBin(ctx,bvhRefiner,(level+1),(columnNr*2+1),(rowNr*2+1),resizeFac));}
this.Ready=function(){if(shape._webgl!==undefined&&shape._webgl.internalDownloadCount!==undefined){return ready();}
return false;};function ready(){readyState=true;if(shape._webgl.internalDownloadCount>0){readyState=false;}
return readyState;}
function updateLoadingState(drawableCollection,transform){childrenReadyState=true;for(var i=0;i<children.length;i++){if(!children[i].Ready()){childrenReadyState=false;}}
if(childrenReadyState){for(var i=0;i<children.length;i++){children[i].Shape()._vf.render=true;}}
if(shape._cf.geometry.node!==null){if(shape._webgl===undefined||shape._webgl.internalDownloadCount===undefined){drawableCollection.context.setupShape(drawableCollection.gl,{shape:shape,transform:transform},drawableCollection.viewarea);}
else{ready();}}}
this.collectDrawables=function(transform,drawableCollection,singlePath,invalidateCache,planeMask){fac=((1/4*Math.pow(level,2)+1.5)*0.1)*bvhRefiner._vf.factor;cullObject.localMatrix=transform;if(!readyState||!childrenReadyState){updateLoadingState(drawableCollection,transform);}
if(readyState&&exists&&(planeMask=drawableCollection.cull(transform,cullObject,singlePath,planeMask))>0){mat_view=drawableCollection.viewMatrix;vPos=mat_view.multMatrixPnt(transform.multMatrixPnt(position));distanceToCamera=Math.sqrt(Math.pow(vPos.x,2)+Math.pow(vPos.y,2)+Math.pow(vPos.z,2));if((distanceToCamera<Math.pow((bvhRefiner._vf.maxDepth-level),2)/fac*1000)||level<bvhRefiner._vf.minDepth){if(bvhRefiner.view.isMovingOrAnimating()&&level>=bvhRefiner._vf.interactionDepth){shape.collectDrawableObjects(transform,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else{if(children.length===0){bvhRefiner.nodeProducer.AddNewNode(that,distanceToCamera);shape.collectDrawableObjects(transform,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else if(children.length===0&&bvhRefiner.createChildren>0){shape.collectDrawableObjects(transform,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else{if(!childrenExist){for(var i=0;i<children.length;i++){if(children[i].Exists()){childrenExist=true;break;}}}
if(childrenExist&&childrenReadyState){for(var i=0;i<children.length;i++){children[i].collectDrawables(transform,drawableCollection,singlePath,invalidateCache,planeMask);}}
else{for(var i=0;i<children.length;i++){children[i].collectDrawables(transform,drawableCollection,singlePath,invalidateCache,planeMask);children[i].Shape()._vf.render=false;}
shape.collectDrawableObjects(transform,drawableCollection,singlePath,invalidateCache,planeMask,[]);}}}}
else{shape.collectDrawableObjects(transform,drawableCollection,singlePath,invalidateCache,planeMask,[]);}}};this.getVolume=function(){return shape.getVolume();};this.Level=function(){return level;};var that=this;initialize();}
function BVHNode(ctx,bvhRefiner,level,path,imgNumber,count)
{var cullObject={};var mat_view;var vPos;var distanceToCamera;var fac=((1/4*Math.pow(level,2)+1.5)*0.1)*bvhRefiner._vf.factor;var children=[];var childrenExist=false;var readyState=false;var childrenReadyState=false;var file=bvhRefiner._vf.url+path+imgNumber+".x3d";var position=new x3dom.fields.SFVec3f(0.0,0.0,0.0);var exists=false;var shape=new x3dom.nodeTypes.Shape(ctx);this.RecalcFactor=function(){fac=((1/4*Math.pow(level,2)+1.5)*0.1)*bvhRefiner._vf.factor;for(var i=0;i<children.length;i++){children[i].RecalcFactor();}};var xhr=new XMLHttpRequest();xhr.open("GET",file,false);try{xhr.send();var xmlDoc=xhr.responseXML;if(xmlDoc!==null){var replacer=new RegExp("\"","g");createGeometry(shape);initialize();exists=true;}}
catch(exp){x3dom.debug.logException("Error loading file '"+file+"': "+exp);}
this.Exists=function()
{return exists;};this.Shape=function(){return shape;};function createGeometry(parent){this._nameSpace=new x3dom.NodeNameSpace("",bvhRefiner._nameSpace.doc);this._nameSpace.setBaseURL(bvhRefiner._nameSpace.baseURL+bvhRefiner._vf.url+path);var tempShape=xmlDoc.getElementsByTagName("Shape")[0];shape=this._nameSpace.setupTree(tempShape);if(!bvhRefiner._vf.useNormals){var appearance=new x3dom.nodeTypes.Appearance(ctx);var material=new x3dom.nodeTypes.Material(ctx);appearance.addChild(material);shape._cf.appearance=appearance;}
position=x3dom.fields.SFVec3f.copy(shape._cf.geometry.node._vf.position);}
function initialize(){cullObject.boundedNode=shape;cullObject.volume=shape.getVolume();}
this.CreateChildren=function(){create();};function create(){for(var i=0;i<count;i++){children.push(new BVHNode(ctx,bvhRefiner,(level+1),path+imgNumber+"/",i+1,count));}}
this.Ready=function(){if(shape._webgl!==undefined&&shape._webgl.internalDownloadCount!==undefined){return ready();}
return false;};function ready(){return(shape._webgl.internalDownloadCount<=0);}
function updateLoadingState(drawableCollection,transform){for(var i=0;i<children.length;i++){childrenReadyState=true;if(!children[i].Ready()){childrenReadyState=false;}
else{children[i].Shape()._vf.render=true;}}
if(shape._cf.geometry.node!==null){if(shape._webgl===undefined||shape._webgl.internalDownloadCount===undefined){drawableCollection.context.setupShape(drawableCollection.gl,{shape:shape,transform:transform},drawableCollection.viewarea);}
else{ready();}}}
this.collectDrawables=function(transform,drawableCollection,singlePath,invalidateCache,planeMask){fac=((1/4*Math.pow(level,2)+1.5)*0.1)*bvhRefiner._vf.factor;cullObject.localMatrix=transform;if(!readyState||!childrenReadyState){updateLoadingState(drawableCollection,transform);}
if(readyState&&exists&&(planeMask=drawableCollection.cull(transform,cullObject,singlePath,planeMask))>0){mat_view=drawableCollection.viewMatrix;vPos=mat_view.multMatrixPnt(transform.multMatrixPnt(position));distanceToCamera=Math.sqrt(Math.pow(vPos.x,2)+Math.pow(vPos.y,2)+Math.pow(vPos.z,2));if((distanceToCamera<Math.pow((bvhRefiner._vf.maxDepth-level),2)/fac)||level<bvhRefiner._vf.minDepth){if(bvhRefiner.view.isMovingOrAnimating()&&level>=bvhRefiner._vf.interactionDepth){shape.collectDrawableObjects(transform,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else{if(children.length===0){bvhRefiner.nodeProducer.AddNewNode(that,distanceToCamera);shape.collectDrawableObjects(transform,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else if(children.length===0&&bvhRefiner.createChildren>0){shape.collectDrawableObjects(transform,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else{if(!childrenExist){for(var i=0;i<children.length;i++){if(children[i].Exists()){childrenExist=true;break;}}}
if(childrenExist&&childrenReadyState){for(var i=0;i<children.length;i++){children[i].collectDrawables(transform,drawableCollection,singlePath,invalidateCache,planeMask);}}
else{for(var i=0;i<children.length;i++){children[i].collectDrawables(transform,drawableCollection,singlePath,invalidateCache,planeMask);children[i].Shape()._vf.render=false;}
shape.collectDrawableObjects(transform,drawableCollection,singlePath,invalidateCache,planeMask,[]);}}}}
else{shape.collectDrawableObjects(transform,drawableCollection,singlePath,invalidateCache,planeMask,[]);}}};this.getVolume=function(){return shape.getVolume();};this.Level=function(){return level;};var that=this;initialize();}
function QuadtreeNode3D_NEW(ctx,bvhRefiner,level,nodeNumber,nodeTransformation,columnNr,rowNr,geometry)
{var children=[];var shape=new x3dom.nodeTypes.Shape();var position=null;var imageAddressColor=bvhRefiner._vf.textureUrl+"/"+level+"/"+
columnNr+"/"+rowNr+"."+
(bvhRefiner._vf.textureFormat).toLowerCase();var imageAddressHeight=bvhRefiner._vf.elevationUrl+"/"+level+"/"+
columnNr+"/"+rowNr+"."+
(bvhRefiner._vf.elevationFormat).toLowerCase();var imageAddressNormal=bvhRefiner._vf.normalUrl+"/"+level+"/"+
columnNr+"/"+rowNr+"."+
(bvhRefiner._vf.normalFormat).toLowerCase();var exists=true;var resizeFac=(bvhRefiner._vf.size.x+bvhRefiner._vf.size.y)/2.0;var cullObject={};function initialize(){var appearance=new x3dom.nodeTypes.Appearance(ctx);var shader=new x3dom.nodeTypes.CommonSurfaceShader(ctx);var ssTexColor=new x3dom.nodeTypes.SurfaceShaderTexture(ctx);var colorTexture=new x3dom.nodeTypes.ImageTexture(ctx);var ssTexDisplace=new x3dom.nodeTypes.SurfaceShaderTexture(ctx);var heightTexture=new x3dom.nodeTypes.ImageTexture(ctx);shape._nameSpace=bvhRefiner._nameSpace;position=nodeTransformation.e3();shader._vf.displacementFactor=bvhRefiner._vf.maxElevation;colorTexture._nameSpace=bvhRefiner._nameSpace;colorTexture._vf.url[0]=imageAddressColor;colorTexture._vf.repeatT=false;colorTexture._vf.repeatS=false;ssTexColor.addChild(colorTexture,'texture');colorTexture.nodeChanged();shader.addChild(ssTexColor,'diffuseTexture');ssTexColor.nodeChanged();heightTexture._nameSpace=bvhRefiner._nameSpace;heightTexture._vf.url[0]=imageAddressHeight;heightTexture._vf.repeatT=false;heightTexture._vf.repeatS=false;ssTexDisplace.addChild(heightTexture,'texture');heightTexture.nodeChanged();shader.addChild(ssTexDisplace,'displacementTexture');heightTexture.nodeChanged();appearance.addChild(shader,'shaders');shader.nodeChanged();shape.addChild(appearance);appearance.nodeChanged();shape.addChild(geometry);geometry.nodeChanged();bvhRefiner.addChild(shape);shape.nodeChanged();cullObject.boundedNode=shape;cullObject.volume=shape.getVolume();cullObject.volume.max.z=Math.round(bvhRefiner._vf.maxElevation/2);cullObject.volume.min.z=-cullObject.volume.max.z;}
function createVertexShader(){return"attribute vec3 position;\n"+"attribute vec3 texcoord;\n"+"uniform mat4 modelViewMatrix;\n"+"uniform mat4 modelViewProjectionMatrix;\n"+"uniform sampler2D texColor;\n"+"uniform sampler2D texHeight;\n"+"uniform float maxElevation;\n"+"uniform sampler2D texNormal;\n"+"varying vec2 texC;\n"+"varying vec3 vLight;\n"+"const float shininess = 32.0;\n"+"\n"+"void main(void) {\n"+"    vec3 uLightPosition = vec3(160.0, -9346.0, 4806.0);\n"+"    vec4 colr = texture2D(texColor, vec2(texcoord[0], 1.0-texcoord[1]));\n"+"    vec3 uAmbientMaterial = vec3(1.0, 1.0, 0.9);"+"    vec3 uAmbientLight = vec3(0.5, 0.5, 0.5);"+"    vec3 uDiffuseMaterial = vec3(0.7, 0.7, 0.7);"+"    vec3 uDiffuseLight = vec3(1.0, 1.0, 1.0);"+"    vec4 vertexPositionEye4 = modelViewMatrix * vec4(position, 1.0);"+"    vec3 vertexPositionEye3 = vec3((modelViewMatrix * vec4(vertexPositionEye4.xyz, 1.0)).xyz);"+"    vec3 vectorToLightSource = normalize(uLightPosition - vertexPositionEye3);"+"    vec4 height = texture2D(texHeight, vec2(texcoord[0], 1.0 - texcoord[1]));\n"+"    vec4 normalEye = 2.0 * texture2D(texNormal, vec2(texcoord[0], 1.0-texcoord[1])) - 1.0;\n"+"    float diffuseLightWeighting = max(dot(normalEye.xyz, vectorToLightSource), 0.0);"+"    texC = vec2(texcoord[0], 1.0-texcoord[1]);\n"+"    vec3 diffuseReflectance = uDiffuseMaterial * uDiffuseLight * diffuseLightWeighting;"+"    vec3 uSpecularMaterial = vec3(0.0, 0.0, 0.0);"+"    vec3 uSpecularLight = vec3(1.0, 1.0, 1.0);"+"    vec3 reflectionVector = normalize(reflect(-vectorToLightSource, normalEye.xyz));"+"    vec3 viewVectorEye = -normalize(vertexPositionEye3);"+"    float rdotv = max(dot(reflectionVector, viewVectorEye), 0.0);"+"    float specularLightWeight = pow(rdotv, shininess);"+"    vec3 specularReflection = uSpecularMaterial * uSpecularLight * specularLightWeight;"+"    vLight = vec4(uAmbientMaterial * uAmbientLight + diffuseReflectance + specularReflection, 1.0).xyz;"+"    gl_Position = modelViewProjectionMatrix * vec4(position.xy, height.x * maxElevation, 1.0);\n"+"}\n";}
function createFragmentShader(){return"#ifdef GL_ES\n"+"precision highp float;\n"+"#endif\n"+"uniform sampler2D texColor;\n"+"uniform sampler2D texNormal;\n"+"varying vec2 texC;\n"+"varying vec3 vLight;\n"+"\n"+"\n"+"void main(void) {\n"+"    vec4 normal = 2.0 * texture2D(texNormal, texC) - 1.0;\n"+"    vec4 colr = texture2D(texColor, texC);\n"+"    gl_FragColor = vec4(colr.xyz * vLight, colr.w);\n"+"}\n";}
function create(){var deltaR=Math.sqrt(Math.pow(4,level));var deltaR1=Math.sqrt(Math.pow(4,level+1));var lt=Math.floor(nodeNumber/deltaR)*4*deltaR+
(nodeNumber%deltaR)*2;var rt=lt+1;var lb=lt+deltaR1;var rb=lb+1;var s=(bvhRefiner._vf.size).multiply(0.25);children.push(new QuadtreeNode3D_NEW(ctx,bvhRefiner,(level+1),lt,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2),(rowNr*2),geometry));children.push(new QuadtreeNode3D_NEW(ctx,bvhRefiner,(level+1),rt,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2+1),(rowNr*2),geometry));children.push(new QuadtreeNode3D_NEW(ctx,bvhRefiner,(level+1),lb,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,-s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2),(rowNr*2+1),geometry));children.push(new QuadtreeNode3D_NEW(ctx,bvhRefiner,(level+1),rb,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,-s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2+1),(rowNr*2+1),geometry));}
this.collectDrawables=function(transform,drawableCollection,singlePath,invalidateCache,planeMask){cullObject.localMatrix=nodeTransformation;if(exists&&(planeMask=drawableCollection.cull(transform,cullObject,singlePath,planeMask))>0){var mat_view=drawableCollection.viewMatrix;var vPos=mat_view.multMatrixPnt(transform.multMatrixPnt(position));var distanceToCamera=Math.sqrt(Math.pow(vPos.x,2)+Math.pow(vPos.y,2)+Math.pow(vPos.z,2));if((distanceToCamera<Math.pow((bvhRefiner._vf.maxDepth-level),2)*resizeFac/bvhRefiner._vf.factor)){if(children.length===0&&bvhRefiner.createChildren===0){bvhRefiner.createChildren++;create();shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else if(children.length===0&&bvhRefiner.createChildren>0){shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else{for(var i=0;i<children.length;i++){children[i].collectDrawables(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);}}}
else{shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}}};this.getVolume=function(){return shape.getVolume();};initialize();}
function OctreeNode(ctx,bvhRefiner,level,nodeTransformation)
{var children=[];var position=nodeTransformation.e3();var shape=new x3dom.nodeTypes.Shape(ctx);var cullObject={};var resizeFac=(bvhRefiner._vf.octSize.x+bvhRefiner._vf.octSize.y+bvhRefiner._vf.octSize.z)/3.0;function initialize(){var appearance=new x3dom.nodeTypes.Appearance(ctx);var geometry=new x3dom.nodeTypes.Box(ctx);geometry._vf.size=bvhRefiner._vf.octSize;geometry.fieldChanged('size');shape._nameSpace=new x3dom.NodeNameSpace("",bvhRefiner._nameSpace.doc);shape._nameSpace.setBaseURL(bvhRefiner._nameSpace.baseURL);shape.addChild(appearance);appearance.nodeChanged();shape.addChild(geometry);geometry.nodeChanged();shape.nodeChanged();cullObject.boundedNode=shape;cullObject.volume=shape.getVolume();}
function create(){var s=bvhRefiner._vf.octSize.multiply(0.25);children.push(new OctreeNode(ctx,bvhRefiner,(level+1),nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,s.y,s.z))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,0.5)))));children.push(new OctreeNode(ctx,bvhRefiner,(level+1),nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,s.y,s.z))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,0.5)))));children.push(new OctreeNode(ctx,bvhRefiner,(level+1),nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,-s.y,s.z))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,0.5)))));children.push(new OctreeNode(ctx,bvhRefiner,(level+1),nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,-s.y,s.z))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,0.5)))));children.push(new OctreeNode(ctx,bvhRefiner,(level+1),nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,s.y,-s.z))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,0.5)))));children.push(new OctreeNode(ctx,bvhRefiner,(level+1),nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,s.y,-s.z))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,0.5)))));children.push(new OctreeNode(ctx,bvhRefiner,(level+1),nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,-s.y,-s.z))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,0.5)))));children.push(new OctreeNode(ctx,bvhRefiner,(level+1),nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,-s.y,-s.z))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,0.5)))));}
this.collectDrawables=function(transform,drawableCollection,singlePath,invalidateCache,planeMask){cullObject.localMatrix=nodeTransformation;if((planeMask=drawableCollection.cull(transform,cullObject,singlePath,planeMask))>0){var mat_view=drawableCollection.viewMatrix;var vPos=mat_view.multMatrixPnt(transform.multMatrixPnt(position));var distanceToCamera=Math.sqrt(Math.pow(vPos.x,2)+Math.pow(vPos.y,2)+Math.pow(vPos.z,2));if((distanceToCamera<Math.pow((bvhRefiner._vf.maxDepth-level),2)*resizeFac/bvhRefiner._vf.factor)){if(children.length===0){create();}
else{for(var i=0;i<children.length;i++){children[i].collectDrawables(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);}}}
else{shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}}};this.getVolume=function(){return shape.getVolume();};initialize();}
function QuadtreeNode3D_32bit(ctx,bvhRefiner,level,nodeNumber,nodeTransformation,columnNr,rowNr,geometry)
{var children=[];var shape=new x3dom.nodeTypes.Shape();var position=null;var imageAddressColor=bvhRefiner._vf.textureUrl+"/"+level+"/"+
columnNr+"/"+rowNr+"."+
(bvhRefiner._vf.textureFormat).toLowerCase();var imageAddressHeight=bvhRefiner._vf.elevationUrl+"/"+level+"/"+
columnNr+"/"+rowNr+"."+
(bvhRefiner._vf.elevationFormat).toLowerCase();var imageAddressNormal=bvhRefiner._vf.normalUrl+"/"+level+"/"+
columnNr+"/"+rowNr+"."+
(bvhRefiner._vf.normalFormat).toLowerCase();var exists=true;var resizeFac=(bvhRefiner._vf.size.x+bvhRefiner._vf.size.y)/2.0;var cullObject={};function initialize(){var appearance=new x3dom.nodeTypes.Appearance(ctx);var textures=new x3dom.nodeTypes.MultiTexture(ctx);var colorTexture=new x3dom.nodeTypes.ImageTexture(ctx);var heightTexture=new x3dom.nodeTypes.ImageTexture(ctx);var normalTexture=new x3dom.nodeTypes.ImageTexture(ctx);var composedShader=new x3dom.nodeTypes.ComposedShader(ctx);shape._nameSpace=bvhRefiner._nameSpace;position=nodeTransformation.e3();var vertexShader=new x3dom.nodeTypes.ShaderPart(ctx);vertexShader._vf.type='vertex';vertexShader._vf.url[0]=createVertexShader();var fragmentShader=new x3dom.nodeTypes.ShaderPart(ctx);fragmentShader._vf.type='fragment';fragmentShader._vf.url[0]=createFragmentShader();composedShader.addChild(vertexShader,'parts');composedShader.addChild(fragmentShader,'parts');colorTexture._nameSpace=bvhRefiner._nameSpace;colorTexture._vf.url[0]=imageAddressColor;colorTexture._vf.repeatT=false;colorTexture._vf.repeatS=false;colorTexture._vf.generateMipMaps=false;textures.addChild(colorTexture,'texture');colorTexture.nodeChanged();var colorTextureField=new x3dom.nodeTypes.Field(ctx);colorTextureField._vf.name='texColor';colorTextureField._vf.type='SFInt32';colorTextureField._vf.value=0;composedShader.addChild(colorTextureField,'fields');colorTextureField.nodeChanged();heightTexture._nameSpace=bvhRefiner._nameSpace;heightTexture._vf.url[0]=imageAddressHeight;heightTexture._vf.repeatT=false;heightTexture._vf.repeatS=false;textures.addChild(heightTexture,'texture');heightTexture.nodeChanged();var heightTextureField=new x3dom.nodeTypes.Field(ctx);heightTextureField._vf.name='texHeight';heightTextureField._vf.type='SFInt32';heightTextureField._vf.value=1;composedShader.addChild(heightTextureField,'fields');heightTextureField.nodeChanged();normalTexture._nameSpace=bvhRefiner._nameSpace;normalTexture._vf.url[0]=imageAddressNormal;normalTexture._vf.repeatT=false;normalTexture._vf.repeatS=false;textures.addChild(normalTexture,'texture');normalTexture.nodeChanged();var normalTextureField=new x3dom.nodeTypes.Field(ctx);normalTextureField._vf.name='texNormal';normalTextureField._vf.type='SFInt32';normalTextureField._vf.value=2;composedShader.addChild(normalTextureField,'fields');normalTextureField.nodeChanged();var maxHeight=new x3dom.nodeTypes.Field(ctx);maxHeight._vf.name='maxElevation';maxHeight._vf.type='SFFloat';maxHeight._vf.value=bvhRefiner._vf.maxElevation;composedShader.addChild(maxHeight,'fields');maxHeight.nodeChanged();appearance.addChild(textures);textures.nodeChanged();appearance.addChild(composedShader);composedShader.nodeChanged();shape.addChild(appearance);appearance.nodeChanged();shape.addChild(geometry);geometry.nodeChanged();bvhRefiner.addChild(shape);shape.nodeChanged();cullObject.boundedNode=shape;cullObject.volume=shape.getVolume();cullObject.volume.max.z=Math.round(bvhRefiner._vf.maxElevation);cullObject.volume.min.z=-cullObject.volume.max.z;}
function createVertexShader(){return"attribute vec3 position;\n"+"attribute vec3 texcoord;\n"+"uniform mat4 modelViewMatrix;\n"+"uniform mat4 modelViewProjectionMatrix;\n"+"uniform sampler2D texColor;\n"+"uniform sampler2D texHeight;\n"+"uniform float maxElevation;\n"+"uniform sampler2D texNormal;\n"+"varying vec2 texC;\n"+"varying vec3 vLight;\n"+"const float shininess = 32.0;\n"+"\n"+"void main(void) {\n"+"    vec3 uLightPosition = vec3(160.0, -9346.0, 4806.0);\n"+"    vec4 colr = texture2D(texColor, vec2(texcoord[0], 1.0-texcoord[1]));\n"+"    vec3 uAmbientMaterial = vec3(1.0, 1.0, 0.9);"+"    vec3 uAmbientLight = vec3(0.5, 0.5, 0.5);"+"    vec3 uDiffuseMaterial = vec3(0.7, 0.7, 0.7);"+"    vec3 uDiffuseLight = vec3(1.0, 1.0, 1.0);"+"    vec4 vertexPositionEye4 = modelViewMatrix * vec4(position, 1.0);"+"    vec3 vertexPositionEye3 = vec3((modelViewMatrix * vec4(vertexPositionEye4.xyz, 1.0)).xyz);"+"    vec3 vectorToLightSource = normalize(uLightPosition - vertexPositionEye3);"+"    vec4 height = texture2D(texHeight, vec2(texcoord[0], 1.0 - texcoord[1]));\n"+"    vec4 normalEye = 2.0 * texture2D(texNormal, vec2(texcoord[0], 1.0-texcoord[1])) - 1.0;\n"+"    float diffuseLightWeighting = max(dot(normalEye.xyz, vectorToLightSource), 0.0);"+"    texC = vec2(texcoord[0], 1.0-texcoord[1]);\n"+"    vec3 diffuseReflectance = uDiffuseMaterial * uDiffuseLight * diffuseLightWeighting;"+"    vec3 uSpecularMaterial = vec3(0.0, 0.0, 0.0);"+"    vec3 uSpecularLight = vec3(1.0, 1.0, 1.0);"+"    vec3 reflectionVector = normalize(reflect(-vectorToLightSource, normalEye.xyz));"+"    vec3 viewVectorEye = -normalize(vertexPositionEye3);"+"    float rdotv = max(dot(reflectionVector, viewVectorEye), 0.0);"+"    float specularLightWeight = pow(rdotv, shininess);"+"    vec3 specularReflection = uSpecularMaterial * uSpecularLight * specularLightWeight;"+"    vLight = vec4(uAmbientMaterial * uAmbientLight + diffuseReflectance + specularReflection, 1.0).xyz;"+"    gl_Position = modelViewProjectionMatrix * vec4(position.xy, ((height.g * 256.0)+height.b) * maxElevation, 1.0);\n"+"}\n";}
function createFragmentShader(){return"#ifdef GL_ES\n"+"precision highp float;\n"+"#endif\n"+"uniform sampler2D texColor;\n"+"uniform sampler2D texNormal;\n"+"varying vec2 texC;\n"+"varying vec3 vLight;\n"+"\n"+"\n"+"void main(void) {\n"+"    vec4 normal = 2.0 * texture2D(texNormal, texC) - 1.0;\n"+"    vec4 colr = texture2D(texColor, texC);\n"+"    float coler = ((colr.g * 256.0)+colr.b);"+"    gl_FragColor = vec4(vLight * coler, 1.0);\n"+"}\n";}
function create(){var deltaR=Math.sqrt(Math.pow(4,level));var deltaR1=Math.sqrt(Math.pow(4,level+1));var lt=Math.floor(nodeNumber/deltaR)*4*deltaR+
(nodeNumber%deltaR)*2;var rt=lt+1;var lb=lt+deltaR1;var rb=lb+1;var s=(bvhRefiner._vf.size).multiply(0.25);children.push(new QuadtreeNode3D_32bit(ctx,bvhRefiner,(level+1),lt,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2),(rowNr*2),geometry));children.push(new QuadtreeNode3D_32bit(ctx,bvhRefiner,(level+1),rt,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2+1),(rowNr*2),geometry));children.push(new QuadtreeNode3D_32bit(ctx,bvhRefiner,(level+1),lb,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(-s.x,-s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2),(rowNr*2+1),geometry));children.push(new QuadtreeNode3D_32bit(ctx,bvhRefiner,(level+1),rb,nodeTransformation.mult(x3dom.fields.SFMatrix4f.translation(new x3dom.fields.SFVec3f(s.x,-s.y,0.0))).mult(x3dom.fields.SFMatrix4f.scale(new x3dom.fields.SFVec3f(0.5,0.5,1.0))),(columnNr*2+1),(rowNr*2+1),geometry));}
this.collectDrawables=function(transform,drawableCollection,singlePath,invalidateCache,planeMask){cullObject.localMatrix=nodeTransformation;if(exists&&(planeMask=drawableCollection.cull(transform,cullObject,singlePath,planeMask))>0){var mat_view=drawableCollection.viewMatrix;var vPos=mat_view.multMatrixPnt(transform.multMatrixPnt(position));var distanceToCamera=Math.sqrt(Math.pow(vPos.x,2)+Math.pow(vPos.y,2)+Math.pow(vPos.z,2));if((distanceToCamera<Math.pow((bvhRefiner._vf.maxDepth-level),2)*resizeFac/bvhRefiner._vf.factor)){if(children.length===0&&bvhRefiner.createChildren===0){bvhRefiner.createChildren++;create();shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else if(children.length===0&&bvhRefiner.createChildren>0){shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}
else{for(var i=0;i<children.length;i++){children[i].collectDrawables(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask);}}}
else{shape.collectDrawableObjects(nodeTransformation,drawableCollection,singlePath,invalidateCache,planeMask,[]);}}};this.getVolume=function(){return shape.getVolume();};initialize();}