/*

X3DAILY

version 1.5

X3D JavaScript parser & 3D web content authoring tool
developed by Yaroslav Akhromov (Yarus)

www.x3daily.com

(c) 2011 X3DAILY

*/

// *******************************************************************************************
//doing document ready status
init=function() {if (arguments.callee.done) return; arguments.callee.done = true; findx3d();}
// ff, opera
if (document.addEventListener) {document.addEventListener("DOMContentLoaded", init, false);}
// ie
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)>");
document.write("<\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
    if (this.readyState == "complete") { init(); }};
/*@end @*/
// safari
if (/WebKit/i.test(navigator.userAgent)) {
    var _timer = setInterval(function() { if (/loaded|complete/.test(document.readyState)) { clearInterval(_timer); delete _timer; init(); }},10);}
// others
window.onload = init;

// *******************************************************************************************
//getting data from x3d tag
function findx3d(){
var src = document.getElementsByTagName("x3d")[0].getAttribute("src");
var width = document.getElementsByTagName("x3d")[0].getAttribute("width");
if(String(width)=="null"){width=500;}
var height = document.getElementsByTagName("x3d")[0].getAttribute("height");
if(String(height)=="null"){height=500;}
var left = document.getElementsByTagName("x3d")[0].getAttribute("left");
if(String(left)=="null"){left=0;}
var top = document.getElementsByTagName("x3d")[0].getAttribute("top");
if(String(top)=="null"){top=0;}
var wireframes = document.getElementsByTagName("x3d")[0].getAttribute("wireframes");
if(String(wireframes)=="null"){wireframes="false";}
var hotkeys = document.getElementsByTagName("x3d")[0].getAttribute("hotkeys");
if(String(hotkeys)=="null"){hotkeys="true";}
var background = document.getElementsByTagName("x3d")[0].getAttribute("background");
if(String(background)=="null"){background="black";}
var align = document.getElementsByTagName("x3d")[0].getAttribute("align");
if(String(align)=="null"){align="none";}
createx3dsection(src,width,height,left,top,wireframes,hotkeys,background,align);}

// *******************************************************************************************
//creating area for x3d
function createx3dsection(sectionsrc,sectionwidth,sectionheight,sectionleft,sectiontop,sectionwireframes,sectionhotkeys,sectionbackground,sectionalign){
var parent = document.getElementsByTagName("body")[0];
var newsection = document.createElement("section");
//newP.className = 'elemClass';
newsection.id = "x3dsection";
if(sectionleft!="none" && sectiontop!="none"){
newsection.style.position = "absolute";}else{newsection.style.position = "relative";}
newsection.style.width = sectionwidth+"px";
newsection.style.height = sectionheight+"px";
if(sectionleft!="none" && sectiontop!="none"){
if(sectionalign=="xcenter"){newsection.style.left=window.innerWidth/2-sectionwidth/2+"px";}else{
newsection.style.left = sectionleft+"px";}
if(sectionalign=="ycenter"){newsection.style.top=window.innerHeight/2-sectionheight/2+"px";}else{
newsection.style.top = sectiontop+"px";}
if(sectionalign=="xycenter"){newsection.style.left=window.innerWidth/2-sectionwidth/2+"px";
newsection.style.top=window.innerHeight/2-sectionheight/2+"px";}}
if(sectionbackground!="none"){
newsection.style.backgroundColor = sectionbackground;}
newsection.style.opacity = 1;
newsection.wireframes=sectionwireframes;
newsection.hotkeys=sectionhotkeys;
parent.appendChild(newsection);
parsex3d(sectionsrc);	
}

// *******************************************************************************************
//parsing x3d file
function parsex3d(x3dfile){
calculate_process=false;
var xmlDoc=null;
var path=x3dfile;
if (window.ActiveXObject){ //code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(path);
} else if (document.implementation.createDocument) { //code for Mozilla, Firefox, Opera, etc.
var xmlhttp = new window.XMLHttpRequest();
xmlhttp.open("GET",path,false); 
xmlhttp.send(null);
var xmlDoc = xmlhttp.responseXML.documentElement;
} else { alert('Your browser cannot load xml-data!'); }

if (xmlDoc!=null){ //if we are successfull 

// *******************************************************************************************
//render Shape
var parent = document.getElementById("x3dsection");
var newcanvas = document.createElement("canvas");
newcanvas.id = "canvas";
newcanvas.width = String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("p"));
newcanvas.height = String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("p"));
parent.appendChild(newcanvas);

document.getElementById("x3dsection").style.webkitUserSelect="none";
document.getElementById("x3dsection").style.MozUserSelect="none"; 
document.getElementById("x3dsection").unselectable;

var parent = document.getElementById("x3dsection");
var preloader = document.createElement("section");
preloader.id = "preloader"; preloader.style.position="absolute"; preloader.style.left=10+"px"; preloader.style.top=0+"px"; preloader.style.zIndex=100000;
preloader.width = String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("p"));
preloader.height = String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("p"));
parent.appendChild(preloader);
document.getElementById("preloader").innerHTML="<p style='font-family:Arial;font-size:9pt;color:rgb(46,99,167);text-align:left;line-height:1;'><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X3DAILY (version 1.5)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X3D JavaScript parser & 3D web content authoring tool<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;developed by Yaroslav Akhromov (Yarus)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://www.x3daily.com' target='_balnk' style='text-decoration:underline; color:rgb(46,99,167);'>www.x3daily.com</a><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&copy; 2011-2012 X3DAILY<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>loading... please wait...</b></p>";

var parent = document.getElementById("x3dsection");
var preloader_status = document.createElement("section");
preloader_status.id = "loading_status"; preloader_status.style.position="absolute"; preloader_status.style.left=10+"px"; preloader_status.style.top=170+"px"; preloader_status.style.zIndex=100001;
preloader_status.width = String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("p"));
preloader_status.height = String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("p"));
parent.appendChild(preloader_status);
document.getElementById("loading_status").innerHTML="<p style='font-family:Arial;font-size:9pt;color:rgb(46,99,167);text-align:left;line-height:1;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[calculating...]</p>";

var transformMatrix="";
how_many_objects=0;

// *******************************************************************************************
//normals application in case of mtl-files
function apply_normals(thismodel){normalize_m=[];
for(i=0; i<thismodel.side.length; i++){temp_n=[];
for(j=0; j<thismodel.side[i].vertices.length; j++){temp_n.push(real_norm_verts_array[thismodel.side[i].vertices[j]]);}
middle_x=middle_y=middle_z=0;
for(n=0; n<temp_n.length; n++){middle_x+=Number(temp_n[n][0]);middle_y+=Number(temp_n[n][1]);middle_z+=Number(temp_n[n][2]);}
thismodel.side[i].normal=[(middle_x/temp_n.length).toFixed(6),(middle_y/temp_n.length).toFixed(6),(middle_z/temp_n.length).toFixed(6)];}}

// *******************************************************************************************
//CREASE ANGLE COMPUTATION
function make_creaseAngle(crease_angle,thismodel){
document.getElementById("widget").style.visibility = "visible";	
function calculate_normal(vertices){
var U = [(vertices[0].x-vertices[1].x),(vertices[0].y-vertices[1].y),(vertices[0].z-vertices[1].z)];
var V = [(vertices[1].x-vertices[2].x),(vertices[1].y-vertices[2].y),(vertices[1].z-vertices[2].z)];
var p = [((U[1]*V[2])-(U[2]*V[1])),((U[0]*V[2])-(U[2]*V[0])),((U[0]*V[1])-(U[1]*V[0]))];
var magP = Math.sqrt((p[0]*p[0])+(p[1]*p[1])+(p[2]*p[2]));
p1=p[0]; p2=p[1]; p3=p[2]; return([p1,p2,p3,magP]);}
function compare_vertex_number(our_vertex,next_plane){
result=false; for(j=0; j<next_plane.vertices.length; j++){
if(our_vertex==next_plane.vertices[j] && our_vertex!=mem){result=true;mem=our_vertex;}} return(result);}
function adjacent_planes(plane0,plane1){ mem=0;	
ct=0; adj=false; for(i=0; i<plane0.vertices.length; i++){
if(compare_vertex_number(plane0.vertices[i],plane1)){ct+=1;}}
if(ct>=2){adj=true;} return(adj);}
function check(n2){s2=false; for(k2=0; k2<temp_sides.length; k2++){if(n2==temp_sides[k2]){s2=true;break;}}return(s2);}
if(String(thismodel.side)=="undefined"){thismodel.side=thismodel.Fside;};
if(String(thismodel.vertexList)=="undefined"){thismodel.vertexList=thismodel.FvertexList;};
for(tu2=0; tu2<thismodel.side.length; tu2++){thismodel.side[tu2].normal="undefined";}
function do_calculating(this_part,nom,times){
for(tu=nom*this_part; tu<nom*this_part+this_part; tu++){f=thismodel.side[tu];
if(String(f.normal)=="undefined"){
normals_of_sides=[]; normals_of_sides.push(calculate_normal([thismodel.vertexList[f.vertices[0]],thismodel.vertexList[f.vertices[1]],thismodel.vertexList[f.vertices[2]]]));
temp_sides=[]; temp_sides.push(tu);
pip=false;
for(u=0; u<thismodel.side.length; u++){
if(!check(u)){	
if(adjacent_planes(f,thismodel.side[u])){pip=true;	
//planes' normals calculation
if(String(thismodel.side[u].normal)!="undefined"){
normals_of_sides.push(thismodel.side[u].normal[0],thismodel.side[u].normal[1],thismodel.side[u].normal[2],thismodel.side[u].normal[3]);	
}else{ normals_of_sides.push(calculate_normal([thismodel.vertexList[thismodel.side[u].vertices[0]],thismodel.vertexList[thismodel.side[u].vertices[1]],thismodel.vertexList[thismodel.side[u].vertices[2]]]));}temp_sides.push(u);}}}
if(pip){
smooth_v1=normals_of_sides[0][0]; smooth_v2=normals_of_sides[0][1]; smooth_v3=normals_of_sides[0][2];
for(w=1; w<normals_of_sides.length; w++){
if(normals_of_sides[w][0]*normals_of_sides[0][0]+normals_of_sides[w][1]*normals_of_sides[0][1]+normals_of_sides[w][2]*normals_of_sides[0][2]>Math.cos(crease_angle)){smooth_v1+=normals_of_sides[w][0]; smooth_v2+=normals_of_sides[w][1]; smooth_v3+=normals_of_sides[w][2];}else{}}
var magPs = Math.sqrt((smooth_v1*smooth_v1)+(smooth_v2*smooth_v2)+(smooth_v3*smooth_v3));
tms=1/magPs; pss1=smooth_v1*tms; pss2=smooth_v2*tms; pss3=smooth_v3*tms;
thismodel.side[temp_sides[0]].normal=[pss1,pss2,pss3,tms];
}else{f.normal=[normals_of_sides[0][0],normals_of_sides[0][1],normals_of_sides[0][2],normals_of_sides[0][3]];}
}}
if(times==2){ cstr="<font color='grey'>"; cstr+="<font color='white'>"; for(wcol=0; wcol<tik+1; wcol++){cstr+="#";} cstr+="</font>";
for(wcol=0; wcol<(20-(tik+1)); wcol++){cstr+="#";} cstr+="</font>";
document.getElementById("t1").innerHTML="calculating normals (creaseAngle) > please wait < "+cstr;
}else if(times==1){calculate_process=false;}}
calculate_process=true;
if(thismodel.side.length>100){
vx=parseInt(thismodel.side.length/20);
document.getElementById("widget").style.opacity=1; 
tik=0; calculate=function(){if(tik>=20){calculate_process=false;render(Fshape);do_actions();document.getElementById("widget").style.opacity=0;
clearInterval(tik_interval);}else{do_calculating(vx,tik,2);}tik++;}
var tik_interval=setInterval("calculate()",1000);
}else{do_calculating(thismodel.side.length,0,1);}
}//end of creaseAngle computation

// *******************************************************************************************
//render shape
function rendershape(type,typep,typepsolid,n,typesn){
//how_many_objects=n+1;
if(s_transformArray.length!=0){ tx=Number(s_transformArray[0]); ty=Number(s_transformArray[1]); ty=-ty; tz=Number(s_transformArray[2]);}else{tx=ty=tz=0;}

if(s_scaleArray.length!=0){ sx=Number(s_scaleArray[0]); sy=Number(s_scaleArray[1]); sz=Number(s_scaleArray[2]);}else{sx=sy=sz=1;}
if(s_rotationArray.length!=0){ rx=Number(s_rotationArray[0]); ry=Number(s_rotationArray[1]); rz=Number(s_rotationArray[2]); ra=Number(s_rotationArray[3]);	
}else{rx=0; ry=0; rz=0; ra=0;};

if(s_rotationArray2.length!=0){ rx2=Number(s_rotationArray2[0]); ry2=Number(s_rotationArray2[1]); rz2=Number(s_rotationArray2[2]); ra2=Number(s_rotationArray2[3]);
}else{rx2=0; ry2=0; rz2=0; ra2=0;};

fs=2*38;typesolid=typepsolid;

// *******************************************************************************************
//render Box
if(type=="Box"){
fs=2*38; w=typep.p1/2; h=typep.p2/2; d=typep.p3/2; c1=typep.p4; c2=typep.p5; c3=typep.p6; a=typep.p7;
shininess=Number(typep.p8); ambientintensity=Number(typep.p9); specularcolorred=Number(typep.p10); specularcolorgreen=Number(typep.p11);
specularcolorblue=Number(typep.p12); emissivecolorred=Number(typep.p13); emissivecolorgreen=Number(typep.p14); emissivecolorblue=Number(typep.p15);
texture=String(typep.p16); creaseangle=0; our_mt=String(typep.p17);
shape={}; shape.vertexList=[]; shape.side=[]; //fs=fs/2;
shape.vertexList.push({x:-w*fs,y:-h*fs,z:d*fs}); shape.vertexList.push({x:w*fs,y:-h*fs,z:d*fs});
shape.vertexList.push({x:w*fs,y:-h*fs,z:-d*fs}); shape.vertexList.push({x:-w*fs,y:-h*fs,z:-d*fs});
shape.vertexList.push({x:-w*fs,y:h*fs,z:d*fs}); shape.vertexList.push({x:w*fs,y:h*fs,z:d*fs});
shape.vertexList.push({x:w*fs,y:h*fs,z:-d*fs}); shape.vertexList.push({x:-w*fs,y:h*fs,z:-d*fs});
thiscolor=[c1,c2,c3,shininess,ambientintensity,specularcolorred,specularcolorgreen,specularcolorblue,emissivecolorred,emissivecolorgreen,emissivecolorblue];
rn=Fshape.FvertexList.length;if(texture!=""){
shape.side.push({vertices:[0+rn,1+rn,2+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[2+rn,3+rn,0+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[2+rn,1+rn,5+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[5+rn,6+rn,2+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[1+rn,0+rn,4+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[4+rn,5+rn,1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[5+rn,4+rn,7+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[7+rn,6+rn,5+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[0+rn,3+rn,7+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[7+rn,4+rn,0+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[3+rn,2+rn,6+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[6+rn,7+rn,3+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});}else{
shape.side.push({vertices:[0+rn,1+rn,2+rn,3+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[2+rn,1+rn,5+rn,6+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[1+rn,0+rn,4+rn,5+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[5+rn,4+rn,7+rn,6+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[0+rn,3+rn,7+rn,4+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[3+rn,2+rn,6+rn,7+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});};

// *******************************************************************************************
//render Sphere
}else if(type=="Sphere"){
dosphere=function(s1,s2){
r=typep.p1*1.8*40; c1=typep.p2; c2=typep.p3; c3=typep.p4; a=typep.p5; 
shininess=Number(typep.p8); ambientintensity=Number(typep.p9); specularcolorred=Number(typep.p10); specularcolorgreen=Number(typep.p11);
specularcolorblue=Number(typep.p12); emissivecolorred=Number(typep.p13); emissivecolorgreen=Number(typep.p14); emissivecolorblue=Number(typep.p15);
texture=String(typep.p16); ui=Number(typep.p17); creaseangle=0; our_mt=String(typep.p18);
shape={}; shape.vertexList=[]; shape.side=[]; na=Number(s1); nn=Number(s2); istep=2*Math.PI/na; jstep=Math.PI/nn;
for(i=0;i<=na;i++){ for(j=0;j<=nn;j++){ if(j==nn){
shape.vertexList.push({x:10000000000*r*Math.cos(istep*i)*Math.sin(jstep*j),y:10000000000*r*Math.sin(istep*i)*Math.sin(jstep*j),z:r*Math.cos(jstep*j)});
}else{ shape.vertexList.push({x:r*Math.cos(istep*i)*Math.sin(jstep*j),y:r*Math.sin(istep*i)*Math.sin(jstep*j),z:r*Math.cos(jstep*j)});}}}
var rad = 90*Math.PI/180; var sin = Math.sin(rad); var cos = Math.cos(rad); var matrix = {a:1,b:0,c:0,d:0,e:cos,f:sin,g:0,h:-sin,i:cos};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix.a+n_y*matrix.b+n_z*matrix.c; shape.vertexList[i].y=n_x*matrix.d+n_y*matrix.e+n_z*matrix.f;
shape.vertexList[i].z=n_x*matrix.g+n_y*matrix.h+n_z*matrix.i;}
thiscolor=[c1,c2,c3,shininess,ambientintensity,specularcolorred,specularcolorgreen,specularcolorblue,emissivecolorred,emissivecolorgreen,emissivecolorblue];
rn=Fshape.FvertexList.length;
for(j=0; j<na; j++){ for(i=0; i<nn; i++){if(texture!=""){		
shape.side.push({vertices:[nn+i+1+(nn+1)*j+rn,nn+i+2+(nn+1)*j+rn,i+1+(nn+1)*j+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"sphere_a_"+(j)+"_"+(nn-1-i),total:na+"_"+nn,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[i+1+(nn+1)*j+rn,i+(nn+1)*j+rn,nn+i+1+(nn+1)*j+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,sidename:"sphere_b_"+(j)+"_"+(nn-1-i),total:na+"_"+nn,objanchor:n,motiontextures:our_mt});}else{
shape.side.push({vertices:[nn+i+1+(nn+1)*j+rn,nn+i+2+(nn+1)*j+rn,i+1+(nn+1)*j+rn,i+(nn+1)*j+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}}};}
if(typesn==1){ meshAngles=typep.p6; meshSides=typep.p7; }else if(typesn==0){ meshAngles=20; meshSides=10; }; dosphere(meshAngles,meshSides);

// *******************************************************************************************
//render Cone
}else if(type=="Cone"){
docone=function(s1){
r=typep.p1*1.8*40; h=typep.p2*1.8*40; bottom=typep.p3; side=typep.p4; c1=typep.p5; c2=typep.p6; c3=typep.p7; a=typep.p8;
shininess=Number(typep.p10); ambientintensity=Number(typep.p11); specularcolorred=Number(typep.p12); specularcolorgreen=Number(typep.p13);
specularcolorblue=Number(typep.p14); emissivecolorred=Number(typep.p15); emissivecolorgreen=Number(typep.p16); emissivecolorblue=Number(typep.p17);
texture=String(typep.p18); creaseangle=0; our_mt=String(typep.p19);
shape={}; shape.vertexList=[]; shape.side=[]; nn=Number(s1); istep=2*Math.PI/nn;
for(i=0; i<nn; i++){shape.vertexList.push({x:2*r*Math.cos(i*istep)/2,y:h/2,z:2*r*Math.sin(i*istep)/2});}
shape.vertexList.push({x:0,y:h/2,z:0}); shape.vertexList.push({x:0,y:-h/2,z:0});
thiscolor=[c1,c2,c3,shininess,ambientintensity,specularcolorred,specularcolorgreen,specularcolorblue,emissivecolorred,emissivecolorgreen,emissivecolorblue];
rn=Fshape.FvertexList.length; if(side=="true"){for(j=0; j<nn-1; j++){if(texture!=""){	
shape.side.push({vertices:[shape.vertexList.length-1+rn,j+1+rn,j+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"conus_a"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});}else{
shape.side.push({vertices:[shape.vertexList.length-1+rn,j+1+rn,j+rn,shape.vertexList.length-1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}};if(texture!=""){
shape.side.push({vertices:[shape.vertexList.length-1+rn,0+rn,nn-1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"conus_a"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});}else{
shape.side.push({vertices:[shape.vertexList.length-1+rn,0+rn,nn-1+rn,shape.vertexList.length-1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}};if(bottom=="true"){
for(j=0; j<nn-1; j++){if(texture!=""){	
shape.side.push({vertices:[nn+rn,j+rn,j+1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"conus_c"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[j+1+rn,nn+rn,nn+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,sidename:"conus_c"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});}else{
shape.side.push({vertices:[nn+rn,j+rn,j+1+rn,nn+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}};if(texture!=""){
shape.side.push({vertices:[nn+rn,nn-1+rn,0+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"conus_c"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[0+rn,nn+rn,nn+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,sidename:"conus_c"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});}else{
shape.side.push({vertices:[nn+rn,nn-1+rn,0+rn,nn+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}calculate_process=false;}}
if(typesn==1){ meshSides=typep.p9; } else if(typesn==0){meshSides=20;} docone(meshSides);

// *******************************************************************************************
//render Cylinder
}else if(type=="Cylinder"){
docylinder=function(s1){
r=typep.p1*1.8*40; h=typep.p2*1.8*40; my_bottom=typep.p3; side=typep.p4; my_top=typep.p5; c1=typep.p6; c2=typep.p7; c3=typep.p8; a=typep.p9;
shininess=Number(typep.p11); ambientintensity=Number(typep.p12); specularcolorred=Number(typep.p13); specularcolorgreen=Number(typep.p14);
specularcolorblue=Number(typep.p15); emissivecolorred=Number(typep.p16); emissivecolorgreen=Number(typep.p17); emissivecolorblue=Number(typep.p18); creaseangle=0; texture=String(typep.p19); our_mt=String(typep.p20);
shape={}; shape.vertexList=[]; shape.side=[]; nn=Number(s1); istep=2*Math.PI/nn;
for(i=0; i<nn; i++){shape.vertexList.push({x:2*r*Math.cos(i*istep)/2,y:h/2,z:2*r*Math.sin(i*istep)/2});}
for(i=0; i<nn; i++){shape.vertexList.push({x:2*r*Math.cos(i*istep)/2,y:-h/2,z:2*r*Math.sin(i*istep)/2});}
shape.vertexList.push({x:0,y:h/2,z:0}); shape.vertexList.push({x:0,y:-h/2,z:0});
thiscolor=[c1,c2,c3,shininess,ambientintensity,specularcolorred,specularcolorgreen,specularcolorblue,emissivecolorred,emissivecolorgreen,emissivecolorblue];
rn=Fshape.FvertexList.length;
if(my_bottom=="true"){for(var j=0; j<nn-1; j++){if(texture!=""){	
shape.side.push({vertices:[shape.vertexList.length-2+rn,j+rn,j+1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"cylinder_c"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[j+1+rn,shape.vertexList.length-2+rn,shape.vertexList.length-2+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,sidename:"cylinder_c"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});}else{
shape.side.push({vertices:[shape.vertexList.length-2+rn,j+rn,j+1+rn,shape.vertexList.length-2+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}};if(texture!=""){
shape.side.push({vertices:[shape.vertexList.length-2+rn,nn-1+rn,0+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"cylinder_c"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[0+rn,shape.vertexList.length-2+rn,shape.vertexList.length-2+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,sidename:"cylinder_c"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});}else{
shape.side.push({vertices:[shape.vertexList.length-2+rn,nn-1+rn,0+rn,shape.vertexList.length-2+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}}
if(my_top=="true"){for(var j=0; j<nn-1; j++){if(texture!=""){	
shape.side.push({vertices:[shape.vertexList.length-1+rn,j+1+nn+rn,j+nn+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"cylinder_c"+(j),total:nn,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[j+nn+rn,shape.vertexList.length-1+rn,shape.vertexList.length-1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,sidename:"cylinder_c"+(j),total:nn,objanchor:n,motiontextures:our_mt});
}else{
shape.side.push({vertices:[shape.vertexList.length-1+rn,j+1+nn+rn,j+nn+rn,shape.vertexList.length-1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}};if(texture!=""){
shape.side.push({vertices:[shape.vertexList.length-1+rn,0+nn+rn,nn-1+nn+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"cylinder_c"+(j),total:nn,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[nn-1+nn+rn,shape.vertexList.length-1+rn,shape.vertexList.length-1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,sidename:"cylinder_c"+(j),total:nn,objanchor:n,motiontextures:our_mt});
}else{
shape.side.push({vertices:[shape.vertexList.length-1+rn,0+nn+rn,nn-1+nn+rn,shape.vertexList.length-1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}}
if(side=="true"){for(var j=0; j<nn-1; j++){if(texture!=""){	
shape.side.push({vertices:[j+rn,j+nn+rn,j+1+nn+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"cylinder_a"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[j+1+nn+rn,j+1+rn,j+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,sidename:"cylinder_b"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});}else{
shape.side.push({vertices:[j+rn,j+nn+rn,j+1+nn+rn,j+1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}};if(texture!=""){
shape.side.push({vertices:[2*nn-1+rn,nn+rn,0+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,sidename:"cylinder_a"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:[0+rn,nn-1+rn,2*nn-1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,sidename:"cylinder_b"+(nn-1-j),total:nn,objanchor:n,motiontextures:our_mt});}else{
shape.side.push({vertices:[2*nn-1+rn,nn+rn,0+rn,nn-1+rn],sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}}
shapes_stack.push(shape.vertexList.length);calculate_process=false;};
if(typesn==1){ meshSides=typep.p10; }else if(typesn==0){ meshSides=20; }docylinder(meshSides);

// *******************************************************************************************
//render IndexedFaceSet
}else if(type=="IndexedFaceSet"){
sides=typep.p1; verts=typep.p2; myccw=typep.p3; creaseangle=Number(typep.p4); colors=typep.p5; c1=typep.p6; c2=typep.p7; c3=typep.p8; a=typep.p9;
shininess=Number(typep.p10); ambientintensity=Number(typep.p11); specularcolorred=Number(typep.p12); specularcolorgreen=Number(typep.p13);
specularcolorblue=Number(typep.p14); emissivecolorred=Number(typep.p15); emissivecolorgreen=Number(typep.p16); emissivecolorblue=Number(typep.p17);
rtp=typep.p18; texture=String(typep.p19); convex=String(typep.p20); inner_tex_coords=typep.p21; inner_tex_array=typep.p22; our_mt=String(typep.p23); 
shape={}; shape.vertexList=[]; shape.side=[];
for(i=0; i<verts.length; i++){shape.vertexList.push({x:Number(verts[i][0])*fs,y:Number(verts[i][1])*fs,z:Number(verts[i][2])*fs});}
var matrix2 = {a:1,b:0,c:0,d:0,e:-1,f:0,g:0,h:0,i:1};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c; shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}; rn=Fshape.FvertexList.length;
for(i=0; i<sides.length; i++){temp_verts=[]; for(j=0; j<sides[i].length; j++){temp_verts.push(Number(sides[i][j])+rn);}
if(myccw=="false"){temp_verts=temp_verts.reverse();}else{}
if(sides[i].length<4){temp_verts.push(Number(sides[i][sides[i].length-1])+rn);};if(i>colors.length-1 || colors.length==1){
thiscolor=[c1,c2,c3,shininess,ambientintensity,specularcolorred,specularcolorgreen,specularcolorblue,emissivecolorred,emissivecolorgreen,emissivecolorblue];
alf=a;}else{tc1=Number(colors[i][0]);tc2=Number(colors[i][1]);tc3=Number(colors[i][2]);if(colors[i].length==4){alf=Number(colors[i][3]);}else{alf=a;}
thiscolor=[tc1,tc2,tc3,shininess,ambientintensity,specularcolorred,specularcolorgreen,specularcolorblue,emissivecolorred,emissivecolorgreen,emissivecolorblue];}
if(rtp.length!=0){alf=rtp[i];}
if(texture==""){shape.side.push({vertices:temp_verts,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}else{
if(temp_verts.length==4){
temp_verts_1=[temp_verts[0],temp_verts[1],temp_verts[2]];temp_verts_2=[temp_verts[2],temp_verts[3],temp_verts[0]];
if(inner_tex_array!=""){
if(String(inner_tex_array[i][3])=="undefined"){inner_tex_array[i][3]=inner_tex_array[i][0]}
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,
texture_map:[inner_tex_array[i][0],inner_tex_array[i][1],inner_tex_array[i][2]],objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:temp_verts_2,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,texture_map:[inner_tex_array[i][2],inner_tex_array[i][3],inner_tex_array[i][0]],objanchor:n,motiontextures:our_mt});
}else{
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:temp_verts_2,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});	
}
}else{ if(convex=="true"){
if((Math.round(temp_verts.length/3)-temp_verts.length/3)>0){add=true}else{add=false}
for(u=0; u<Math.round(temp_verts.length/3); u++){ if(u==Math.round(temp_verts.length/3)-1 && add){
temp_verts_1=[temp_verts[0],temp_verts[2*u+1],temp_verts[2*u+2]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}else{
temp_verts_1=[temp_verts[2*u+2],temp_verts[2*u+1],temp_verts[0]]; temp_verts_2=[temp_verts[2*u+3],temp_verts[2*u+2],temp_verts[0]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:temp_verts_2,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});}}}else{
if((Math.round(temp_verts.length/3)-temp_verts.length/3)>0){add=true}else{add=false}
for(u=0; u<temp_verts.length-2; u++){ if(u==temp_verts.length-3 && add){
temp_verts_1=[temp_verts[temp_verts.length-(u+1)],temp_verts[temp_verts.length-(u)],temp_verts[u+1]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}else{
if(u==0){ temp_verts_1=[temp_verts[temp_verts.length-(u+1)],u,temp_verts[u+1]];	}else{
temp_verts_1=[temp_verts[temp_verts.length-(u+1)],temp_verts[temp_verts.length-(u)],temp_verts[u+1]];}
temp_verts_2=[temp_verts[temp_verts.length-(u+1)],temp_verts[u+1],temp_verts[u+2]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:temp_verts_2,sideColor:thiscolor,sideAlpha:alf,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});}}}}}};
if(real_norm_verts_array!=0){apply_normals(shape);};if(creaseangle>0){ make_creaseAngle(creaseangle,shape); }//else{calculate_process=false;render(Fshape);}

// *******************************************************************************************
//render Text
}else if(type=="Text"){
our_str=typep.p1; our_size=typep.p2; our_spacing=typep.p3; our_style=typep.p4;
if(our_style.indexOf('"')!=-1){our_style=our_style.substring(our_style.indexOf('"')+1,our_style.lastIndexOf('"'));}
if(our_style=='BOLD'){thisstyle=8;}else if(our_style=='PLAIN'){thisstyle=3;}
c1=typep.p5; c2=typep.p6; c3=typep.p7; a=typep.p8; shininess=Number(typep.p9);
ambientintensity=Number(typep.p10); specularcolorred=Number(typep.p11); specularcolorgreen=Number(typep.p12); specularcolorblue=Number(typep.p13);
emissivecolorred=Number(typep.p14); emissivecolorgreen=Number(typep.p15); emissivecolorblue=Number(typep.p16); creaseangle=0;
shape={}; shape.vertexList=[]; shape.side=[]; lx=our_spacing*14; ls=our_size*5; ld=2*lx; total_ld=(ld/2)*our_str.length; depth=-40-lx-ls; myz=0;
letters_pos=new Array();
for(i=0; i<our_str.length; i++){ sd=ld/2*(i+1)-(ld/2)*(our_str.length-i);
if(our_str.charAt(i) == " "){	
shape.vertexList.push({x:0*ls+sd,y:(0*ls+depth+lx),z:myz});
letters_pos.push(1);
} else if(our_str.charAt(i) == "A"){
shape.vertexList.push({x:-1.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});	
shape.vertexList.push({x:0.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.75*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.25*ls+sd,y:(3.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.25*ls+sd,y:(3.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.75*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1*ls+sd,y:(5.5*ls+depth+lx),z:myz});
letters_pos.push(10);
} else if (our_str.charAt(i) == "B"){
shape.vertexList.push({x:-2.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(0.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.75*ls+sd,y:(1*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(1.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.75*ls+sd,y:(2*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(2.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.25*ls+sd,y:(2.9*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.6*ls+sd,y:(2.9*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(3.05*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.1*ls+sd,y:(3.3*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.4*ls+sd,y:(4*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.1*ls+sd,y:(4.7*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.5*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.6*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.6*ls+sd,y:(0.5*ls+depth+lx),z:myz});
letters_pos.push(17);
} else if (our_str.charAt(i) == "C"){
shape.vertexList.push({x:2*ls+sd,y:(2*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(0.25*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(0.25*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1*ls+sd,y:(0.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.75*ls+sd,y:(2*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2*ls+sd,y:(3*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(4.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1*ls+sd,y:(5.25*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(5*ls+depth+lx),z:myz});
letters_pos.push(12);
} else if (our_str.charAt(i) == "D"){
shape.vertexList.push({x:-2.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.75*ls+sd,y:(1.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(3*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.75*ls+sd,y:(4.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
letters_pos.push(9);
} else if (our_str.charAt(i) == "E"){
shape.vertexList.push({x:-2.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(1.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.25*ls+sd,y:(2.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.75*ls+sd,y:(2.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.75*ls+sd,y:(2*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.75*ls+sd,y:(3.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(4*ls+depth+lx),z:myz});
letters_pos.push(12);
} else if (our_str.charAt(i) == "F"){
shape.vertexList.push({x:-2.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(1.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.25*ls+sd,y:(2.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.75*ls+sd,y:(2.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.75*ls+sd,y:(2*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.75*ls+sd,y:(3.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
letters_pos.push(11);
} else if (our_str.charAt(i) == "G"){
shape.vertexList.push({x:1.75*ls+sd,y:(0.25*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.75*ls+sd,y:(1.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.25*ls+sd,y:(0.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(0.1*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.4*ls+sd,y:(1*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.1*ls+sd,y:(3*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.3*ls+sd,y:(5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(5.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.75*ls+sd,y:(5.25*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.75*ls+sd,y:(3.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.25*ls+sd,y:(3.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.25*ls+sd,y:(3.5*ls+depth+lx),z:myz});
letters_pos.push(12);
} else if (our_str.charAt(i) == "H"){
shape.vertexList.push({x:2.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.5*ls+sd,y:(2.8*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(2.8*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
letters_pos.push(14);
} else if (our_str.charAt(i) == "I"){
shape.vertexList.push({x:1.75*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.75*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.75*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.75*ls+sd,y:(5.5*ls+depth+lx),z:myz});
letters_pos.push(6);
} else if (our_str.charAt(i) == "J"){
shape.vertexList.push({x:-1.2*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.9*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.9*ls+sd,y:(4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.5*ls+sd,y:(5.2*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.5*ls+sd,y:(5.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(5.1*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(3.5*ls+depth+lx),z:myz});
letters_pos.push(8);
} else if (our_str.charAt(i) == "K"){
shape.vertexList.push({x:-2.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.6*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.3*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.3*ls+sd,y:(3.25*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.6*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.3*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.6*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.4*ls+sd,y:(2.7*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.2*ls+sd,y:(3*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.75*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:3*ls+sd,y:(5.5*ls+depth+lx),z:myz});
letters_pos.push(14);
} else if (our_str.charAt(i) == "L"){
shape.vertexList.push({x:-2.4*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.1*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.1*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.4*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.1*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.1*ls+sd,y:(3.5*ls+depth+lx),z:myz});
letters_pos.push(7);
} else if (our_str.charAt(i) == "M"){
shape.vertexList.push({x:2.4*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.4*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.8*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.6*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.9*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(3.75*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.4*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.8*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.4*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.9*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.6*ls+sd,y:(5.4*ls+depth+lx),z:myz});
letters_pos.push(13);	
} else if (our_str.charAt(i) == "N"){
shape.vertexList.push({x:-2.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.6*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.6*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.5*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.4*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.7*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.7*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.4*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.6*ls+sd,y:(0.5*ls+depth+lx),z:myz});
letters_pos.push(9);	
} else if (our_str.charAt(i) == "O"){
shape.vertexList.push({x:-0*ls+sd,y:(0.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.9*ls+sd,y:(0.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.4*ls+sd,y:(1*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.9*ls+sd,y:(2*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.1*ls+sd,y:(3*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.9*ls+sd,y:(4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.4*ls+sd,y:(5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.9*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(5.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.9*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.4*ls+sd,y:(5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.9*ls+sd,y:(4*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.1*ls+sd,y:(3*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.9*ls+sd,y:(2*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.4*ls+sd,y:(1*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.9*ls+sd,y:(0.6*ls+depth+lx),z:myz});
letters_pos.push(16);	
} else if (our_str.charAt(i) == "P"){
shape.vertexList.push({x:-2.2*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(0.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.7*ls+sd,y:(1.1*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(2*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.7*ls+sd,y:(2.9*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(3.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(3.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.1*ls+sd,y:(3.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.1*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.5*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.2*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.1*ls+sd,y:(0.5*ls+depth+lx),z:myz});
letters_pos.push(13);
} else if(our_str.charAt(i) == "Q"){
shape.vertexList.push({x:0*ls+sd,y:(0.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.9*ls+sd,y:(0.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.4*ls+sd,y:(1*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.9*ls+sd,y:(2*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.1*ls+sd,y:(3*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.9*ls+sd,y:(4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.4*ls+sd,y:(5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.9*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(5.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.9*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.3*ls+sd,y:(6.7*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.4*ls+sd,y:(6.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(6.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.4*ls+sd,y:(6.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.3*ls+sd,y:(6.7*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.1*ls+sd,y:(6.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.4*ls+sd,y:(5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.9*ls+sd,y:(4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.1*ls+sd,y:(3*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.9*ls+sd,y:(2*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.4*ls+sd,y:(1*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.9*ls+sd,y:(0.6*ls+depth+lx),z:myz});
letters_pos.push(22);
} else if(our_str.charAt(i) == "R"){
shape.vertexList.push({x:-2.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(0.8*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.4*ls+sd,y:(1.2*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.6*ls+sd,y:(1.8*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.4*ls+sd,y:(2.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(2.8*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(2.8*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.6*ls+sd,y:(3.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.9*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(2.8*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
letters_pos.push(16);	
} else if(our_str.charAt(i) == "S"){
shape.vertexList.push({x:1.5*ls+sd,y:(0.3*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.7*ls+sd,y:(1.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.5*ls+sd,y:(1*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(0.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(0.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1*ls+sd,y:(0.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.4*ls+sd,y:(0.9*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.7*ls+sd,y:(1.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.3*ls+sd,y:(2.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.4*ls+sd,y:(2.9*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(3.1*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.6*ls+sd,y:(3.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.8*ls+sd,y:(4.1*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.6*ls+sd,y:(5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0*ls+sd,y:(5.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.9*ls+sd,y:(4.1*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(5.6*ls+depth+lx),z:myz});
letters_pos.push(19);
} else if(our_str.charAt(i) == "T"){
shape.vertexList.push({x:2.2*ls+sd,y:(2.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:2*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.2*ls+sd,y:(2.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.4*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.4*ls+sd,y:(5.4*ls+depth+lx),z:myz});
letters_pos.push(8);	
} else if(our_str.charAt(i) == "U"){
shape.vertexList.push({x:2.5*ls+sd,y:(0.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.6*ls+sd,y:(0.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.7*ls+sd,y:(0.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.7*ls+sd,y:(3.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.6*ls+sd,y:(4.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.9*ls+sd,y:(5.3*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.9*ls+sd,y:(5.3*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.6*ls+sd,y:(4.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.7*ls+sd,y:(3.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.7*ls+sd,y:(0.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.5*ls+sd,y:(0.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.6*ls+sd,y:(0.4*ls+depth+lx),z:myz});
letters_pos.push(13);	
} else if(our_str.charAt(i) == "V"){
shape.vertexList.push({x:2.7*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.8*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.1*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.1*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.8*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.7*ls+sd,y:(0.5*ls+depth+lx),z:myz});
letters_pos.push(7);
} else if(our_str.charAt(i) == "W"){
shape.vertexList.push({x:2.7*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.2*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.8*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.3*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(1.8*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.3*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.2*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.8*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.7*ls+sd,y:(0.5*ls+depth+lx),z:myz});
letters_pos.push(9);
} else if(our_str.charAt(i) == "X"){
shape.vertexList.push({x:2.2*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.7*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.8*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(3*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.8*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.2*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.7*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.8*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.7*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.2*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.8*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.7*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.2*ls+sd,y:(0.5*ls+depth+lx),z:myz});
letters_pos.push(13);
} else if(our_str.charAt(i) == "Y"){
shape.vertexList.push({x:2.4*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.6*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.8*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(3.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.5*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.8*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.6*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.4*ls+sd,y:(0.5*ls+depth+lx),z:myz});
letters_pos.push(10);
} else if(our_str.charAt(i) == "Z"){
shape.vertexList.push({x:-1.5*ls+sd,y:(2.2*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.4*ls+sd,y:(0.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.5*ls+sd,y:(0.6*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.8*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.3*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.4*ls+sd,y:(3.7*ls+depth+lx),z:myz});
letters_pos.push(6);
}else if(our_str.charAt(i) == "1"){
shape.vertexList.push({x:-2.2*ls+sd,y:(2.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.4*ls+sd,y:(5.4*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.4*ls+sd,y:(5.4*ls+depth+lx),z:myz});
letters_pos.push(5);	
} else if (our_str.charAt(i) == "2" || our_str.charAt(i) == "3" || our_str.charAt(i) == "4" || our_str.charAt(i) == "5" || our_str.charAt(i) == "6" || our_str.charAt(i) == "7" || our_str.charAt(i) == "8" || our_str.charAt(i) == "9" || our_str.charAt(i) == "0"){
shape.vertexList.push({x:2.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.5*ls+sd,y:(2.8*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(2.8*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.5*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(0.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-1.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-2.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:-0.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:1.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:2.25*ls+sd,y:(5.5*ls+depth+lx),z:myz});
shape.vertexList.push({x:0.5*ls+sd,y:(5.5*ls+depth+lx),z:myz});
letters_pos.push(14);
}} //end of for
thiscolor=[c1,c2,c3,shininess,ambientintensity,specularcolorred,specularcolorgreen,specularcolorblue,emissivecolorred,emissivecolorgreen,emissivecolorblue];
rn=Fshape.FvertexList.length;
for(i=0; i<our_str.length; i++){
if(i==0) {lv=0;} else { lv+=letters_pos[i-1]; }
if(our_str.charAt(i) == " "){
shape.side.push({vertices:[lv+rn,lv+rn,lv+rn,lv+rn],sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description});
} else if(our_str.charAt(i) == "A"){
va=[5+lv+rn,6+lv+rn,7+lv+rn,9+lv+rn,8+lv+rn,7+lv+rn,6+lv+rn,1+lv+rn,lv+rn,1+lv+rn,5+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,2+lv+rn,5+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
} else if(our_str.charAt(i) == "B"){
va=[8+lv+rn,7+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn,1+lv+rn,lv+rn,1+lv+rn,16+lv+rn,15+lv+rn,14+lv+rn,15+lv+rn,13+lv+rn,12+lv+rn,11+lv+rn,10+lv+rn,9+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
} else if(our_str.charAt(i) == "C"){
va=[6+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,11+lv+rn,10+lv+rn,9+lv+rn,8+lv+rn,7+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,1+lv+rn,lv+rn,1+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
} else if(our_str.charAt(i) == "D"){
va=[1+lv+rn,7+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn,1+lv+rn,lv+rn,1+lv+rn,7+lv+rn,8+lv+rn,7+lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
} else if(our_str.charAt(i) == "E"){
va=[8+lv+rn,1+lv+rn,lv+rn,2+lv+rn,3+lv+rn,2+lv+rn,1+lv+rn,4+lv+rn,5+lv+rn,7+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,11+lv+rn,10+lv+rn,8+lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
} else if(our_str.charAt(i) == "F"){
va=[8+lv+rn,3+lv+rn,lv+rn,1+lv+rn,2+lv+rn,1+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,7+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,8+lv+rn]	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
} else if(our_str.charAt(i) == "G"){
va=[5+lv+rn,6+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,11+lv+rn,10+lv+rn,9+lv+rn,8+lv+rn,7+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn,1+lv+rn,0+lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
} else if(our_str.charAt(i) == "H"){
va=[lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,11+lv+rn,12+lv+rn,13+lv+rn,11+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,5+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,8+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn,lv+rn]; va=va.reverse();	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
} else if(our_str.charAt(i) == "I"){
va=[lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,3+lv+rn,2+lv+rn,lv+rn]; va=va.reverse();	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
} else if(our_str.charAt(i) == "J"){
va=[3+lv+rn,2+lv+rn,lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
} else if(our_str.charAt(i) == "K"){
va=[3+lv+rn,2+lv+rn,lv+rn,1+lv+rn,lv+rn,2+lv+rn,3+lv+rn,10+lv+rn,4+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,10+lv+rn,3+lv+rn,11+lv+rn,12+lv+rn,13+lv+rn,12+lv+rn,11+lv+rn,3+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,7+lv+rn,3+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
} else if(our_str.charAt(i) == "L"){
la=[4+lv+rn,5+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn,1+lv+rn,lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn]; 
shape.side.push({vertices:la,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
} else if(our_str.charAt(i) == "M"){
va=[lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,3+lv+rn,2+lv+rn,1+lv+rn,6+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,8+lv+rn,10+lv+rn,11+lv+rn,12+lv+rn,10+lv+rn,8+lv+rn,7+lv+rn,6+lv+rn,1+lv+rn,2+lv+rn,lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
} else if(our_str.charAt(i) == "N"){
va=[2+lv+rn,1+lv+rn,lv+rn,1+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,8+lv+rn,6+lv+rn,5+lv+rn,1+lv+rn,2+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
} else if(our_str.charAt(i) == "O"){
la=[lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,11+lv+rn,12+lv+rn,13+lv+rn,14+lv+rn,15+lv+rn,lv+rn];	
shape.side.push({vertices:la,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});		
} else if(our_str.charAt(i) == "P"){
va=[8+lv+rn,12+lv+rn,lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,11+lv+rn,9+lv+rn,8+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});			
} else if(our_str.charAt(i) == "Q"){
va=[10+lv+rn,9+lv+rn,16+lv+rn,17+lv+rn,18+lv+rn,19+lv+rn,20+lv+rn,21+lv+rn,lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,11+lv+rn,12+lv+rn,13+lv+rn,14+lv+rn,15+lv+rn,14+lv+rn,13+lv+rn,12+lv+rn,11+lv+rn,10+lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});			
} else if(our_str.charAt(i) == "R"){
va=[12+lv+rn,15+lv+rn,lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,9+lv+rn,8+lv+rn,7+lv+rn,11+lv+rn,12+lv+rn,14+lv+rn,13+lv+rn,12+lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});			
} else if(our_str.charAt(i) == "S"){
va=[15+lv+rn,14+lv+rn,13+lv+rn,12+lv+rn,11+lv+rn,10+lv+rn,9+lv+rn,8+lv+rn,7+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn,1+lv+rn,lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,11+lv+rn,12+lv+rn,13+lv+rn,14+lv+rn,15+lv+rn,16+lv+rn,17+lv+rn,18+lv+rn,17+lv+rn,16+lv+rn,15+lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});			
} else if(our_str.charAt(i) == "T"){
va=[lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,2+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,5+lv+rn,4+lv+rn,1+lv+rn,lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});			
} else if(our_str.charAt(i) == "U"){
va=[lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,10+lv+rn,11+lv+rn,12+lv+rn,10+lv+rn,9+lv+rn,8+lv+rn,7+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn,lv+rn];va=va.reverse();	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});			
} else if(our_str.charAt(i) == "V"){
va=[lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn,lv+rn]; va=va.reverse();
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});			
} else if(our_str.charAt(i) == "W"){
va=[lv+rn,2+lv+rn,1+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,7+lv+rn,8+lv+rn,6+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,1+lv+rn,lv+rn]; va=va.reverse();
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
} else if(our_str.charAt(i) == "X"){
va=[lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,4+lv+rn,3+lv+rn,10+lv+rn,11+lv+rn,12+lv+rn,10+lv+rn,3+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,7+lv+rn,3+lv+rn,2+lv+rn,lv+rn]; va=va.reverse();
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
} else if(our_str.charAt(i) == "Y"){
va=[lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,6+lv+rn,4+lv+rn,3+lv+rn,7+lv+rn,8+lv+rn,9+lv+rn,7+lv+rn,3+lv+rn,2+lv+rn,lv+rn]; va=va.reverse();
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
} else if(our_str.charAt(i) == "Z"){
va=[3+lv+rn,2+lv+rn,1+lv+rn,lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
}else if(our_str.charAt(i) == "1"){
va=[2+lv+rn,1+lv+rn,0+lv+rn,1+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,2+lv+rn];	
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});			
} else if(our_str.charAt(i) == "2"){
va=[3+lv+rn,2+lv+rn,5+lv+rn,2+lv+rn,3+lv+rn,4+lv+rn,8+lv+rn,11+lv+rn,8+lv+rn,4+lv+rn,3+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
} else if(our_str.charAt(i) == "3"){
va=[4+lv+rn,3+lv+rn,2+lv+rn,5+lv+rn,2+lv+rn,11+lv+rn,8+lv+rn,11+lv+rn,3+lv+rn,4+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
}else if(our_str.charAt(i) == "4"){
va=[2+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,11+lv+rn];va=va.reverse();
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
}else if(our_str.charAt(i) == "5"){
va=[8+lv+rn,11+lv+rn,3+lv+rn,4+lv+rn,5+lv+rn,2+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,11+lv+rn,8+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
}else if(our_str.charAt(i) == "6"){
va=[8+lv+rn,11+lv+rn,3+lv+rn,4+lv+rn,8+lv+rn,11+lv+rn,8+lv+rn,5+lv+rn,2+lv+rn,5+lv+rn,8+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
}else if(our_str.charAt(i) == "7"){
va=[8+lv+rn,2+lv+rn,5+lv+rn,2+lv+rn,8+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
}else if(our_str.charAt(i) == "8"){
va=[2+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn,5+lv+rn,8+lv+rn,11+lv+rn,2+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
}else if(our_str.charAt(i) == "9"){
va=[2+lv+rn,5+lv+rn,4+lv+rn,3+lv+rn,2+lv+rn,5+lv+rn,2+lv+rn,11+lv+rn,8+lv+rn,11+lv+rn,2+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});	
}else if(our_str.charAt(i) == "0"){
va=[2+lv+rn,5+lv+rn,8+lv+rn,11+lv+rn,2+lv+rn,5+lv+rn,2+lv+rn];
shape.side.push({vertices:va,sideColor:thiscolor,sideAlpha:a,text:true,style:thisstyle,thisurl:url,thisparameter:parameter,thisdescription:description,objanchor:n});
}}//end of for
calculate_process=false;

// *******************************************************************************************
//render Extrusion
}else if(type=="Extrusion"){
ourcrosssection=typep.p1; ourbegincap=typep.p2; ourspine=typep.p3; ourendcap=typep.p4; ourscale=typep.p5; creaseangle=Number(typep.p6);
ourorientation=typep.p7; ourccw=typep.p8; c1=typep.p9; c2=typep.p10; c3=typep.p11; a=typep.p12; shininess=Number(typep.p13);
ambientintensity=Number(typep.p14); specularcolorred=Number(typep.p15); specularcolorgreen=Number(typep.p16); specularcolorblue=Number(typep.p17);
emissivecolorred=Number(typep.p18); emissivecolorgreen=Number(typep.p19); emissivecolorblue=Number(typep.p20); texture=String(typep.p21); convex=String(typep.p22);
our_mt=String(typep.p23); 
shape={}; shape.vertexList=[]; shape.side=[]; fs=2*38;
for(j=0; j<ourspine.length; j++){
for(i=0; i<ourcrosssection.length; i++){shape.vertexList.push({x:Number(ourcrosssection[i][0])*fs,y:0*fs,z:Number(ourcrosssection[i][1])*fs});}
if(ourscale.length>1){
matrix = {a:Number(ourscale[j][0]),b:0,c:0,d:0,e:0,f:0,g:0,h:0,i:Number(ourscale[j][1])};
for(i=0; i<ourcrosssection.length; i++){ sn_x=shape.vertexList[i+ourcrosssection.length*j].x; sn_y=shape.vertexList[i+ourcrosssection.length*j].y; 
sn_z=shape.vertexList[i+ourcrosssection.length*j].z; shape.vertexList[i+ourcrosssection.length*j].x=sn_x*matrix.a+sn_y*matrix.b+sn_z*matrix.c; 
shape.vertexList[i+ourcrosssection.length*j].y=sn_x*matrix.d+sn_y*matrix.e+sn_z*matrix.f;
shape.vertexList[i+ourcrosssection.length*j].z=sn_x*matrix.g+sn_y*matrix.h+sn_z*matrix.i;}}
if(ourorientation.length>1){ rad = Number(ourorientation[j][3]); sin = Math.sin(rad); cos = Math.cos(rad);
if(Number(ourorientation[j][0])!=0){matrix2 = {a:1,b:0,c:0,d:0,e:cos,f:sin,g:0,h:-sin,i:cos};
for(i=0; i<ourcrosssection.length; i++){ n_x=shape.vertexList[i+ourcrosssection.length*j].x; n_y=shape.vertexList[i+ourcrosssection.length*j].y;
n_z=shape.vertexList[i+ourcrosssection.length*j].z; shape.vertexList[i+ourcrosssection.length*j].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i+ourcrosssection.length*j].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i+ourcrosssection.length*j].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}
if(Number(ourorientation[j][1])!=0){matrix2 = {a:cos,b:0,c:-sin,d:0,e:1,f:0,g:sin,h:0,i:cos};
for(i=0; i<ourcrosssection.length; i++){ n_x=shape.vertexList[i+ourcrosssection.length*j].x; n_y=shape.vertexList[i+ourcrosssection.length*j].y;
n_z=shape.vertexList[i+ourcrosssection.length*j].z; shape.vertexList[i+ourcrosssection.length*j].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i+ourcrosssection.length*j].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i+ourcrosssection.length*j].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}
if(Number(ourorientation[j][2])!=0){matrix2 = {a:cos,b:sin,c:0,d:-sin,e:cos,f:0,g:0,h:0,i:1};
for(i=0; i<ourcrosssection.length; i++){ n_x=shape.vertexList[i+ourcrosssection.length*j].x; n_y=shape.vertexList[i+ourcrosssection.length*j].y;
n_z=shape.vertexList[i+ourcrosssection.length*j].z; shape.vertexList[i+ourcrosssection.length*j].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i+ourcrosssection.length*j].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i+ourcrosssection.length*j].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}}
for(i=0; i<ourcrosssection.length; i++){ shape.vertexList[i+ourcrosssection.length*j].x+=Number(ourspine[j][0])*fs;
shape.vertexList[i+ourcrosssection.length*j].y+=Number(ourspine[j][1])*fs; shape.vertexList[i+ourcrosssection.length*j].z+=Number(ourspine[j][2])*fs;}}
var rad2 = 180*Math.PI/180; var sin2 = Math.sin(rad2); var cos2 = Math.cos(rad2); var matrix2 = {a:1,b:0,c:0,d:0,e:cos2,f:sin2,g:0,h:-sin2,i:cos2};
for(i=0; i<shape.vertexList.length; i++){ n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c; shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}
thiscolor=[c1,c2,c3,shininess,ambientintensity,specularcolorred,specularcolorgreen,specularcolorblue,emissivecolorred,emissivecolorgreen,emissivecolorblue];
rn=Fshape.FvertexList.length; begin_verts=[];	for(i=0; i<ourcrosssection.length; i++){begin_verts.push(i);}	
all_verts=[]; for(i=0; i<ourspine.length; i++){inner_verts=[];
for(j=0; j<begin_verts.length; j++){inner_verts.push(begin_verts[j]+i*begin_verts.length);}
all_verts=all_verts.concat(inner_verts);}
if(ourbegincap=="true"){for(i=0; i<begin_verts.length; i++){begin_verts[i]=begin_verts[i]+rn;}
if(ourccw=="false"){begin_verts=begin_verts.reverse();}
if(texture==""){shape.side.push({vertices:begin_verts,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}else{ if(convex=="true"){
if((Math.round(begin_verts.length/3)-begin_verts.length/3)>0){add=true}else{add=false}
for(u=0; u<Math.round(begin_verts.length/3); u++){ if(u==Math.round(begin_verts.length/3)-1 && add){
temp_verts_1=[begin_verts[0],begin_verts[2*u+1],begin_verts[2*u+2]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}else{
temp_verts_1=[begin_verts[0],begin_verts[2*u+1],begin_verts[2*u+2]]; temp_verts_2=[begin_verts[0],begin_verts[2*u+2],begin_verts[2*u+3]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:temp_verts_2,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});}}	
}else{if((Math.round(begin_verts.length/3)-begin_verts.length/3)>0){add=true}else{add=false}
for(u=0; u<begin_verts.length-2; u++){ if(u==begin_verts.length-3 && add){
temp_verts_1=[begin_verts[begin_verts.length-(u+1)],begin_verts[begin_verts.length-(u)],begin_verts[u+1]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n});}else{ if(u==0){
temp_verts_1=[begin_verts[begin_verts.length-(u+1)],u,begin_verts[u+1]];}else{
temp_verts_1=[begin_verts[begin_verts.length-(u+1)],begin_verts[begin_verts.length-(u)],begin_verts[u+1]];}
temp_verts_2=[begin_verts[begin_verts.length-(u+1)],begin_verts[u+1],begin_verts[u+2]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:temp_verts_2,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});}}}}}; if(ourendcap=="true"){end_verts=[];
for(i=0; i<ourcrosssection.length; i++){end_verts.push(i+begin_verts.length*(ourspine.length-1));}
for(i=0; i<end_verts.length; i++){end_verts[i]=end_verts[i]+rn;}
if(ourccw=="false"){end_verts=end_verts.reverse();}
if(texture==""){shape.side.push({vertices:end_verts.reverse(),sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0});}else{ if(convex=="true"){ end_verts_temp=end_verts.reverse();
if((Math.round(end_verts_temp.length/3)-end_verts_temp.length/3)>0){add=true}else{add=false}
for(u=0; u<Math.round(end_verts_temp.length/3); u++){ if(u==Math.round(end_verts_temp.length/3)-1 && add){
temp_verts_1=[end_verts_temp[0],end_verts_temp[2*u+1],end_verts_temp[2*u+2]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}else{
temp_verts_1=[end_verts_temp[0],end_verts_temp[2*u+1],end_verts_temp[2*u+2]];
temp_verts_2=[end_verts_temp[0],end_verts_temp[2*u+2],end_verts_temp[2*u+3]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:temp_verts_2,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});}}}else{ end_verts_temp=end_verts.reverse();	
if((Math.round(end_verts_temp.length/3)-end_verts_temp.length/3)>0){add=true}else{add=false}
for(u=0; u<end_verts_temp.length-2; u++){ if(u==end_verts_temp.length-3 && add){
temp_verts_1=[end_verts_temp[end_verts_temp.length-(u+1)],end_verts_temp[end_verts_temp.length-(u)],end_verts_temp[u+1]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}else{
if(u==0){temp_verts_1=[end_verts_temp[end_verts_temp.length-(u+1)],u,end_verts_temp[u+1]];}else{
temp_verts_1=[end_verts_temp[end_verts_temp.length-(u+1)],end_verts_temp[end_verts_temp.length-(u)],end_verts_temp[u+1]];}
temp_verts_2=[end_verts_temp[end_verts_temp.length-(u+1)],end_verts_temp[u+1],end_verts_temp[u+2]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:temp_verts_2,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});}}}}};temp_verts=[];
for(j=0; j<ourspine.length-1; j++){ for(i=0; i<ourcrosssection.length-1; i++){
temp_verts=[all_verts[0+i+begin_verts.length*(j+1)]+rn,all_verts[1+i+begin_verts.length*(j+1)]+rn,all_verts[1+i+begin_verts.length*j]+rn,all_verts[0+i+begin_verts.length*j]+rn]; if(ourccw=="false"){temp_verts=temp_verts.reverse();}
if(texture==""){shape.side.push({vertices:temp_verts,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});}else{
if(temp_verts.length==4){temp_verts_1=[temp_verts[0],temp_verts[1],temp_verts[2]];temp_verts_2=[temp_verts[2],temp_verts[3],temp_verts[0]];
shape.side.push({vertices:temp_verts_1,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:0,objanchor:n,motiontextures:our_mt});
shape.side.push({vertices:temp_verts_2,sideColor:thiscolor,sideAlpha:a,thisurl:url,thisparameter:parameter,thisdescription:description,thistexture:texture,tn:1,objanchor:n,motiontextures:our_mt});}}}};if(ourbegincap=="false" || ourendcap=="false"){typesolid="false";}
if(creaseangle>0){ make_creaseAngle(creaseangle,shape); }else{calculate_process=false;}}

// *******************************************************************************************
//render transformations

if(sx==1 && sy==1 && sz==1){}else{
var matrix = {a:sx,b:0,c:0,d:0,e:sy,f:0,g:0,h:0,i:sz};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix.a+n_y*matrix.b+n_z*matrix.c;
shape.vertexList[i].y=n_x*matrix.d+n_y*matrix.e+n_z*matrix.f;
shape.vertexList[i].z=n_x*matrix.g+n_y*matrix.h+n_z*matrix.i;}}

if(s_rotationArray2.length==0){

if(ra!=0){
var rad = ra; var sin = Math.sin(rad); var cos = Math.cos(rad);
if(rx!=0){ var matrix2 = {a:1,b:0,c:0,d:0,e:cos,f:sin,g:0,h:-sin,i:cos};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}
if(ry!=0){ var matrix2 = {a:cos,b:0,c:-sin,d:0,e:1,f:0,g:sin,h:0,i:cos};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}
if(rz!=0){ var matrix2 = {a:cos,b:sin,c:0,d:-sin,e:cos,f:0,g:0,h:0,i:1};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}}

}else{

if(ra2!=0){
var rad = ra2; var sin = Math.sin(rad); var cos = Math.cos(rad);
if(rx2!=0){ var matrix2 = {a:1,b:0,c:0,d:0,e:cos,f:sin,g:0,h:-sin,i:cos};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}
if(ry2!=0){ var matrix2 = {a:cos,b:0,c:-sin,d:0,e:1,f:0,g:sin,h:0,i:cos};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}
if(rz2!=0){ var matrix2 = {a:cos,b:sin,c:0,d:-sin,e:cos,f:0,g:0,h:0,i:1};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}}
}

for(i=0; i<shape.vertexList.length; i++){
shape.vertexList[i].x+=tx*fs; shape.vertexList[i].y+=ty*fs; shape.vertexList[i].z+=tz*fs;}

if(s_rotationArray2.length!=0){
if(ra!=0){
var rad = ra; var sin = Math.sin(rad); var cos = Math.cos(rad);
if(rx!=0){ var matrix2 = {a:1,b:0,c:0,d:0,e:cos,f:sin,g:0,h:-sin,i:cos};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}
if(ry!=0){ var matrix2 = {a:cos,b:0,c:-sin,d:0,e:1,f:0,g:sin,h:0,i:cos};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}
if(rz!=0){ var matrix2 = {a:cos,b:sin,c:0,d:-sin,e:cos,f:0,g:0,h:0,i:1};
for(i=0; i<shape.vertexList.length; i++){
n_x=shape.vertexList[i].x; n_y=shape.vertexList[i].y; n_z=shape.vertexList[i].z;
shape.vertexList[i].x=n_x*matrix2.a+n_y*matrix2.b+n_z*matrix2.c;
shape.vertexList[i].y=n_x*matrix2.d+n_y*matrix2.e+n_z*matrix2.f;
shape.vertexList[i].z=n_x*matrix2.g+n_y*matrix2.h+n_z*matrix2.i;}}}	
}

// *******************************************************************************************
//AABB (Axis-Aligned Bounding Box) calculation for collision
focalLength=700; function CreateAABBFromVertices_local(Vertices){ var vMin=vMax=[];
vMax[0]=vMa0=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].x);
vMax[1]=vMa1=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].y);
vMax[2]=vMa2=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].z);
vMin[0]=vMi0=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].x);
vMin[1]=vMi1=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].y);
vMin[2]=vMi2=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].z);
for(var e=0;e<Vertices.length;e++) { for(var j=0; j<Vertices[e].vertices.length; j++) { var v=Vertices[e].vertices[j]-rn;
vMax[0]=vMa0; vMax[1]=vMa1; vMax[2]=vMa2; vMin[0]=vMi0; vMin[1]=vMi1; vMin[2]=vMi2; 
vMin[0]=Math.min(vMi0,parseInt(shape.vertexList[v].x)); vMi0=vMin[0]; 
vMax[0]=Math.max(vMa0,parseInt(shape.vertexList[v].x)); vMa0=vMax[0];
vMin[1]=Math.min(vMi1,parseInt(shape.vertexList[v].y)); vMi1=vMin[1];
vMax[1]=Math.max(vMa1,parseInt(shape.vertexList[v].y)); vMa1=vMax[1];
vMin[2]=Math.min(vMi2,parseInt(shape.vertexList[v].z)); vMi2=vMin[2];	
vMax[2]=Math.max(vMa2,parseInt(shape.vertexList[v].z)); vMa2=vMax[2]; }}
scale1=focalLength/(focalLength-vMa2); vMa0s=vMa0*scale1; vMa1s=vMa1*scale1;
scale2=focalLength/(focalLength-vMi2); vMi0s=vMi0*scale2; vMi1s=vMi1*scale2;
E={}; E.width=(vMa0s-vMi0s)/2; E.height=(vMa1s-vMi1s)/2; E.depth=(vMa2-vMi2)/2;
E.x=vMi0s+E.width; E.y=vMi1s+E.height; E.z=vMi2+E.depth;
global_AABB.push([E.x,E.y,E.z,E.width,E.height,E.depth]);};
//CreateAABBFromVertices_local(shape.side);
/*
focalLength=700; function CreateAABBFromVertices_local(Vertices){ var vMin=vMax=[];
vMax[0]=vMa0=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].x);
vMax[1]=vMa1=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].y);
vMax[2]=vMa2=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].z);
vMin[0]=vMi0=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].x);
vMin[1]=vMi1=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].y);
vMin[2]=vMi2=parseInt(shape.vertexList[Vertices[0].vertices[0]-rn].z);
for(var e=0;e<Vertices.length;e++) { for(var j=0; j<Vertices[e].vertices.length; j++) { var v=Vertices[e].vertices[j]-rn;
vMax[0]=vMa0; vMax[1]=vMa1; vMax[2]=vMa2; vMin[0]=vMi0; vMin[1]=vMi1; vMin[2]=vMi2; 
vMin[0]=Math.min(vMi0,parseInt(shape.vertexList[v].x)); vMi0=vMin[0]; 
vMax[0]=Math.max(vMa0,parseInt(shape.vertexList[v].x)); vMa0=vMax[0];
vMin[1]=Math.min(vMi1,parseInt(shape.vertexList[v].y)); vMi1=vMin[1];
vMax[1]=Math.max(vMa1,parseInt(shape.vertexList[v].y)); vMa1=vMax[1];
vMin[2]=Math.min(vMi2,parseInt(shape.vertexList[v].z)); vMi2=vMin[2];	
vMax[2]=Math.max(vMa2,parseInt(shape.vertexList[v].z)); vMa2=vMax[2]; }}
scale1=focalLength/(focalLength-vMa2); vMa0s=vMa0*scale1; vMa1s=vMa1*scale1;
scale2=focalLength/(focalLength-vMi2); vMi0s=vMi0*scale2; vMi1s=vMi1*scale2;
E={}; E.width=(vMa0s-vMi0s)/2; E.height=(vMa1s-vMi1s)/2; E.depth=(vMa2-vMi2)/2;
E.x=vMi0s+E.width; E.y=vMi1s+E.height; E.z=vMi2+E.depth;
global_AABB.push([E.x,E.y,E.z,E.width,E.height,E.depth,our_lod]);};
//if(our_lod!="" && our_lod!="undefined"){if(our_lod.indexOf("low")==-1){CreateAABBFromVertices_local(shape.side)}}
//CreateAABBFromVertices_local(shape.side);
*/

calculate_process=false;

if(m_real_sides_array.length!=0 && m_real_verts_array.length!=0){
Fshape.FvertexList=Fshape.FvertexList.concat(shape.vertexList);Fshape.Fside=Fshape.Fside.concat(shape.side);};//render_permission=true;

} //end of rendershape

// *******************************************************************************************
//X3D nodes parsing
render_permission=false; m_real_sides_array=m_real_verts_array=[];
parse_nodes=function(sn){
	
render_permission=false; m_real_sides_array=m_real_verts_array=[];
mydoc=xmlDoc.getElementsByTagName("X3D"); scene=xmlDoc.getElementsByTagName("Scene");
function RemoveWhitespace(xml){var loopIndex;
for (loopIndex = 0; loopIndex < xml.childNodes.length; loopIndex++){ var currentNode = xml.childNodes[loopIndex];
if (currentNode.nodeType == 1){RemoveWhitespace(currentNode);} if (((/^\s+$/.test(currentNode.nodeValue))) && (currentNode.nodeType == 3)){
xml.removeChild(xml.childNodes[loopIndex--]);}}}; RemoveWhitespace(scene[0]);

Fshape={FvertexList:[],Fside:[]};
shapes_stack=[];
wait=false;
anchors=false;denom="";
real_norm_verts_array=[];
obj = {}; bitmaps=[]; obj.textures=[]; texture_url=""; textures=false; delta_cam_x=0; delta_cam_y=0; delta_cam_z=0;
old_camera_x=old_camera_y=old_camera_z=0; delta_camera_yaw=0; delta_pitch=delta_yaw=0;
camera_dist=700; camera_x=0*70; camera_y=0*70; camera_z=10*70-camera_dist; camera_pitch=0; camera_yaw=0; camera_roll=0;
globalz=10*70-camera_dist;
new_camera_x=camera_x; new_camera_y=camera_y; new_camera_z=camera_z;
new_camera_pitch=camera_pitch; new_camera_yaw=camera_yaw; new_camera_roll=camera_roll; new_camera_description="";

camera=true;

collision=false;
global_AABB=[];
act_up=act_down=act_left=act_right=act_mouse=false;
global_collision=false;
rat=false;
walk_mode=false; nav_speed=15; viewpoints=[];
how_many_objects=0;
tvt=-1;
s_transformArray=s_transformArray2=[]; s_scaleArray=[]; s_rotationArray=s_rotationArray2=[];

for(t0=0; t0<scene[0].childNodes.length; t0++){

snode_tag=scene[0].childNodes.item(t0).tagName;

if(String(snode_tag)=="undefined"){}else{

if(snode_tag=="Transform"){

s_transform=scene[0].childNodes.item(t0).getAttribute("translation");
if(String(s_transform)=="null" || String(s_transform)==""){s_transform="0 0 0";}
s_transformArray=s_transform.split(" ");
s_scale=scene[0].childNodes.item(t0).getAttribute("scale");
if(String(s_scale)=="null" || String(s_scale)==""){s_scale="1 1 1";}
s_scaleArray=s_scale.split(" ");
s_rotation=scene[0].childNodes.item(t0).getAttribute("rotation");
if(String(s_rotation)=="null" || String(s_rotation)==""){s_rotation="0 0 0 0";}
s_rotationArray=s_rotation.split(" ");
node_tag=scene[0].childNodes.item(t0).childNodes[0].tagName;

tra1=Number(s_transformArray[0]);
tra2=Number(s_transformArray[1]);
tra3=Number(s_transformArray[2]);

sca1=Number(s_scaleArray[0]);
sca2=Number(s_scaleArray[1]);
sca3=Number(s_scaleArray[2]);

/*
rot1=Number(s_rotationArray[0]);	
rot2=Number(s_rotationArray[1]);	
rot3=Number(s_rotationArray[2]);	
rot4=Number(s_rotationArray[3]);	
*/

for(t2=0; t2<scene[0].childNodes.item(t0).childNodes.length; t2++){

if(scene[0].childNodes.item(t0).childNodes[t2].tagName=="Anchor"){

anchors=true;
url=scene[0].childNodes.item(t0).childNodes[t2].getAttribute("url");
if(String(url)=="null" || String(url)==""){url="";}
parameter=scene[0].childNodes.item(t0).childNodes[t2].getAttribute("parameter");
if(String(parameter)=="null" || String(parameter)==""){parameter="'target=_blank'";}
node_tag=scene[0].childNodes.item(t0).childNodes[t2].childNodes[0].tagName;
description=scene[0].childNodes.item(t0).childNodes[t2].getAttribute("description"); 
if(String(description)=="null" || String(description)==""){description="";}	

for(t3=0; t3<scene[0].childNodes.item(t0).childNodes[t2].childNodes.length; t3++){
inner_parsing(scene[0].childNodes.item(t0).childNodes[t2].childNodes[t3]);	
}

}else if(scene[0].childNodes.item(t0).childNodes[t2].tagName=="Transform"){

s_transform2=scene[0].childNodes.item(t0).childNodes[t2].getAttribute("translation");
if(String(s_transform2)=="null" || String(s_transform2)==""){s_transform2="0 0 0";}
s_transformArray2=s_transform2.split(" ");
s_transformArray=[tra1+Number(s_transformArray2[0]),tra2+Number(s_transformArray2[1]),tra3+Number(s_transformArray2[2])];
s_scale2=scene[0].childNodes.item(t0).childNodes[t2].getAttribute("scale");
if(String(s_scale2)=="null" || String(s_scale2)==""){s_scale2="1 1 1";}
s_scaleArray2=s_scale2.split(" ");

s_scaleArray=[sca1*Number(s_scaleArray2[0]),sca2*Number(s_scaleArray2[1]),sca3*Number(s_scaleArray2[2])];

s_rotation2=scene[0].childNodes.item(t0).childNodes[t2].getAttribute("rotation");
if(String(s_rotation2)=="null" || String(s_rotation2)==""){s_rotation2="0 0 0 0";}
s_rotationArray2=s_rotation2.split(" ");
/*
if(Number(s_rotationArray2[0])==0 || rot1==0){s_rotationArray[0]=rot1+Number(s_rotationArray2[0]);}
if(Number(s_rotationArray2[1])==0 || rot2==0){s_rotationArray[1]=rot2+Number(s_rotationArray2[1]);}
if(Number(s_rotationArray2[2])==0 || rot3==0){s_rotationArray[2]=rot3+Number(s_rotationArray2[2]);}
s_rotationArray[3]=rot4+Number(s_rotationArray2[3]);
*/
for(t3=0; t3<scene[0].childNodes.item(t0).childNodes[t2].childNodes.length; t3++){
url="";description="";parameter="";
inner_parsing(scene[0].childNodes.item(t0).childNodes[t2].childNodes[t3]);
}

}

else{
url="";description="";parameter="";
inner_parsing(scene[0].childNodes.item(t0).childNodes[t2]);
}

}
	
}else if(snode_tag=="Anchor"){

anchors=true;
url=scene[0].childNodes.item(t0).getAttribute("url");
if(String(url)=="null" || String(url)==""){url="";}
parameter=scene[0].childNodes.item(t0).getAttribute("parameter");
if(String(parameter)=="null" || String(parameter)==""){parameter="'target=_blank'";}
node_tag=scene[0].childNodes.item(t0).childNodes[0].tagName;
description=scene[0].childNodes.item(t0).getAttribute("description"); 
if(String(description)=="null" || String(description)==""){description="";}

s_transformArray=s_transformArray2=[]; s_scaleArray=[]; s_rotationArray=s_rotationArray2=[];
inner_parsing(scene[0].childNodes[t0]);

	
}else{
url="";description="";parameter="";	
s_transformArray=s_transformArray2=[]; s_scaleArray=[]; s_rotationArray=s_rotationArray2=[];
//inner_parsing(scene[0].childNodes);	//scene[0].childNodes[t]

//for(ik=0; ik<scene[0].childNodes.length; ik++){
	inner_parsing(scene[0].childNodes[t0]);
	//}
}
}} //end of for

function inner_parsing(node){
node_tag=node.tagName; navy=viewp=false;

// *******************************************************************************************
//we found Anchor node
if(node_tag=="Anchor"){
anchors=true;
url=scene[0].childNodes.item(t0).getAttribute("url");
if(String(url)=="null" || String(url)==""){url="";}
parameter=scene[0].childNodes.item(t0).getAttribute("parameter");
if(String(parameter)=="null" || String(parameter)==""){parameter="'target=_blank'";}
node_tag=scene[0].childNodes.item(t0).childNodes[0].tagName;
description=scene[0].childNodes.item(t0).getAttribute("description");
if(String(description)=="null" || String(description)==""){description="";}
}//else{url="";description="";parameter="";}

// *******************************************************************************************
//we found Transform node
if(node_tag=="Transform"){
s_transform=scene[0].childNodes.item(t0).getAttribute("translation");
if(String(s_transform)=="null" || String(s_transform)==""){s_transform="0 0 0";}
s_transformArray=s_transform.split(" ");
s_scale=scene[0].childNodes.item(t0).getAttribute("scale");
if(String(s_scale)=="null" || String(s_scale)==""){s_scale="1 1 1";}
s_scaleArray=s_scale.split(" ");
s_rotation=scene[0].childNodes.item(t0).getAttribute("rotation");
if(String(s_rotation)=="null" || String(s_rotation)==""){s_rotation="0 0 0";}
s_rotationArray=s_rotation.split(" ");
node_tag=scene[0].childNodes.item(t0).childNodes[0].tagName;
}//else{s_transformArray=[]; s_scaleArray=[]; s_rotationArray=[];}

// *******************************************************************************************
//we found NavigationInfo node
if(node_tag=="NavigationInfo"){
nav_type=scene[0].childNodes.item(t0).getAttribute("type");	
if(String(nav_type)=="null" || String(nav_type)==""){nav_type="EXAMINE";}
if(nav_type=="EXAMINE"){walk_mode=false;}else if(nav_type=="WALK"){walk_mode=true;}
nav_s=scene[0].childNodes.item(t0).getAttribute("speed");
if(String(nav_s)=="null" || String(nav_s)==""){nav_speed=1*15;}else{nav_speed=Number(nav_s)*15;}
navy=true;}

// *******************************************************************************************
//we found Viewpoint node
if(node_tag=="Viewpoint"){
viewp_position=scene[0].childNodes.item(t0).getAttribute("position");
if(String(viewp_position)=="null" || String(viewp_position)==""){viewp_position="0 0 10";}	
viep_ar=viewp_position.split(" ");
new_camera_x=Number(viep_ar[0])*70;
new_camera_y=Number(viep_ar[1])*70;//-camera_dist;
new_camera_z=Number(viep_ar[2])*70-camera_dist;//camera_z-=700;
viewp_orientation=scene[0].childNodes.item(t0).getAttribute("orientation");
if(String(viewp_orientation)=="null" || String(viewp_orientation)==""){viewp_orientation="0 0 1 0";}
vieo_ar=viewp_orientation.split(" ");
if(Number(vieo_ar[0])==1){new_camera_pitch=Number(vieo_ar[3])*180/Math.PI;}else{new_camera_pitch=0;}
if(Number(vieo_ar[1])==1){new_camera_yaw=Number(vieo_ar[3])*180/Math.PI;}else{new_camera_yaw=0;}
if(Number(vieo_ar[2])==1){new_camera_roll=Number(vieo_ar[3])*180/Math.PI;}else{new_camera_roll=0;}
new_camera_description=scene[0].childNodes.item(t0).getAttribute("description");
if(String(new_camera_description)=="null" || String(new_camera_description)==""){new_camera_description="";}
viewpoints.push([new_camera_x,new_camera_y,new_camera_z,new_camera_pitch,new_camera_yaw,new_camera_roll,String(new_camera_description)]);
viewp=true;}

if(!navy){if(!viewp){
// *******************************************************************************************
//we found Shape node
if(node_tag=="Shape"){
shape=node; how_many_objects++;

if(String(shape.getElementsByTagName("Appearance")[0])!="undefined"){
appearance_length=node.childNodes.length;}}

for(i=0;i<=appearance_length;i++){

// *******************************************************************************************
//we found Material node
if(String(shape.getElementsByTagName("Material")[0])!="undefined"){
var dcolor=shape.getElementsByTagName("Material")[0].getAttribute("diffuseColor");
if(String(dcolor)=="null" || String(dcolor)==""){dcolor="0.8 0.8 0.8";}
var dcolorArray=dcolor.split(" ");
rc=Number(dcolorArray[0]); gc=Number(dcolorArray[1]); bc=Number(dcolorArray[2]);
var alpha=shape.getElementsByTagName("Material")[0].getAttribute("transparency");
if(String(alpha)=="null" || String(alpha)==""){alpha=0;} alpha=1-alpha;
var shininess=shape.getElementsByTagName("Material")[0].getAttribute("shininess");
if(String(shininess)=="null" || String(shininess)==""){shininess="0.2";}
var ambientintensity=shape.getElementsByTagName("Material")[0].getAttribute("ambientIntensity");
if(String(ambientintensity)=="null" || String(ambientintensity)==""){ambientintensity="0.2";}
var specularcolor=shape.getElementsByTagName("Material")[0].getAttribute("specularColor");
if(String(specularcolor)=="null" || String(specularcolor)==""){specularcolor="0 0 0";}
var specularcolorArray=specularcolor.split(" ");
rsc=Number(specularcolorArray[0]); gsc=Number(specularcolorArray[1]); bsc=Number(specularcolorArray[2]);
var emissivecolor=shape.getElementsByTagName("Material")[0].getAttribute("emissiveColor");
if(String(emissivecolor)=="null" || String(emissivecolor)==""){emissivecolor="0 0 0";}
var emissivecolorArray=emissivecolor.split(" ");
rec=Number(emissivecolorArray[0]); gec=Number(emissivecolorArray[1]); bec=Number(emissivecolorArray[2]);};

// *******************************************************************************************
//we found ImageTexture node
if(String(shape.getElementsByTagName("ImageTexture")[0])!="undefined"){
if(tvt!=t0){tex_url=shape.getElementsByTagName("ImageTexture")[0].getAttribute("url");
if(String(tex_url)=="null" || String(tex_url)==""){tex_url="";texture_url="";};texture_url=tex_url;
if(texture_url!=""){bitmaps.push(texture_url);textures=true;}tvt=t0;}}else{texture_url="";}}

// *******************************************************************************************
//we found Box node
if(String(shape.getElementsByTagName("Box")[0])!="undefined"){
var size=shape.getElementsByTagName("Box")[0].getAttribute("size");
var solid=shape.getElementsByTagName("Box")[0].getAttribute("solid");
if(String(solid)=="null" || String(solid)==""){solid="true";}
if(String(size)=="null" || String(size)==""){size="2 2 2";}
var sizeArray=size.split(" ");
var lod=shape.getElementsByTagName("Box")[0].getAttribute("motiontextures");
if(String(lod)=="null" || String(lod)==""){lod="true";};
params={p1:sizeArray[0],p2:sizeArray[1],p3:sizeArray[2],p4:rc,p5:gc,p6:bc,p7:alpha,p8:shininess,p9:ambientintensity,p10:rsc,p11:gsc,p12:bsc,p13:rec,p14:gec,p15:bec,p16:texture_url,p17:lod};
rendershape("Box",params,solid,t0,sn);}

// *******************************************************************************************
//we found Sphere node
else if(String(shape.getElementsByTagName("Sphere")[0])!="undefined"){
var radius=shape.getElementsByTagName("Sphere")[0].getAttribute("radius");
var solid=shape.getElementsByTagName("Sphere")[0].getAttribute("solid");
if(String(solid)=="null" || String(solid)==""){solid="true";}
if(String(radius)=="null" || String(radius)==""){radius=1;}
var meshAngles=shape.getElementsByTagName("Sphere")[0].getAttribute("meshAngles");
if(String(meshAngles)=="null" || String(meshAngles)==""){meshAngles=20;}
var meshSides=shape.getElementsByTagName("Sphere")[0].getAttribute("meshSides");
if(String(meshSides)=="null" || String(meshSides)==""){meshSides=10;}
var lod=shape.getElementsByTagName("Sphere")[0].getAttribute("motiontextures");
if(String(lod)=="null" || String(lod)==""){lod="true";};
params={p1:radius,p2:rc,p3:gc,p4:bc,p5:alpha,p6:meshAngles,p7:meshSides,p8:shininess,p9:ambientintensity,p10:rsc,p11:gsc,p12:bsc,p13:rec,p14:gec,p15:bec,p16:texture_url,p17:t0,p18:lod};
rendershape("Sphere",params,solid,t0,sn);}

// *******************************************************************************************
//we found Cone node
else if(String(shape.getElementsByTagName("Cone")[0])!="undefined"){
var bottomradius=shape.getElementsByTagName("Cone")[0].getAttribute("bottomRadius");
var height=shape.getElementsByTagName("Cone")[0].getAttribute("height");
var bottom=shape.getElementsByTagName("Cone")[0].getAttribute("bottom");
var side=shape.getElementsByTagName("Cone")[0].getAttribute("side");
var solid=shape.getElementsByTagName("Cone")[0].getAttribute("solid");
if(String(bottom)=="null" || String(bottom)==""){bottom="true";}
if(String(side)=="null" || String(side)==""){side="true";}
if(String(solid)=="null" || String(solid)==""){solid="true";}
if(String(bottomradius)=="null" || String(bottomradius)==""){bottomradius=1;}
if(String(height)=="null" || String(height)==""){height=2;}
var meshSides=shape.getElementsByTagName("Cone")[0].getAttribute("meshSides");
if(String(meshSides)=="null" || String(meshSides)==""){meshSides=20;}
var lod=shape.getElementsByTagName("Cone")[0].getAttribute("motiontextures");
if(String(lod)=="null" || String(lod)==""){lod="true";};
params={p1:bottomradius,p2:height,p3:bottom,p4:side,p5:rc,p6:gc,p7:bc,p8:alpha,p9:meshSides,p10:shininess,p11:ambientintensity,p12:rsc,p13:gsc,p14:bsc,p15:rec,p16:gec,p17:bec,p18:texture_url,p19:lod}; rendershape("Cone",params,solid,t0,sn);}

// *******************************************************************************************
//we found Cylinder node
else if(String(shape.getElementsByTagName("Cylinder")[0])!="undefined"){
var radius=shape.getElementsByTagName("Cylinder")[0].getAttribute("radius");
var height=shape.getElementsByTagName("Cylinder")[0].getAttribute("height");
var bottom=shape.getElementsByTagName("Cylinder")[0].getAttribute("bottom");
var side=shape.getElementsByTagName("Cylinder")[0].getAttribute("side");
var top=shape.getElementsByTagName("Cylinder")[0].getAttribute("top");
var solid=shape.getElementsByTagName("Cylinder")[0].getAttribute("solid");
if(String(bottom)=="null" || String(bottom)==""){bottom="true";}
if(String(side)=="null" || String(side)==""){side="true";}
if(String(top)=="null" || String(top)==""){top="true";}
if(String(solid)=="null" || String(solid)==""){solid="true";}
if(String(radius)=="null" || String(radius)==""){radius=1;}
if(String(height)=="null" || String(height)==""){height=2;}
var meshSides=shape.getElementsByTagName("Cylinder")[0].getAttribute("meshSides");
if(String(meshSides)=="null" || String(meshSides)==""){meshSides=20;}
var lod=shape.getElementsByTagName("Cylinder")[0].getAttribute("motiontextures");
if(String(lod)=="null" || String(lod)==""){lod="true";};
params={p1:radius,p2:height,p3:bottom,p4:side,p5:top,p6:rc,p7:gc,p8:bc,p9:alpha,p10:meshSides,p11:shininess,p12:ambientintensity,p13:rsc,p14:gsc,p15:bsc,p16:rec,p17:gec,p18:bec,p19:texture_url,p20:lod}; rendershape("Cylinder",params,solid,t0,sn);}

// *******************************************************************************************
//we found IndexedFaceSet node
else if(String(shape.getElementsByTagName("IndexedFaceSet")[0])!="undefined"){calculate_process=true;
var objnormals=shape.getElementsByTagName("IndexedFaceSet")[0].getAttribute("objnormals");
if(String(objnormals)=="null" || String(objnormals)==""){objnormals="off";}
var src=shape.getElementsByTagName("IndexedFaceSet")[0].getAttribute("src");
var mtl=shape.getElementsByTagName("IndexedFaceSet")[0].getAttribute("mtl");
function send_data(){
var solid=shape.getElementsByTagName("IndexedFaceSet")[0].getAttribute("solid");
if(String(solid)=="null" || String(solid)==""){solid="true";}
var ccw=shape.getElementsByTagName("IndexedFaceSet")[0].getAttribute("ccw");
if(String(ccw)=="null" || String(ccw)==""){ccw="true";}
var creaseangle=shape.getElementsByTagName("IndexedFaceSet")[0].getAttribute("creaseAngle");
if(String(creaseangle)=="null" || String(creaseangle)==""){creaseangle=0;}
var convex=shape.getElementsByTagName("IndexedFaceSet")[0].getAttribute("convex");
if(String(convex)=="null" || String(convex)==""){convex="true";};

var lod=shape.getElementsByTagName("IndexedFaceSet")[0].getAttribute("motiontextures");
if(String(lod)=="null" || String(lod)==""){lod="true";};
/*
real_array_t=[];
for(i=0; i<real_array_tt.length/4; i++){
	real_array_t.push([real_array_tt[i*4],real_array_tt[i*4+1],real_array_tt[i*4+2]]);	
	}
*/
params={p1:real_sides_array,p2:real_verts_array,p3:ccw,p4:creaseangle,p5:real_color_array,p6:rc,p7:gc,p8:bc,p9:alpha,p10:shininess,p11:ambientintensity,p12:rsc,p13:gsc,p14:bsc,p15:rec,p16:gec,p17:bec,p18:real_transparency_array,p19:texture_url,p20:convex,p21:real_verts_tex_array,p22:real_array_t,p23:lod};
rendershape("IndexedFaceSet",params,solid,t0,sn);}
real_verts_array=[]; real_sides_array=[]; real_norm_verts_array=[]; real_transparency_array=[]; real_verts_tex_array=[]; real_array_t=[]; real_array_tt=[];
if(String(src)!="null"){
wait=true;		
if(m_real_sides_array.length!=0 && m_real_verts_array.length!=0){
real_sides_array=m_real_sides_array; real_verts_array=m_real_verts_array; 	
send_data();}else{
txtFile = new XMLHttpRequest();
txtFile.open("GET",src,true);
txtFile.onreadystatechange = function() {
if (txtFile.readyState === 4){
allText = txtFile.responseText;
lines = txtFile.responseText.split("\n");
for(i=0; i<lines.length; i++){str=lines[i];str_array=[];str_array_norm=[]; 
if(str.substr(0,6)=="usemtl"){real_sides_array.push(str.substr(7,str.length));}	
if(str.substr(0,3)=="vn "){
if(String(objnormals)=="off"){}else{	
strnorm=str.substr(3,str.length);str_array_norm=strnorm.split(" ");
real_norm_verts_array.push(str_array_norm);}
}else if(str.substr(0,3)=="vt "){str2=str.substr(2,str.length);
str_array=str2.split(" ");
real_verts_tex_array.push([str_array[1],str_array[2]]);
}else 
if(str.substr(0,2)=="v "){str2=str.substr(2,str.length);
str_array=str2.split(" ");
real_verts_array.push(str_array);}else 
if(str.substr(0,2)=="f "){str2=str.substr(2,str.length);
str_array=str2.split(" ");
str_array2=[];teax=[];
for(k=0; k<str_array.length; k++){
str3=str_array[k];
pos=str3.indexOf("/");
if(pos!=-1){real_n=str3.substr(0,pos); 
if(str3.lastIndexOf("/")!=-1){real_t=Number(str3.substring(pos+1,str3.lastIndexOf("/"))); teax.push(real_t);}}
else{real_n=str3;}
str_array2.push(Number(real_n)-1);}
real_sides_array.push(str_array2); real_array_t.push(teax); rat=true;}}
m_real_sides_array=real_sides_array; m_real_verts_array=real_verts_array;
if(String(shape.getElementsByTagName("Color")[0])!="undefined"){
var color=shape.getElementsByTagName("Color")[0].getAttribute("color");
color_array=color.split(",");
colors_array=[]; real_color_array=[];
for(j=0; j<color_array.length; j++){colors_array[j]=color_array[j].split(" ");}
for(j=0; j<colors_array.length; j++){temp_array=[];	
for(i=0; i<colors_array[j].length; i++){if(colors_array[j][i]!=""){temp_array.push(colors_array[j][i]);}}
real_color_array[j]=temp_array;}}
else if(String(shape.getElementsByTagName("ColorRGBA")[0])!="undefined"){
var color=shape.getElementsByTagName("ColorRGBA")[0].getAttribute("color");
color_array=color.split(",");
colors_array=[]; real_color_array=[];
for(j=0; j<color_array.length; j++){colors_array[j]=color_array[j].split(" ");}
for(j=0; j<colors_array.length; j++){temp_array=[];	
for(i=0; i<colors_array[j].length; i++){if(colors_array[j][i]!=""){temp_array.push(colors_array[j][i]);}}
real_color_array[j]=temp_array;}}else{real_color_array=[];real_color_array.length=1;}
if(String(mtl)!="null"){
real_verts_array_mtl=[];	
var Url = mtl;
function ProcessRequest(){if (xmlHttp.readyState == 4) {
allText_mtl=xmlHttp.responseText;lines_mtl = xmlHttp.responseText.split("\n");d_trans=false;
for(i=0; i<lines_mtl.length; i++){str_mtl=lines_mtl[i];str_array_mtl=[];
if(str_mtl.substr(0,6)=="newmtl"){str_array_mtl.push(str_mtl.substr(7,str_mtl.length));}else
if(str_mtl.substr(0,2)=="Ka"){ka=str_mtl.substr(3,str_mtl.length);str_array_mtl=ka.split(" ");	
}else if(str_mtl.substr(0,2)=="Kd"){kd=str_mtl.substr(3,str_mtl.length);str_array_mtl=kd.split(" ");}
else if(str_mtl.substr(0,1)=="d"){d_trans=true;if(str_mtl.indexOf("-")!=-1){}else{d_t=str_mtl.substr(2,str_mtl.length);str_array_mtl.push(d_t);}}
if(str_array_mtl.length!=0){real_verts_array_mtl.push(str_array_mtl);}}
m_real_sides_array_final=[];real_color_array=[];that_color=[];that_color_s=[];that_transparency=[];real_transparency_array=[];
for(i=0; i<real_sides_array.length; i++){for(j=0; j<real_verts_array_mtl.length; j++){
if(real_sides_array[i]==real_verts_array_mtl[j]){that_color.push(real_verts_array_mtl[j+2]);
if(d_trans){that_transparency.push(real_verts_array_mtl[j+3]);}
that_color_s.push(i);}}}
for(k=0; k<that_color_s.length; k++){if(String(that_color_s[k+1])=="undefined"){}else{
for(l=that_color_s[k]; l<that_color_s[k+1]-1; l++){real_color_array.push(that_color[k]);
if(d_trans){real_transparency_array.push(that_transparency[k]);}}
for(u=that_color_s[k]; u<that_color_s[k+1]-1; u++){m_real_sides_array_final.push(m_real_sides_array[u+1]);}}}
real_sides_array=m_real_sides_array_final;send_data();}}
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();xmlHttp.onreadystatechange = ProcessRequest;xmlHttp.open("GET", Url, true );xmlHttp.send(null);}
if(String(mtl)!="null"){}else{send_data();}}}
txtFile.send(null);}}else{	
var coordIndex=shape.getElementsByTagName("IndexedFaceSet")[0].getAttribute("coordIndex");
coord_array=coordIndex.split(-1);
sides_array=[]; real_sides_array=[];quteg=false;
for(j=0; j<coord_array.length; j++){spp=coord_array[j].split(" ");qute=false; 
for(q=0;q<spp.length;q++){if(spp[q].indexOf("/")!=-1){
//for(k=0; k<str_array.length; k++){
//str3=spp[q];teax=[];
//mystr3=str3.substring(str3.indexOf("/")+1,str3.length);
//teax.push(Number(mystr3.substring(0,mystr3.indexOf("/"))));
//teax.push(Number(mystr3.substring(mystr3.indexOf("/")+1,mystr3.length)));
//real_t=Number(spp[q].substring(spp[q].indexOf("/")+1,spp[q].lastIndexOf("/"))); alert(real_t);teax.push(real_t);	
//rat=true;	real_array_tt.push(teax);
quteg=true;qute=true;}}
if(qute){resq=[];for(q=0;q<spp.length;q++){resq.push(spp[q].substr(0,spp[q].indexOf("/")))};sides_array[j]=resq;}else{sides_array[j]=coord_array[j].split(" ");}}
for(j=0; j<sides_array.length-1; j++){temp_array=[];
for(i=0; i<sides_array[j].length; i++){if(sides_array[j][i]!=""){if(quteg){temp_array.push(sides_array[j][i]-1);}else{temp_array.push(sides_array[j][i]);}}}
real_sides_array[j]=temp_array;}
var points=shape.getElementsByTagName("Coordinate")[0].getAttribute("point");
points_array=points.split(",");
if(points_array.length>1){
verts_array=[]; real_verts_array=[];
for(j=0; j<points_array.length; j++){verts_array[j]=points_array[j].split(" ");}
for(j=0; j<verts_array.length; j++){temp_array=[];	
for(i=0; i<verts_array[j].length; i++){if(verts_array[j][i]!=""){temp_array.push(verts_array[j][i]);}}
real_verts_array[j]=temp_array;}
}else{ verts_array=points.split(" ");
for(u=0; u<verts_array.length/3; u++){ real_verts_array[u]=[verts_array[3*u],verts_array[3*u+1],verts_array[3*u+2]]; }}
if(String(shape.getElementsByTagName("Textures")[0])!="undefined"){
var texturecoords=shape.getElementsByTagName("Textures")[0].getAttribute("coords");
texturecoords2=texturecoords.split(",");
texturecoords3=[];
for(i=0; i<texturecoords2.length; i++){
texturecoords3.push(texturecoords2[i].split(" "));}
texturecoords4=[];
for(i=0; i<texturecoords3.length; i++){temptex=[];
for(j=0; j<texturecoords3[i].length; j++){if(texturecoords3[i][j]!=""){temptex.push(texturecoords3[i][j]);}}
texturecoords4.push(temptex);}real_verts_tex_array=texturecoords4;}
if(String(shape.getElementsByTagName("Color")[0])!="undefined"){
var color=shape.getElementsByTagName("Color")[0].getAttribute("color");
color_array=color.split(",");
colors_array=[]; real_color_array=[];
for(j=0; j<color_array.length; j++){colors_array[j]=color_array[j].split(" ");}
for(j=0; j<colors_array.length; j++){temp_array=[];	
for(i=0; i<colors_array[j].length; i++){if(colors_array[j][i]!=""){temp_array.push(colors_array[j][i]);}}
real_color_array[j]=temp_array;}}
else if(String(shape.getElementsByTagName("ColorRGBA")[0])!="undefined"){
var color=shape.getElementsByTagName("ColorRGBA")[0].getAttribute("color");
color_array=color.split(",");
colors_array=[]; real_color_array=[];
for(j=0; j<color_array.length; j++){colors_array[j]=color_array[j].split(" ");}
for(j=0; j<colors_array.length; j++){temp_array=[];	
for(i=0; i<colors_array[j].length; i++){if(colors_array[j][i]!=""){temp_array.push(colors_array[j][i]);}}
real_color_array[j]=temp_array;}}else{real_color_array=[];real_color_array.length=1;}send_data();}}

// *******************************************************************************************
//we found Text node
else if(String(shape.getElementsByTagName("Text")[0])!="undefined"){
var string=shape.getElementsByTagName("Text")[0].getAttribute("string");
var solid=shape.getElementsByTagName("Text")[0].getAttribute("solid");
if(String(solid)=="null" || String(solid)==""){solid="true";}
var size=shape.getElementsByTagName("FontStyle")[0].getAttribute("size");
if(String(size)=="null" || String(size)==""){size=1;}
var spacing=shape.getElementsByTagName("FontStyle")[0].getAttribute("spacing");
if(String(spacing)=="null" || String(spacing)==""){spacing=1;}
var style=shape.getElementsByTagName("FontStyle")[0].getAttribute("style");
if(String(style)=="null" || String(style)==""){style='"PLAIN"';}
params={p1:string.toUpperCase(),p2:size,p3:spacing,p4:style,p5:rc,p6:gc,p7:bc,p8:alpha,p9:shininess,p10:ambientintensity,p11:rsc,p12:gsc,p13:bsc,p14:rec,p15:gec,p16:bec}; rendershape("Text",params,solid,t0,sn);}

// *******************************************************************************************
//we found Extrusion node
else if(String(shape.getElementsByTagName("Extrusion")[0])!="undefined"){
var lod=shape.getElementsByTagName("Extrusion")[0].getAttribute("motiontextures");
if(String(lod)=="null" || String(lod)==""){lod="true";};	
var crosssection=shape.getElementsByTagName("Extrusion")[0].getAttribute("crossSection");
if(String(crosssection)=="null" || String(crosssection)==""){crosssection="1 1, 1 -1, -1 -1, -1 1, 1 1";}
cross_array=crosssection.split(",");
cross_verts=[]; real_cross_verts=[];
for(i=0; i<cross_array.length; i++){cross_verts[i]=cross_array[i].split(" ");}
for(j=0; j<cross_verts.length; j++){temp_array=[];
for(i=0; i<cross_verts[j].length; i++){if(cross_verts[j][i]!=""){temp_array.push(cross_verts[j][i]);}}
real_cross_verts[j]=temp_array;}
var begincap=shape.getElementsByTagName("Extrusion")[0].getAttribute("beginCap");
if(String(begincap)=="null" || String(begincap)==""){begincap="true";}
var spine=shape.getElementsByTagName("Extrusion")[0].getAttribute("spine");
if(String(spine)=="null" || String(spine)==""){spine="0 0 0, 0 1 0";}
spine_array=spine.split(",");
spine_verts=[]; real_spine_verts=[];
for(i=0; i<spine_array.length; i++){spine_verts[i]=spine_array[i].split(" ");}
for(j=0; j<spine_verts.length; j++){temp_array=[];
for(i=0; i<spine_verts[j].length; i++){if(spine_verts[j][i]!=""){temp_array.push(spine_verts[j][i]);}}
real_spine_verts[j]=temp_array;}
var endcap=shape.getElementsByTagName("Extrusion")[0].getAttribute("endCap");
if(String(endcap)=="null" || String(endcap)==""){endcap="true";}
var scale=shape.getElementsByTagName("Extrusion")[0].getAttribute("scale");
if(String(scale)=="null" || String(scale)==""){scale="1 1";}
scale_array=scale.split(",");
scale_verts=[]; real_scale_verts=[];
for(i=0; i<scale_array.length; i++){scale_verts[i]=scale_array[i].split(" ");}
for(j=0; j<scale_verts.length; j++){temp_array=[];
for(i=0; i<scale_verts[j].length; i++){if(scale_verts[j][i]!=""){temp_array.push(scale_verts[j][i]);}}
real_scale_verts[j]=temp_array;}
var creaseangle=shape.getElementsByTagName("Extrusion")[0].getAttribute("creaseAngle");
if(String(creaseangle)=="null" || String(creaseangle)==""){creaseangle=0;}
var solid=shape.getElementsByTagName("Extrusion")[0].getAttribute("solid");
if(String(solid)=="null" || String(solid)==""){solid="true";}
var orientation=shape.getElementsByTagName("Extrusion")[0].getAttribute("orientation");
if(String(orientation)=="null" || String(orientation)==""){orientation="0 0 1 0";}
orientation_array=orientation.split(",");
orientation_verts=[]; real_orientation_verts=[];
for(i=0; i<orientation_array.length; i++){orientation_verts[i]=orientation_array[i].split(" ");}
for(j=0; j<orientation_verts.length; j++){temp_array=[];
for(i=0; i<orientation_verts[j].length; i++){if(orientation_verts[j][i]!=""){temp_array.push(orientation_verts[j][i]);}}
real_orientation_verts[j]=temp_array;}
var ccw=shape.getElementsByTagName("Extrusion")[0].getAttribute("ccw");
if(String(ccw)=="null" || String(ccw)==""){ccw="true";}
var convex=shape.getElementsByTagName("Extrusion")[0].getAttribute("convex");
if(String(convex)=="null" || String(convex)==""){convex="true";}
params={p1:real_cross_verts,p2:begincap,p3:real_spine_verts,p4:endcap,p5:real_scale_verts,p6:creaseangle,p7:real_orientation_verts,p8:ccw,p9:rc,p10:gc,p11:bc,p12:alpha,p13:shininess,p14:ambientintensity,p15:rsc,p16:gsc,p17:bsc,p18:rec,p19:gec,p20:bec,p21:texture_url,p22:convex,p23:lod}; rendershape("Extrusion",params,solid,t0,sn);}

// *******************************************************************************************
//we found something else
if(!wait){
Fshape.FvertexList=Fshape.FvertexList.concat(shape.vertexList);
Fshape.Fside=Fshape.Fside.concat(shape.side);
//render_permission=true;
}
}}//end of if navy / viewp


}//end of for
}

// *******************************************************************************************
//transformations
cameraZ = function(roll){
rad = roll*Math.PI/180;sin = Math.sin(rad);cos = Math.cos(rad);
matrix = {a:cos,b:-sin,c:0,d:sin,e:cos,f:0,g:0,h:0,i:1};
for(c=0; c<Fshape.FvertexList.length; c++){
newx=matrix.a*Fshape.FvertexList[c].x+matrix.b*Fshape.FvertexList[c].y+matrix.c*Fshape.FvertexList[c].z;
newy=matrix.d*Fshape.FvertexList[c].x+matrix.e*Fshape.FvertexList[c].y+matrix.f*Fshape.FvertexList[c].z;
newz=matrix.g*Fshape.FvertexList[c].x+matrix.h*Fshape.FvertexList[c].y+matrix.i*Fshape.FvertexList[c].z;
Fshape.FvertexList[c].x=newx; Fshape.FvertexList[c].y=newy; Fshape.FvertexList[c].z=newz;}}
cameraY = function(yaw){
rad = yaw*Math.PI/180;sin = Math.sin(rad);cos = Math.cos(rad);
matrix = {a:cos,b:0,c:sin,d:0,e:1,f:0,g:-sin,h:0,i:cos};	
for(c=0; c<Fshape.FvertexList.length; c++){
newx=matrix.a*Fshape.FvertexList[c].x+matrix.b*Fshape.FvertexList[c].y+matrix.c*Fshape.FvertexList[c].z;
newy=matrix.d*Fshape.FvertexList[c].x+matrix.e*Fshape.FvertexList[c].y+matrix.f*Fshape.FvertexList[c].z;
newz=matrix.g*Fshape.FvertexList[c].x+matrix.h*Fshape.FvertexList[c].y+matrix.i*Fshape.FvertexList[c].z;
Fshape.FvertexList[c].x=newx; Fshape.FvertexList[c].y=newy; Fshape.FvertexList[c].z=newz;}}
cameraX = function(pitch){
rad = pitch*Math.PI/180;sin = Math.sin(rad);cos = Math.cos(rad)
matrix = {a:1,b:0,c:0,d:0,e:cos,f:-sin,g:0,h:sin,i:cos};
for(c=0; c<Fshape.FvertexList.length; c++){
newx=matrix.a*Fshape.FvertexList[c].x+matrix.b*Fshape.FvertexList[c].y+matrix.c*Fshape.FvertexList[c].z;
newy=matrix.d*Fshape.FvertexList[c].x+matrix.e*Fshape.FvertexList[c].y+matrix.f*Fshape.FvertexList[c].z;
newz=matrix.g*Fshape.FvertexList[c].x+matrix.h*Fshape.FvertexList[c].y+matrix.i*Fshape.FvertexList[c].z;
Fshape.FvertexList[c].x=newx; Fshape.FvertexList[c].y=newy; Fshape.FvertexList[c].z=newz;}}
translate = function(xl,yl,zl){
for(c=0; c<Fshape.FvertexList.length; c++){Fshape.FvertexList[c].x+=xl;Fshape.FvertexList[c].y+=yl;Fshape.FvertexList[c].z+=zl;}	
for(g=0; g<global_AABB.length; g++){global_AABB[g][0]+=xl;global_AABB[g][1]+=yl;global_AABB[g][2]+=zl;}}
rotateX = function (degree) {
var rad = degree*Math.PI/180; var sin = Math.sin(rad); var cos = Math.cos(rad);
var matrix = {a:1,b:0,c:0,d:0,e:cos,f:sin,g:0,h:-sin,i:cos}; transform(matrix);}
rotateY = function (degree) {	
var rad = degree*Math.PI/180; var sin = Math.sin(rad); var cos = Math.cos(rad);
var matrix = {a:cos,b:0,c:-sin,d:0,e:1,f:0,g:sin,h:0,i:cos}; transform(matrix);}
rotateZ = function (degree) {
var rad = degree*Math.PI/180; var sin = Math.sin(rad); var cos = Math.cos(rad);
var matrix = {a:cos,b:sin,c:0,d:-sin,e:cos,f:0,g:0,h:0,i:1};transform(matrix);}
rotateXY = function (degree1,degree2) {	
var rad1 = degree1*Math.PI/180; var sin1 = Math.sin(rad1); var cos1 = Math.cos(rad1);
var matrix1 = {a:1,b:0,c:0,d:0,e:cos1,f:sin1,g:0,h:-sin1,i:cos1};
var rad2 = degree2*Math.PI/180; var sin2 = Math.sin(rad2); var cos2 = Math.cos(rad2);
var matrix2 = {a:cos2,b:0,c:-sin2,d:0,e:1,f:0,g:sin2,h:0,i:cos2};
var mc1 = matrix1.a*matrix1.b; var mc2 = matrix2.a*matrix2.d; var mc3 = matrix2.b*matrix2.e;	
var mc4 = matrix2.c*matrix2.f; var mc5 = matrix1.d*matrix1.e; var mc6 = matrix1.g*matrix1.h;
var ma = (matrix1.a+matrix2.d)*(matrix1.b+matrix2.a)+matrix1.c*matrix2.g-mc1-mc2;
var mb = (matrix1.a+matrix2.e)*(matrix1.b+matrix2.b)+matrix1.c*matrix2.h-mc1-mc3;
var mc = (matrix1.a+matrix2.f)*(matrix1.b+matrix2.c)+matrix1.c*matrix2.i-mc1-mc4
var md = (matrix1.d+matrix2.d)*(matrix1.e+matrix2.a)+matrix1.f*matrix2.g-mc5-mc2;
var me = (matrix1.d+matrix2.e)*(matrix1.e+matrix2.b)+matrix1.f*matrix2.h-mc5-mc3;	
var mf = (matrix1.d+matrix2.f)*(matrix1.e+matrix2.c)+matrix1.f*matrix2.i-mc5-mc4;
var mg = (matrix1.g+matrix2.d)*(matrix1.h+matrix2.a)+matrix1.i*matrix2.g-mc6-mc2;
var mh = (matrix1.g+matrix2.e)*(matrix1.h+matrix2.b)+matrix1.i*matrix2.h-mc6-mc3;
var mi = (matrix1.g+matrix2.f)*(matrix1.h+matrix2.c)+matrix1.i*matrix2.i-mc6-mc4;
matrix = {a:ma,b:mb,c:mc,d:md,e:me,f:mf,g:mg,h:mh,i:mi};transform(matrix);}	
	
transform = function (matrix) {
if (transformMatrix) {
var c1 = matrix.a*matrix.b;
var c2 = transformMatrix.a*transformMatrix.d;
var c3 = transformMatrix.b*transformMatrix.e;	
var c4 = transformMatrix.c*transformMatrix.f;
var c5 = matrix.d*matrix.e; var c6 = matrix.g*matrix.h;
var a = (matrix.a+transformMatrix.d)*(matrix.b+transformMatrix.a)+matrix.c*transformMatrix.g-c1-c2;
var b = (matrix.a+transformMatrix.e)*(matrix.b+transformMatrix.b)+matrix.c*transformMatrix.h-c1-c3;
var c = (matrix.a+transformMatrix.f)*(matrix.b+transformMatrix.c)+matrix.c*transformMatrix.i-c1-c4
var d = (matrix.d+transformMatrix.d)*(matrix.e+transformMatrix.a)+matrix.f*transformMatrix.g-c5-c2;
var e = (matrix.d+transformMatrix.e)*(matrix.e+transformMatrix.b)+matrix.f*transformMatrix.h-c5-c3;	
var f = (matrix.d+transformMatrix.f)*(matrix.e+transformMatrix.c)+matrix.f*transformMatrix.i-c5-c4;
var g = (matrix.g+transformMatrix.d)*(matrix.h+transformMatrix.a)+matrix.i*transformMatrix.g-c6-c2;
var h = (matrix.g+transformMatrix.e)*(matrix.h+transformMatrix.b)+matrix.i*transformMatrix.h-c6-c3;
var i = (matrix.g+transformMatrix.f)*(matrix.h+transformMatrix.c)+matrix.i*transformMatrix.i-c6-c4;
transformMatrix = {a:a,b:b,c:c,d:d,e:e,f:f,g:g,h:h,i:i};}else{transformMatrix=matrix;}}

// *******************************************************************************************
//light source
LightSource = function(x,y,z,brightness) {
this.x=x; this.y=y; this.z=-z; this.brightness=brightness;
this.calcMag = function() {this.magnitude=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);}
this.calcMag();}
focalLength=700; //400//depth imitation
light = new LightSource(0,0,-200,100);

// *******************************************************************************************
//render	
render = function (model,rendermode) { //if(model.FvertexList.length!=0){

// *******************************************************************************************
//verticies sorting (z-sort)
vsort = function(amodel){
middist=0; midPoint1=0; midPoint2=0; midPoint3=0; distArray=[];
for(i=0; i<amodel.length; i++){
midPoint1=((model.FvertexList[amodel[i][0].vertices[0]].x+model.FvertexList[amodel[i][0].vertices[1]].x+model.FvertexList[amodel[i][0].vertices[2]].x)/3).toFixed(2);
midPoint2=((model.FvertexList[amodel[i][0].vertices[0]].y+model.FvertexList[amodel[i][0].vertices[1]].y+model.FvertexList[amodel[i][0].vertices[2]].y)/3).toFixed(2);
midPoint3=((model.FvertexList[amodel[i][0].vertices[0]].z+model.FvertexList[amodel[i][0].vertices[1]].z+model.FvertexList[amodel[i][0].vertices[2]].z)/3).toFixed(2);
middist=Math.sqrt(midPoint1*midPoint1+midPoint2*midPoint2+(focalLength-midPoint3)*(focalLength-midPoint3));
distArray.push([middist,i]);}
dresult=distArray.sort(function(v,w) {if (v[0]>w[0]){
return -1; } else if (v[0]<w[0]){ return 1; } else { return 0; }});
ddresult=[]; for(i=0; i<dresult.length; i++){ ddresult[i]=dresult[i][1]; }}//end of vsort

// *******************************************************************************************
//backface calculation
backface=function(ourverts){	
x1=model.FvertexList[ourverts[0]].x; y1=model.FvertexList[ourverts[0]].y; z1=model.FvertexList[ourverts[0]].z;
x2=model.FvertexList[ourverts[1]].x; y2=model.FvertexList[ourverts[1]].y; z2=model.FvertexList[ourverts[1]].z;
x3=model.FvertexList[ourverts[2]].x; y3=model.FvertexList[ourverts[2]].y; z3=model.FvertexList[ourverts[2]].z;
v1=x3;v2=y3;v3=z3;
nx = ((y1-y2)*(z1-z3))-((z1-z2)*(y1-y3)); ny = ((z1-z2)*(x1-x3))-((x1-x2)*(z1-z3)); nz = ((x1-x2)*(y1-y3))-((y1-y2)*(x1-x3));
dist=-700; if(nz*dist+nx*v1+ny*v2+nz*v3>0){perm=true;}else{perm=false;}}

// *******************************************************************************************
//AABB (Axis-Aligned Bounding Box) calculation
AABB=[];
function CreateAABBFromVertices(Vertices,AABBurl,AABBdes){
vMin=vMax=[];
vMax[0]=vMa0=parseInt(model.FvertexList[Vertices[0].vertices[0]].x);
vMax[1]=vMa1=parseInt(model.FvertexList[Vertices[0].vertices[0]].y);
vMax[2]=vMa2=parseInt(model.FvertexList[Vertices[0].vertices[0]].z);
vMin[0]=vMi0=parseInt(model.FvertexList[Vertices[0].vertices[0]].x);
vMin[1]=vMi1=parseInt(model.FvertexList[Vertices[0].vertices[0]].y);
vMin[2]=vMi2=parseInt(model.FvertexList[Vertices[0].vertices[0]].z);
for(var i=0;i<Vertices.length;i++) { for(var j=0; j<Vertices[i].vertices.length; j++){ var v=Vertices[i].vertices[j];
vMax[0]=vMa0; vMax[1]=vMa1; vMax[2]=vMa2; vMin[0]=vMi0; vMin[1]=vMi1; vMin[2]=vMi2;
vMin[0]=Math.min(vMi0,parseInt(model.FvertexList[v].x)); vMi0=vMin[0];
vMax[0]=Math.max(vMa0,parseInt(model.FvertexList[v].x)); vMa0=vMax[0];
vMin[1]=Math.min(vMi1,parseInt(model.FvertexList[v].y)); vMi1=vMin[1];
vMax[1]=Math.max(vMa1,parseInt(model.FvertexList[v].y)); vMa1=vMax[1];
vMin[2]=Math.min(vMi2,parseInt(model.FvertexList[v].z)); vMi2=vMin[2];	
vMax[2]=Math.max(vMa2,parseInt(model.FvertexList[v].z)); vMa2=vMax[2]; }}
scale1=focalLength/(focalLength-vMa2); vMa0s=vMa0*scale1; vMa1s=vMa1*scale1;
scale2=focalLength/(focalLength-vMi2); vMi0s=vMi0*scale2; vMi1s=vMi1*scale2;
E={}; 
E.width=(vMa0s-vMi0s)/2; 
E.height=(vMa1s-vMi1s)/2;
//E.depth=(vMa2-vMi2)/2;
E.x=vMi0s+E.width;
E.y=vMi1s+E.height;
AABB.push(E); AABB.push(AABBurl); AABB.push(AABBdes);}

canvas=document.getElementById("canvas"); context=canvas.getContext("2d"); context.clearRect(0,0,newcanvas.width,newcanvas.height);
context.strokeStyle="rgba("+c1+","+c2+","+c3+",1)"; context.lineJoin="round";
des_perm=true; des_perm2=true;

if(camera){

if(old_camera_x>camera_x){delta_cam_x--;}else if(old_camera_x<camera_x){delta_cam_x++;}else{}
//if(old_camera_y>camera_y){delta_cam_y--;}else if(old_camera_y<camera_y){delta_cam_y++;}else{}
if(old_camera_z>camera_z){delta_cam_z--;}else if(old_camera_z<camera_z){delta_cam_z++;}else{}

//light = new LightSource(-nav_speed*delta_cam_x,-camera_y,700+nav_speed*delta_cam_z,100);

if(global_collision){
for(g=0; g<global_AABB.length; g++){
xgt=global_AABB[g][0]+camera_x; ygt=global_AABB[g][1]+camera_y; zgt=global_AABB[g][2]-camera_z-camera_dist;
global_AABB[g][0]=xgt; global_AABB[g][1]=ygt; global_AABB[g][2]=zgt;
rad = camera_yaw*Math.PI/180; sin = Math.sin(rad); cos = Math.cos(rad); matrix = {a:cos,b:0,c:sin,d:0,e:1,f:0,g:-sin,h:0,i:cos};
newx=matrix.a*global_AABB[g][0]+matrix.b*global_AABB[g][1]+matrix.c*global_AABB[g][2];
newy=matrix.d*global_AABB[g][0]+matrix.e*global_AABB[g][1]+matrix.f*global_AABB[g][2];
newz=matrix.g*global_AABB[g][0]+matrix.h*global_AABB[g][1]+matrix.i*global_AABB[g][2];
global_AABB[g][0]=newx; global_AABB[g][1]=newy; global_AABB[g][2]=newz;
rad = camera_pitch*Math.PI/180; sin = Math.sin(rad); cos = Math.cos(rad); matrix = {a:1,b:0,c:0,d:0,e:cos,f:-sin,g:0,h:sin,i:cos};
newx=matrix.a*global_AABB[g][0]+matrix.b*global_AABB[g][1]+matrix.c*global_AABB[g][2];
newy=matrix.d*global_AABB[g][0]+matrix.e*global_AABB[g][1]+matrix.f*global_AABB[g][2];
newz=matrix.g*global_AABB[g][0]+matrix.h*global_AABB[g][1]+matrix.i*global_AABB[g][2];
global_AABB[g][0]=newx; global_AABB[g][1]=newy; global_AABB[g][2]=newz;
rad = camera_roll*Math.PI/180; sin = Math.sin(rad); cos = Math.cos(rad); matrix = {a:cos,b:-sin,c:0,d:sin,e:cos,f:0,g:0,h:0,i:1};
newx=matrix.a*global_AABB[g][0]+matrix.b*global_AABB[g][1]+matrix.c*global_AABB[g][2];
newy=matrix.d*global_AABB[g][0]+matrix.e*global_AABB[g][1]+matrix.f*global_AABB[g][2];
newz=matrix.g*global_AABB[g][0]+matrix.h*global_AABB[g][1]+matrix.i*global_AABB[g][2];
global_AABB[g][0]=newx; global_AABB[g][1]=newy; global_AABB[g][2]=newz;
xgt=global_AABB[g][0]-camera_x; ygt=global_AABB[g][1]-camera_y; zgt=global_AABB[g][2]+camera_z+camera_dist;
global_AABB[g][0]=xgt; global_AABB[g][1]=ygt; global_AABB[g][2]=zgt;
xgt=global_AABB[g][0]+camera_x; ygt=global_AABB[g][1]+camera_y; zgt=global_AABB[g][2]-camera_z;//-camera_dist;
global_AABB[g][0]=xgt; global_AABB[g][1]=ygt; global_AABB[g][2]=zgt;}}

for(c=0; c<model.FvertexList.length; c++){
xcam=model.FvertexList[c].x+camera_x; ycam=model.FvertexList[c].y+camera_y; zcam=model.FvertexList[c].z-camera_z-camera_dist;
model.FvertexList[c].x=xcam; model.FvertexList[c].y=ycam; model.FvertexList[c].z=zcam;
rad = camera_yaw*Math.PI/180; sin = Math.sin(rad); cos = Math.cos(rad); matrix = {a:cos,b:0,c:sin,d:0,e:1,f:0,g:-sin,h:0,i:cos};
newx=matrix.a*model.FvertexList[c].x+matrix.b*model.FvertexList[c].y+matrix.c*model.FvertexList[c].z;
newy=matrix.d*model.FvertexList[c].x+matrix.e*model.FvertexList[c].y+matrix.f*model.FvertexList[c].z;
newz=matrix.g*model.FvertexList[c].x+matrix.h*model.FvertexList[c].y+matrix.i*model.FvertexList[c].z;
model.FvertexList[c].x=newx; model.FvertexList[c].y=newy; model.FvertexList[c].z=newz;
rad = camera_pitch*Math.PI/180; sin = Math.sin(rad); cos = Math.cos(rad); matrix = {a:1,b:0,c:0,d:0,e:cos,f:-sin,g:0,h:sin,i:cos};
newx=matrix.a*model.FvertexList[c].x+matrix.b*model.FvertexList[c].y+matrix.c*model.FvertexList[c].z;
newy=matrix.d*model.FvertexList[c].x+matrix.e*model.FvertexList[c].y+matrix.f*model.FvertexList[c].z;
newz=matrix.g*model.FvertexList[c].x+matrix.h*model.FvertexList[c].y+matrix.i*model.FvertexList[c].z;
model.FvertexList[c].x=newx; model.FvertexList[c].y=newy; model.FvertexList[c].z=newz;
rad = camera_roll*Math.PI/180; sin = Math.sin(rad); cos = Math.cos(rad)
matrix = {a:cos,b:-sin,c:0,d:sin,e:cos,f:0,g:0,h:0,i:1};
newx=matrix.a*model.FvertexList[c].x+matrix.b*model.FvertexList[c].y+matrix.c*model.FvertexList[c].z;
newy=matrix.d*model.FvertexList[c].x+matrix.e*model.FvertexList[c].y+matrix.f*model.FvertexList[c].z;
newz=matrix.g*model.FvertexList[c].x+matrix.h*model.FvertexList[c].y+matrix.i*model.FvertexList[c].z;
model.FvertexList[c].x=newx; model.FvertexList[c].y=newy; model.FvertexList[c].z=newz;
xcam=model.FvertexList[c].x-camera_x; ycam=model.FvertexList[c].y-camera_y; zcam=model.FvertexList[c].z+camera_z+camera_dist;
model.FvertexList[c].x=xcam; model.FvertexList[c].y=ycam; model.FvertexList[c].z=zcam;
xcam=model.FvertexList[c].x+camera_x; ycam=model.FvertexList[c].y+camera_y; zcam=model.FvertexList[c].z-camera_z;//-camera_dist;
model.FvertexList[c].x=xcam; model.FvertexList[c].y=ycam; model.FvertexList[c].z=zcam;
camera=false;}//end of for	

old_camera_x=camera_x;
old_camera_x=camera_y;

old_camera_z=camera_z;
old_camera_z=camera_y;

}

va=[];
if (transformMatrix) { stc=0;
for (var i=0; i<model.FvertexList.length; i++) {
var vert=model.FvertexList[i];
var const1 = transformMatrix.a*transformMatrix.b; 
var const2 = vert.x*vert.y; 
var const3 = transformMatrix.d*transformMatrix.e;
var const4 = transformMatrix.g*transformMatrix.h;
var x = (transformMatrix.a+vert.y)*(transformMatrix.b+vert.x)+transformMatrix.c*vert.z-const1-const2;
var y = (transformMatrix.d+vert.y)*(transformMatrix.e+vert.x)+transformMatrix.f*vert.z-const3-const2;
var z = (transformMatrix.g+vert.y)*(transformMatrix.h+vert.x)+transformMatrix.i*vert.z-const4-const2;
vert.x=x; vert.y=y; vert.z=z; va.push(vert); } delete transformMatrix;}

if (transformMatrix) {
for(g=0; g<global_AABB.length; g++){
var const1 = transformMatrix.a*transformMatrix.b;
var const2 = global_AABB[g][0]*global_AABB[g][1];
var const3 = transformMatrix.d*transformMatrix.e;
var const4 = transformMatrix.g*transformMatrix.h;
var x = (transformMatrix.a+global_AABB[g][1])*(transformMatrix.b+global_AABB[g][0])+transformMatrix.c*global_AABB[g][2]-const1-const2;
var y = (transformMatrix.d+global_AABB[g][1])*(transformMatrix.e+global_AABB[g][0])+transformMatrix.f*global_AABB[g][2]-const3-const2;
var z = (transformMatrix.g+global_AABB[g][1])*(transformMatrix.h+global_AABB[g][0])+transformMatrix.i*global_AABB[g][2]-const4-const2;
global_AABB[g][0]=x; global_AABB[g][1]=y; global_AABB[g][2]=z;}}

if(rendermode!="calculate"){
/*
objlodg=true;objlodgarray=[];
if(global_AABB.length!=0){//(global_AABB[g][0])<100 && (global_AABB[g][0])>-100 && camera_x>global_AABB[g][0]-global_AABB[g][3]*3 && camera_x<global_AABB[g][0]+global_AABB[g][3]*3
for(g=0; g<global_AABB.length; g++){//|| (globalz)<=(global_AABB[g][2]-global_AABB[g][5])
//|| global_AABB[g][0]>100
//if((global_AABB[g][2]+global_AABB[g][5]>100) || (global_AABB[g][0]+global_AABB[g][3])>100){objlodg=false;}else{objlodg=true;}
objlodgarray.push([objlodg,global_AABB[g][6]]);
}}
*/
if(global_collision){
collision=false;for(g=0; g<global_AABB.length; g++){
if((camera_z+camera_dist/2)<=global_AABB[g][2] && camera_x>global_AABB[g][0]-global_AABB[g][3]*3 && camera_x<global_AABB[g][0]+global_AABB[g][3]*3 && camera_y<global_AABB[g][1]+global_AABB[g][4] && camera_y>global_AABB[g][1]-global_AABB[g][4]){collision=true;}else{}}

if(collision){
if(act_up){translate(0,0,-nav_speed);if(!walk_mode){delta_cam_z+=1;}
}else if(act_left){translate(nav_speed,0,0); 
}else if(act_right){translate(-nav_speed,0,0);}

if(walk_mode && act_mouse){delta_pitch+=m_x/5;camera_pitch=-m_x/5;

if(delta_pitch>60){
		//delta_pitch=60;
		//camera_pitch=0;
		camera_yaw=+m_y/5; delta_yaw+=m_y/5;
		//render(Fshape);	
	}else if(delta_pitch<-60){
		//delta_pitch=-60;
		//camera_pitch=0;
		camera_yaw=+m_y/5; delta_yaw+=m_y/5;
		//render(Fshape);	
	}else{
		camera_yaw=+m_y/5; delta_yaw+=m_y/5;
}}


act_up=act_down=act_left=act_right=act_mouse=false;}else{collision=false;}}

var verts2D=[]; var depthArray=[];
for (var i=0; i<model.Fside.length; i++) { 

var zDepth = 0;
for (var j=0; j<model.Fside[i].vertices.length; j++) { var whichVert =  model.Fside[i].vertices[j];
if (String(verts2D[whichVert])=="undefined") { verts2D[whichVert]={};
var scale=focalLength/(focalLength-model.FvertexList[whichVert].z);
verts2D[whichVert].x=model.FvertexList[whichVert].x*scale+String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("p"))/2;
verts2D[whichVert].y=model.FvertexList[whichVert].y*scale+String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("p"))/2;}
zDepth+=model.FvertexList[whichVert].z;} depthArray.push([model.Fside[i],zDepth]);} vsort(depthArray);

if(model.Fside.length<100 && creaseangle>0){make_creaseAngle(creaseangle,model);}

objanchorarraynames=[];

for (var i=0; i<ddresult.length; i++) {	

// *******************************************************************************************
//2D culling

drawit=true;//verd="";
/*
if(String(model.Fside[ddresult[i]].objlod)!="" && String(model.Fside[ddresult[i]].objlod)!="undefined"){

//alert(model.Fside[ddresult[i]].objlod);
if(String(model.Fside[ddresult[i]].objlod).indexOf("_low")!=-1){
stst=String(model.Fside[ddresult[i]].objlod).substring(0,String(model.Fside[ddresult[i]].objlod).indexOf("_low"));
}else{stst=String(model.Fside[ddresult[i]].objlod)}

for(l=0; l<objlodgarray.length; l++){
if(stst==objlodgarray[l][1]){verd=objlodgarray[l][0];}
}


	verd=false;


if(verd){
if(String(model.Fside[ddresult[i]].objlod).indexOf("_low")!=-1){drawit=true}else{drawit=false}
}else{
if(String(model.Fside[ddresult[i]].objlod).indexOf("_low")!=-1){drawit=false}else{drawit=true}
}

}
*/
can_x=Number(String(document.getElementById("x3dsection").style.left).substr(0,String(document.getElementById("x3dsection").style.left).indexOf("px")));
can_y=Number(String(document.getElementById("x3dsection").style.top).substr(0,String(document.getElementById("x3dsection").style.top).indexOf("px")));
our_w=Number(String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("px")));	
our_h=Number(String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("px")));	

if(drawit){
drawit_x=drawit_y=drawit_z=false;
for(tp=0; tp<model.Fside[ddresult[i]].vertices.length; tp++){
v_x=verts2D[model.Fside[ddresult[i]].vertices[tp]].x; 
v_y=verts2D[model.Fside[ddresult[i]].vertices[tp]].y; 
v_z=model.FvertexList[model.Fside[ddresult[i]].vertices[tp]].z; 
if(v_x<0 || v_x>our_w){}else{drawit_x=true;}
if(v_y<0 || v_y>our_h){}else{drawit_y=true;}
if(v_z>camera_z+camera_dist){}else{drawit_z=true;}//camera_z+camera_dist
/*
v_z=model.FvertexList[model.Fside[ddresult[i]].vertices[tp]].z;
if(v_z>camera_z+camera_dist){}else{drawit_z=true;}
*/
}
if(drawit_x==false || drawit_y==false || drawit_z==false){drawit=false;}else{drawit=true;}
}
/*
function findxy(x1,y1,x2,y2,x3,y3,x4,y4,n){

if(n==1){

ox=0;
oy=(y1*x2-y2*x1)/(x2-x1);

if(x1>x2){

ourdtos.push([x1,y1]);
ourdtos.push([ox,oy]);

}else{

ourdtos.push([ox,oy]);
//ourdtos.push([x2,y2]);	

}
} else if(n==2){
if(x2-x1==0){ox=x1;}else{
ox=-((y1*x2-y2*x1)/(x2-x1))/((y2-y1)/(x2-x1));}
oy=0;

if(y1>y2){
	
ourdtos.push([x1,y1]);
ourdtos.push([ox,oy]);	
	
} else if(n==3){
oy=our_h;
if(x2-x1==0){ox=x1;}else{
ox=(oy-((y1*x2-y2*x1)/(x2-x1)))/((y2-y1)/(x2-x1));

}

if(y1>y2){

ourdtos.push([ox,oy]);
//ourdtos.push([x1,y1]);		
	
}else{

ourdtos.push([x1,y1]);
ourdtos.push([ox,oy]);
	
}

}else{
	
ourdtos.push([ox,oy]);
//ourdtos.push([x2,y2]);	
	
}
	
	
} else if(n==4){
	
ox=our_w;
oy=ox*((y2-y1)/(x2-x1))+(y1*x2-y2*x1)/(x2-x1);

if(x1<x2){
ourdtos.push([x1,y1]);
ourdtos.push([ox,oy]);
	
	
}else if(x1>x2){

ourdtos.push([ox,oy]);	
//ourdtos.push([x2,y2]);
	
	
}	
	
}	
	
}
function intersec(ax1,ay1,ax2,ay2,bx1,by1,bx2,by2){
vp1=(bx2-bx1)*(ay1-by1)-(by2-by1)*(ax1-bx1);
vp2=(bx2-bx1)*(ay2-by1)-(by2-by1)*(ax2-bx1);
vp3=(ax2-ax1)*(by1-ay1)-(ay2-ay1)*(bx1-ax1);
vp4=(ax2-ax1)*(by2-ay1)-(ay2-ay1)*(bx2-ax1);
if((vp1*vp2<0) && (vp3*vp4<0)){return true;}else{ return false;}
}

vx1=verts2D[model.Fside[ddresult[i]].vertices[tp]].x;
vy1=verts2D[model.Fside[ddresult[i]].vertices[tp]].y;
if(tp==model.Fside[ddresult[i]].vertices.length-1){tpp=0;}else{tpp=tp+1;}
vx2=verts2D[model.Fside[ddresult[i]].vertices[tpp]].x;
vy2=verts2D[model.Fside[ddresult[i]].vertices[tpp]].y;

if(vx1>0 && vx1<our_w && vx2>0 && vx2<our_w && vy1>0 && vy1<our_h && vy2>0 && vy2<our_h){//alert(vx1+" :: "+vx2);
	ourdtos.push([vx1,vy1]);
	//ourdtos.push([vx2,vy2]);

	}else{

if(intersec(vx1,vy1,vx2,vy2,0,0,0,our_h)){findxy(vx1,vy1,vx2,vy2,0,0,0,our_h,1);}

if(intersec(vx1,vy1,vx2,vy2,0,0,our_w,0)){findxy(vx1,vy1,vx2,vy2,0,0,our_w,0,2);}

if(intersec(vx1,vy1,vx2,vy2,0,our_h,our_w,our_h)){findxy(vx1,vy1,vx2,vy2,0,our_h,our_w,our_h,3);}

if(intersec(vx1,vy1,vx2,vy2,our_w,0,our_w,our_h)){findxy(vx1,vy1,vx2,vy2,our_w,0,our_w,our_h,4);}

}
}
*/
/*
for(tu=0; tu<ourdtos.length; tu++){
verts2D[tu].x=ourdtos[tu][0];
verts2D[tu].y=ourdtos[tu][1];
	}*/	
//alert(ourdtos.length);
/*
for(tp=0; tp<ourdtos.length; tp++){
verts2D[tp].x=ourdtos[tp][0];
verts2D[tp].y=ourdtos[tp][1];
}
*/
/*
for(tp=0; tp<model.Fside[ddresult[i]].vertices; tp++){
verts2D[model.Fside[ddresult[i]].vertices[tp]].x=ourdtos[tp][0];
verts2D[model.Fside[ddresult[i]].vertices[tp]].y=ourdtos[tp][1];
}
*/


//}//}
/*
drawit_z=false;
for(tp=0; tp<model.Fside[ddresult[i]].vertices.length; tp++){
v_z=model.FvertexList[model.Fside[ddresult[i]].vertices[tp]].z;
if(v_z>camera_z+camera_dist){}else{drawit_z=true;}
}

if(drawit_z){
drawit=true;//docheckint();
}
*/
/*	
drawit_s=false;	
for(tp=0; tp<model.Fside[ddresult[i]].vertices.length; tp++){
v_x=verts2D[model.Fside[ddresult[i]].vertices[tp]].x; v_y=verts2D[model.Fside[ddresult[i]].vertices[tp]].y;
if(v_x>our_w){}else{drawit_s=true;}}
if(drawit_s){
drawit_s2=false;	
for(tp=0; tp<model.Fside[ddresult[i]].vertices.length; tp++){
v_x=verts2D[model.Fside[ddresult[i]].vertices[tp]].x; v_y=verts2D[model.Fside[ddresult[i]].vertices[tp]].y;
if(v_x<0){}else{drawit_s2=true;}}	
if(drawit_s2){
drawit_s3=false;		
for(tp=0; tp<model.Fside[ddresult[i]].vertices.length; tp++){
v_x=verts2D[model.Fside[ddresult[i]].vertices[tp]].x; v_y=verts2D[model.Fside[ddresult[i]].vertices[tp]].y;
if(v_y<0){}else{drawit_s3=true;}}		
if(drawit_s3){
drawit_s4=false;		
for(tp=0; tp<model.Fside[ddresult[i]].vertices.length; tp++){
v_x=verts2D[model.Fside[ddresult[i]].vertices[tp]].x; v_y=verts2D[model.Fside[ddresult[i]].vertices[tp]].y;
if(v_y>our_h){}else{drawit_s4=true;}}	
if(drawit_s4){
	//drawit=true;docheckint();
	}	
	}	
	}	
	}*/
//}
//drawit=true;
//docheckint();

/*
drawit_z=false;
for(tp=0; tp<model.Fside[ddresult[i]].vertices.length; tp++){
v_z=model.FvertexList[model.Fside[ddresult[i]].vertices[tp]].z;
if(v_z>camera_z+camera_dist){}else{drawit_z=true;}
}*/

if(drawit){

if(model.Fside[ddresult[i]].thisurl!=""){

arrrs=[];
for(tpp=0; tpp<model.Fside[ddresult[i]].vertices.length; tpp++){
arrrs.push([(verts2D[model.Fside[ddresult[i]].vertices[tpp]].x).toFixed(2),(verts2D[model.Fside[ddresult[i]].vertices[tpp]].y).toFixed(2)]);}

if(objanchorarraynames.length!=0){ggood=-1;
for(k9=0; k9<objanchorarraynames.length; k9++){if(objanchorarraynames[k9][0]==model.Fside[ddresult[i]].objanchor){
tyky=objanchorarraynames[k9][4];tyky=tyky.concat(arrrs);objanchorarraynames[k9][4]=tyky;ggood=k9;}}
		
if(ggood==-1){objanchorarraynames.push([model.Fside[ddresult[i]].objanchor,model.Fside[ddresult[i]].thisurl,model.Fside[ddresult[i]].thisdescription,model.Fside[ddresult[i]].thisparameter,arrrs]); ggood=objanchorarraynames.length-1;}
	
}else{objanchorarraynames.push([model.Fside[ddresult[i]].objanchor,model.Fside[ddresult[i]].thisurl,model.Fside[ddresult[i]].thisdescription,model.Fside[ddresult[i]].thisparameter,arrrs]); ggood=0;}

}

if(model.Fside[ddresult[i]].text==true || creaseangle>0){
context.shadowOffsetX=1; context.shadowOffsetY=1; context.shadowBlur=5;
context.shadowColor="rgba("+c1*255+","+c2*255+","+c3*255+",0.5)";	
}else{context.shadowOffsetX=0; context.shadowOffsetY=0; context.shadowBlur=0;}	

var sideVerts = model.Fside[ddresult[i]].vertices;

if(typesolid=="true"){backface(sideVerts);}else{perm=true;}

if(perm){
context.save();	
context.beginPath();
context.moveTo(verts2D[sideVerts[0]].x,verts2D[sideVerts[0]].y);	
lColorCode=getSideColor(model,model.Fside[ddresult[i]]);
lColor = lColorCode; iRed = Math.ceil(lColor[0]); iGreen = Math.ceil(lColor[1]); iBlue = Math.ceil(lColor[2]);
a=model.Fside[ddresult[i]].sideAlpha;
if(document.getElementById("x3dsection").wireframes=="false"){
context.fillStyle="rgba("+iRed+","+iGreen+","+iBlue+","+a+")";
if(a==1){}else{a=a/4;}
if(model.Fside[ddresult[i]].text!=true){
context.strokeStyle="rgba("+iRed+","+iGreen+","+iBlue+","+a+")";
}else{context.strokeStyle="rgba("+iRed+","+iGreen+","+iBlue+","+a+")";}
}else{context.shadowColor="rgba("+iRed+","+iGreen+","+iBlue+",0)";//"rgba("+c1*255+","+c2*255+","+c3*255+",0)";
if(model.Fside[ddresult[i]].text!=true){context.strokeStyle="rgba("+iRed+","+iGreen+","+iBlue+",1)";}else{
context.strokeStyle="rgba("+iRed+","+iGreen+","+iBlue+",0)";}}
		
for(var j=1; j<sideVerts.length; j++){context.lineTo(verts2D[sideVerts[j]].x,verts2D[sideVerts[j]].y);}
context.lineTo(verts2D[sideVerts[0]].x,verts2D[sideVerts[0]].y);

if(document.getElementById("x3dsection").wireframes=="true"){
if(model.Fside[ddresult[i]].text!=true){context.lineWidth=1;context.stroke();
}else{context.lineWidth=model.Fside[ddresult[i]].style;context.stroke();}
}else{if(model.Fside[ddresult[i]].text!=true){
brows=navigator.userAgent.toLowerCase();
if(brows.indexOf("firefox")!=-1 || brows.indexOf("opera")!=-1 || (navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)){if(ddresult.length>500){motiont="false";}else{motiont=model.Fside[ddresult[i]].motiontextures;}
}else{motiont=model.Fside[ddresult[i]].motiontextures;}
if(model.Fside[ddresult[i]].thistexture==""){context.fill();}else{
	if(mentiontextures==true && motiont=="false"){context.fill();}else{

// *******************************************************************************************
//texturing	
function place_texture(){
x0 = verts2D[sideVerts[0]].x; y0 = verts2D[sideVerts[0]].y;
x1 = verts2D[sideVerts[1]].x; y1 = verts2D[sideVerts[1]].y;
x2 = verts2D[sideVerts[2]].x; y2 = verts2D[sideVerts[2]].y;	
if(denom==""){denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;}
m11 = - (sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
m22 = - (sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
dx = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
dy = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;
brows=navigator.userAgent.toLowerCase();if(brows.indexOf("firefox")!=-1){if(m12==0){m12+=0.1;}}; context.transform(m11,m12,m21,m22,dx,dy);
context.fillStyle="rgba(0,0,0,0)";context.fill();context.drawImage(bitmap,0,0);context.restore();
context.fillStyle="rgba("+iRed+","+iGreen+","+iBlue+",0.2)";context.fill();};trs=false; trn=0;
for(tr=0;tr<obj.textures.length/4;tr++){if(String(obj.textures[4*tr+1])==String(model.Fside[ddresult[i]].thistexture) && trs==false){trs=true;trn=4*tr}}
bitmap = obj.textures[trn]; bitmap_width=obj.textures[trn+2]; bitmap_height=obj.textures[trn+3];context.clip();
if(rat){
if(model.Fside[ddresult[i]].tn==0){
tex_swt=1;denom="";
sx0=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[0]][0])*bitmap_width;
sy0=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[0]][1])*bitmap_height;
sx1=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[1]][0])*bitmap_width;
sy1=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[1]][1])*bitmap_height;
sx2=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[2]][0])*bitmap_width;
sy2=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[2]][1])*bitmap_height;
place_texture();
}else{tex_swt=0;denom="";
sx0=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[0]][0])*bitmap_width;
sy0=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[0]][1])*bitmap_height;
sx2=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[1]][0])*bitmap_width;
sy2=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[1]][1])*bitmap_height;
sx1=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[2]][0])*bitmap_width;
sy1=Number(inner_tex_coords[model.Fside[ddresult[i]].texture_map[2]][1])*bitmap_height;	
place_texture();}}else{
if(String(model.Fside[ddresult[i]].sidename)!="undefined"){
if(String(model.Fside[ddresult[i]].sidename).indexOf("cylinder")!=-1 || String(model.Fside[ddresult[i]].sidename).indexOf("conus")!=-1){
if(String(model.Fside[ddresult[i]].sidename).indexOf("cylinder")!=-1){	
which_side=String(model.Fside[ddresult[i]].sidename).substring(9,10);
which_number=Number(String(model.Fside[ddresult[i]].sidename).substr(10,String(model.Fside[ddresult[i]].sidename).length));
}else if(String(model.Fside[ddresult[i]].sidename).indexOf("conus")!=-1){
which_side=String(model.Fside[ddresult[i]].sidename).substring(6,7);
which_number=Number(String(model.Fside[ddresult[i]].sidename).substr(7,String(model.Fside[ddresult[i]].sidename).length));}
how_many=model.Fside[ddresult[i]].total; part_width=bitmap_width/how_many; context.lineWidth=0;
if(which_side=="a"){tex_swt=1;denom="";if(which_number==0){
if(String(model.Fside[ddresult[i]].sidename).indexOf("conus")!=-1){
sx2 = part_width*(which_number); sy2 = bitmap_height; sx1 = part_width*(which_number+1); sy1 = bitmap_height; sx0 =part_width*(which_number+1); sy0 = 0;	
}else if(String(model.Fside[ddresult[i]].sidename).indexOf("cylinder")!=-1){
sx2 = part_width*(which_number)+1; sy2 = bitmap_height; sx1 = part_width*(which_number)+1; sy1 = 0; sx0 = part_width*(which_number+1)-1; sy0 = 0;
}}else{if(String(model.Fside[ddresult[i]].sidename).indexOf("conus")!=-1){
sx2 = part_width*(which_number+1); sy2 = bitmap_height; sx1 = part_width*(which_number); sy1 = bitmap_height; sx0 = part_width*(which_number); sy0 = 0;		
}else if(String(model.Fside[ddresult[i]].sidename).indexOf("cylinder")!=-1){
sx2 = part_width*(which_number)+1; sy2 = 0; sx1 = part_width*(which_number+1)-1; sy1 = 0; sx0 =part_width*(which_number+1)-1; sy0 = bitmap_height;}}
place_texture();}else if(which_side=="b"){
tex_swt=0;denom="";	if(which_number==0){
sx0 = part_width*(which_number); sy0 = bitmap_height; sx1 = part_width*(which_number+1); sy1 = bitmap_height; sx2 =part_width*(which_number+1); sy2 = 0;}else{
sx0 = part_width*(which_number); sy0 = 0; sx1 = part_width*(which_number); sy1 = bitmap_height; sx2 =part_width*(which_number+1); sy2 =  bitmap_height;}
place_texture();}else if(which_side="c"){
tex_swt=0;denom="";	
if(bitmap_width/2>=bitmap_height/2){r=bitmap_width/2;}else{r=bitmap_height/2;}; m0=bitmap_width/2; m1=bitmap_height/2; ist=2*Math.PI/how_many;
sx2=2*r*Math.cos(which_number*ist)/2+m0; sy2=2*r*Math.sin(which_number*ist)/2+m1; 
sx1=2*r*Math.cos((which_number+1)*ist)/2+m0; sy1=2*r*Math.sin((which_number+1)*ist)/2+m1; sx0=m0; sy0=m1;
place_texture();}
}else if(String(model.Fside[ddresult[i]].sidename).indexOf("sphere")!=-1){
which_side=String(model.Fside[ddresult[i]].sidename).substring(7,8);
lstr=String(model.Fside[ddresult[i]].sidename).substr(9,String(model.Fside[ddresult[i]].sidename).length)
which_number1=Number(String(model.Fside[ddresult[i]].sidename).substr(9,lstr.indexOf("_")));
which_number2=Number(lstr.substring(lstr.lastIndexOf("_")+1,String(model.Fside[ddresult[i]].sidename).length));
how_many1=Number(String(model.Fside[ddresult[i]].total).substr(0,String(model.Fside[ddresult[i]].total).indexOf("_")));
how_many2=Number(String(model.Fside[ddresult[i]].total).substr(String(model.Fside[ddresult[i]].total).lastIndexOf("_")+1,String(model.Fside[ddresult[i]].total).length));
part_width=bitmap_width/how_many1; part_height=bitmap_height/how_many2;
if(which_side=="a"){tex_swt=1;denom="";
if(which_number1==how_many1-1){
sx2 = part_width*(which_number1)+1; sy2 = part_height*(which_number2); sx1 = part_width*(which_number1+1)-1; sy1 = part_height*(which_number2); 
sx0 = part_width*(which_number1+1)-1; sy0 = part_height*(which_number2+1);}else{
sx2 = part_width*(which_number1); sy2 = part_height*(which_number2); sx1 = part_width*(which_number1+1); sy1 = part_height*(which_number2); 
sx0 = part_width*(which_number1+1); sy0 = part_height*(which_number2+1);}
place_texture();
}else if(which_side=="b"){tex_swt=1;denom="";
if(which_number1==0){
sx0 = part_width*(which_number1)+1; sy0 = part_height*(which_number2); sx1 = part_width*(which_number1)+1; sy1 = part_height*(which_number2+1); 
sx2 = part_width*(which_number1+1)-1; sy2 = part_height*(which_number2+1);}else{
sx0 = part_width*(which_number1); sy0 = part_height*(which_number2); sx1 = part_width*(which_number1); sy1 = part_height*(which_number2+1); 
sx2 = part_width*(which_number1+1); sy2 = part_height*(which_number2+1);}
place_texture();}
}}else{context.lineWidth=0;
if(model.Fside[ddresult[i]].tn==0){tex_swt=1;denom="";
sx0 = (bitmap_width-1); sy0 = 1; sx1 = 1; sy1 = 1; sx2 = 1; sy2 = (bitmap_height-1);
place_texture();}else{tex_swt=0;denom="";	
sx0 = 1; sy0 = (bitmap_height-1); sx1 = (bitmap_width-1); sy1 = (bitmap_height-1); sx2 = (bitmap_width-1); sy2 = 1;
place_texture();}}context.lineWidth=0;}}}}
else{context.lineWidth=model.Fside[ddresult[i]].style;context.stroke();}};
if(model.Fside[ddresult[i]].thistexture!=""){context.lineWidth=0;}else{context.lineWidth=1;}
if(model.Fside[ddresult[i]].thistexture==""){context.stroke();};context.closePath();}}}

CalculateFrameRate();
if(!calculate_process){document.getElementById("t1").innerHTML=FPS+" fps"+" || polygons number: "+ddresult.length;
}else{document.getElementById("t1").innerHTML="calculating normals (creaseAngle) > please wait < <font color='grey'>####################</font>";}

}};//}//end of render

// *******************************************************************************************
//lights
getSideColor = function (model,side) {
if(String(side.thistexture)!="undefined" && side.thistexture!=""){side.sideColor[0]=0;side.sideColor[1]=0;side.sideColor[2]=0;}	
var verts = [model.FvertexList[side.vertices[0]],model.FvertexList[side.vertices[1]],model.FvertexList[side.vertices[2]]];
var lightFactor = factorLightAngle(verts,side); return(lightFactor);}
factorLightAngle = function (vertices,side) {
if(creaseangle==0){if(real_norm_verts_array.length!=0){p1=side.normal[0]; p2=side.normal[1]; p3=side.normal[2];}else{	
var U = [(vertices[0].x-vertices[1].x),(vertices[0].y-vertices[1].y),(vertices[0].z-vertices[1].z)];
var V = [(vertices[1].x-vertices[2].x),(vertices[1].y-vertices[2].y),(vertices[1].z-vertices[2].z)];
var p = [((U[1]*V[2])-(U[2]*V[1])),((U[0]*V[2])-(U[2]*V[0])),((U[0]*V[1])-(U[1]*V[0]))];
var magPP = Math.sqrt((p[0]*p[0])+(p[1]*p[1])+(p[2]*p[2]));
t=1/magPP; p1=p[0]*t; p2=p[1]*t; p3=p[2]*t;}}else{pi=[];
pi[0]=side.normal[0]; pi[1]=side.normal[1]; pi[2]=side.normal[2]; magPi=side.normal[3]; p1=pi[0]; p2=pi[1]; p3=pi[2];}
lt=1/light.magnitude; light1=light.x*lt; light2=light.y*lt; light3=light.z*lt;
var dP = ((p1*light1)+(p2*light2)+(p3*light3));	
var NL=(p1*light1)+(p2*light2)+(p3*light3);
var R=[(2*NL*p1-light1),(2*NL*p2-light2),(2*NL*p3-light3)];
V={x:0,y:0,z:-200}; magV=Math.sqrt(V.x*V.x+V.y*V.y+V.z*V.z); tv=1/magV; V1=V.x*tv; V2=V.y*tv; V3=V.z*tv;
var RV=R[0]*V1+R[1]*V2+R[2]*V3;
Ka=side.sideColor[4]*3; 
D={r:side.sideColor[0],g:side.sideColor[1],b:side.sideColor[2]}; 
A={r:Ka*D.r,g:Ka*D.g,b:Ka*D.b};
Kd=0.6; Att=0.8; L={r:1,g:1,b:1}; Ks=1; 
S={r:side.sideColor[5],g:side.sideColor[6],b:side.sideColor[7]}; 
n=side.sideColor[3]*20; 
Ir = side.sideColor[8]+A.r*Ka + Att*L.r*Kd*D.r*NL + Att*L.r*Ks*S.r*Math.pow(Math.max(RV,0),n); 
Ig = side.sideColor[9]+A.g*Ka + Att*L.g*Kd*D.g*NL + Att*L.g*Ks*S.g*Math.pow(Math.max(RV,0),n); 
Ib = side.sideColor[10]+A.b*Ka + Att*L.b*Kd*D.b*NL + Att*L.b*Ks*S.b*Math.pow(Math.max(RV,0),n);
return([(Ir*255),(Ig*255),(Ib*255)]);}
	
// *******************************************************************************************
//FPS calculation
var FPS=0.0; var framesPerSecond = 0.0; var lastTime = 0.0;
function CalculateFrameRate(){
d=new Date(); currentTime = d.getTime()*0.001; framesPerSecond++;
if(currentTime-lastTime > 1.0){ lastTime = currentTime; FPS=framesPerSecond; framesPerSecond = 0;}}

// *******************************************************************************************
//engine start-point
//dotextures=true;
mentiontextures=false;
var parent = document.getElementById("x3dsection");
var nnewsection = document.createElement("section");nnewsection.id = "widget";nnewsection.style.width = 100+"px";parent.appendChild(nnewsection);
document.getElementById("widget").style.visibility = "hidden";
document.getElementById("widget").onselectstart = function() { return(false); };var mywidget=document.getElementById("widget");
mywidget.innerHTML="<section id='t1' style='position:absolute; top:5px; left:5px; color:whitesmoke; font-family:Arial; border-style:dashed; border-width:3px 3px 3px 3px; border-color:rgba(50,50,50,1); padding: 2px 2px 2px 2px; align:right; -moz-user-select: none; -khtml-user-select: none; user-select: none; -webkit-user-select: none'></section>";

var nnewsection2 = document.createElement("section");nnewsection2.id = "des_wnd";nnewsection2.style.width = 100+"px";parent.appendChild(nnewsection2);
//for modes
var nnewsection2 = document.createElement("section");nnewsection2.id = "des_mode";nnewsection2.style.width = 100+"px";parent.appendChild(nnewsection2);
nnewsection2.style.opacity = 0;

parse_nodes(1);

light = new LightSource(-nav_speed*delta_cam_x,-camera_y,700+nav_speed*delta_cam_z,100);

vp=false;

function load_textures(){lt=0;
function loading_tex(yt){var base_image = new Image();
base_image.onload = function(){obj.textures.push(base_image);obj.textures.push(bitmaps[yt]);
if(vp){}else{
howmanyim=(yt*100)/bitmaps.length;
document.getElementById("loading_status").innerHTML="<p style='font-family:Arial;font-size:9pt;color:rgb(46,99,167);text-align:left;line-height:1;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[loading textures @ "+Math.ceil(howmanyim)+"%]</p>";}
obj.textures.push(base_image.width);obj.textures.push(base_image.height);lt++;
if(lt<bitmaps.length){loading_tex(lt);}else{
if(vp){
camera_x=viewpoints[cam_c][0]; camera_y=viewpoints[cam_c][1]; camera_z=viewpoints[cam_c][2];
camera_pitch=viewpoints[cam_c][3]; camera_yaw=viewpoints[cam_c][4]; camera_roll=viewpoints[cam_c][5]; camera_description=viewpoints[cam_c][6];
camera=true; shiftx=camera_x; shifty=camera_y; shiftz=camera_z; shiftpitch=camera_pitch; shiftyaw=camera_yaw; shiftroll=camera_roll;delta_cam_z=0;
render(Fshape);
camera_yaw=camera_pitch=camera_roll=0; camera_x=camera_y=camera_z=0;
}else{
camera_dist=700; camera_x=new_camera_x; camera_y=new_camera_y; camera_z=new_camera_z;
camera_pitch=new_camera_pitch; camera_yaw=new_camera_yaw; camera_roll=new_camera_roll; camera_description=new_camera_description;
shiftx=shifty=shiftz=shiftpitch=shiftyaw=shiftroll=0;
}

//camera_yaw=camera_pitch=camera_roll=0; camera_x=camera_y=camera_z=0;
//render_permission=true;calculate_process=false;

render(Fshape);
render_permission=true;calculate_process=false;

//textures=false;
}}; base_image.src = bitmaps[yt];};if(bitmaps.length!=0){render_permission=false;loading_tex(0);}
};load_textures();

camera_dist=700; camera_x=new_camera_x; camera_y=new_camera_y; camera_z=new_camera_z;//-new_camera_z-camera_dist;
camera_pitch=new_camera_pitch; camera_yaw=new_camera_yaw; camera_roll=new_camera_roll; camera_description=new_camera_description;
shiftx=shifty=shiftz=shiftpitch=shiftyaw=shiftroll=0;

//light = new LightSource(-camera_x,-camera_y,200+camera_z,100);
if(!textures && calculate_process==false){render_permission=true;}

doit=function(){ttt=Fshape.Fside;
if(!textures && calculate_process==false){render_permission=true;}
if(calculate_process){document.getElementById("loading_status").innerHTML="<p style='font-family:Arial;font-size:9pt;color:rgb(46,99,167);text-align:left;line-height:1;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[calculating...]</p>";}

if(render_permission){clearInterval(load_models);
document.getElementById("x3dsection").removeChild(document.getElementById("preloader")); 
document.getElementById("x3dsection").removeChild(document.getElementById("loading_status"));

document.getElementById("stamp").style.display="block";
document.getElementById("map").style.display="block";
document.getElementById("background").style.display="block";
document.getElementById("navigationring").style.display="block";
document.getElementById("help1").style.display="block";
document.getElementById("help2").style.display="block";	
if(Math.random()<0.5){muss="";}else{muss="2";};document.getElementById("island"+muss).play();

render(Fshape);}} 

load_models = setInterval("doit()",1);

// *******************************************************************************************
//HUD - heads-up-display
mode_screen=false;mode_str="";
function do_mode_screen(mes){
if(!mode_screen){mode_screen=true; vdd=0; mshowit3=function(){
vdd++; document.getElementById("des_mode").style.opacity=1-(0.02*vdd);
if(vdd==50){clearInterval(imddd3);document.getElementById("des_mode").style.display="none";mode_screen=false;}}
mshowit2=function(){clearInterval(imdddd);vdd=0; imddd3=setInterval("mshowit3()",5);}
mshowit=function(){	document.getElementById("des_mode").style.display="inline";
vdd++; document.getElementById("des_mode").style.opacity=0.02*vdd; if(vdd==50){clearInterval(imddd);imdddd=setInterval("mshowit2()",500);}}
imddd=setInterval("mshowit()",5);}}

function do_WALK_navigation(){walk_mode=true;} function do_EXAMINE_navigation(){walk_mode=false;}

moveup=movedown=moveleft=moveright=false;

mshowit5 = function(){

brows=navigator.userAgent.toLowerCase();if(brows.indexOf("firefox")!=-1){window.scrollTo(0,0);}
	
camera=true;	
if(moveup){
brows=navigator.userAgent.toLowerCase();if(brows.indexOf("firefox")!=-1){window.scrollTo(0,0);}	
if(global_collision){act_up=true;};

//camera_x=camera_y=0;
//camera_yaw=camera_roll=0;
camera_z=0;
transformMatrix="";
translate(0,0,camera_z-700); 
cameraX(-delta_pitch);
//cameraY(-delta_yaw);
translate(0,0,camera_z+700); 
	//camera_yaw=0; 
camera_roll=camera_yaw=camera_pitch=0;//camera_yaw=camera_pitch=0;
camera_z=-nav_speed; 

if(delta_yaw>360){ruki=delta_yaw-360;}
else if(delta_yaw<-360){ruki=delta_yaw+360;}
else {ruki=delta_yaw;}

/*
if(ruki>270 || ruki<-270){
globalz-=Math.cos((Math.abs(ruki)-270)*Math.PI/180)*nav_speed;}
else if(ruki>180 || ruki<-180){
globalz+=Math.cos((Math.abs(ruki)-180)*Math.PI/180)*nav_speed;}	
else if(ruki>90 || ruki<-90){
globalz+=Math.cos((180-Math.abs(ruki))*Math.PI/180)*nav_speed;	
}else if(ruki<90 || ruki>-90){
globalz-=Math.cos(ruki*Math.PI/180)*nav_speed;}
*/

globalz-=nav_speed;

translate(0,0,-camera_z);
camera_y=0;
camera_z=0;
camera_x=0;
camera_pitch=delta_pitch;	
	//camera_yaw=delta_yaw;
camera_roll=0;	
render(Fshape);
brows=navigator.userAgent.toLowerCase();if(brows.indexOf("firefox")!=-1){window.scrollTo(0,0);}

}else if(movedown){
brows=navigator.userAgent.toLowerCase();if(brows.indexOf("firefox")!=-1){window.scrollTo(0,0);}	
//camera_x=camera_y=0;
camera_z=0;
transformMatrix="";
translate(0,0,camera_z-700); 
cameraX(-delta_pitch);
translate(0,0,camera_z+700); 
	//camera_yaw=0; 
camera_roll=camera_yaw=camera_pitch=0;
camera_z=-nav_speed; globalz+=Math.cos(delta_yaw*Math.PI/180)*nav_speed;
translate(0,0,camera_z); 
camera_y=0;
camera_z=0;
camera_x=0;
camera_pitch=delta_pitch;	
	//camera_yaw=delta_yaw;
camera_roll=0;
brows=navigator.userAgent.toLowerCase();if(brows.indexOf("firefox")!=-1){window.scrollTo(0,0);}	
render(Fshape);	
brows=navigator.userAgent.toLowerCase();if(brows.indexOf("firefox")!=-1){window.scrollTo(0,0);}
}else if(moveleft){if(global_collision){act_left=true;}
//camera_x=camera_y=
camera_z=0;
transformMatrix="";
translate(0,0,camera_z-700); 
cameraX(-delta_pitch);
translate(0,0,camera_z+700); 
	//camera_yaw=0; 
camera_roll=0;
camera_x=nav_speed;
translate(camera_x,0,0); 
camera_y=0;
camera_z=0;
camera_pitch=delta_pitch;	
	//camera_yaw=delta_yaw;
camera_roll=0;
render(Fshape);
}else if(moveright){if(global_collision){act_right=true;}
//camera_x=camera_y=
camera_z=0;
transformMatrix="";
translate(0,0,camera_z-700); 
cameraX(-delta_pitch);
translate(0,0,camera_z+700); 
	//camera_yaw=0; 
camera_roll=0;
camera_x=-nav_speed;
translate(camera_x,0,0); 
camera_y=0;
camera_z=0;
camera_pitch=delta_pitch;	
	//camera_yaw=delta_yaw;
camera_roll=0;
render(Fshape);		
}

}

if(walk_mode){walk_int=setInterval("mshowit5()",1/1000);}

// *******************************************************************************************
//camera zoom in / out
zoomin=zoomout=false; zoominout = function(){
if(zoomin){if(global_collision){act_up=true;};camera_yaw=camera_pitch=camera_roll=0; camera_x=camera_y=camera_z=0;
camera=true; delta_cam_z-=1; transformMatrix=""; translate(0,0,nav_speed); render(Fshape);
}else if(zoomout){if(global_collision){act_down=true;};camera_yaw=camera_pitch=camera_roll=0; camera_x=camera_y=camera_z=0;
camera=true; delta_cam_z+=1; transformMatrix=""; translate(0,0,-nav_speed); render(Fshape);}}
zoom_int=setInterval("zoominout()",1/1000);

// *******************************************************************************************
//camera switch
cam_c=-1;
function change_camera(){if(render_permission){	
cam_c++; if(cam_c==viewpoints.length){cam_c=0;} mode_str=viewpoints[cam_c][6];//rgba(139,137,137,0.6)
document.getElementById("des_mode").innerHTML="<section id='t1' width="+200+"px style='position:absolute; left:"+cl_x+"px; top:"+cl_y+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+200+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px;-moz-user-select: none; -khtml-user-select: none; user-select: none;'>"+mode_str+"</section>"; 
do_mode_screen(); transformMatrix=""; parse_nodes(1); vp=true; if(textures){load_textures();}else{
camera_x=viewpoints[cam_c][0]; camera_y=viewpoints[cam_c][1]; camera_z=viewpoints[cam_c][2];
camera_pitch=viewpoints[cam_c][3]; camera_yaw=viewpoints[cam_c][4]; camera_roll=viewpoints[cam_c][5]; camera_description=viewpoints[cam_c][6];
camera=true; shiftx=camera_x; shifty=camera_y; shiftz=camera_z; shiftpitch=camera_pitch; shiftyaw=camera_yaw; shiftroll=camera_roll; render(Fshape); delta_cam_z=0;}}}

// *******************************************************************************************
//hot-keys events
function hotkeys_down(event){
can_x=Number(String(document.getElementById("x3dsection").style.left).substr(0,String(document.getElementById("x3dsection").style.left).indexOf("px")));
can_y=Number(String(document.getElementById("x3dsection").style.top).substr(0,String(document.getElementById("x3dsection").style.top).indexOf("px")));
our_w=Number(String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("px")));	
our_h=Number(String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("px")));	
cl_x=our_w/2-100; cl_y=our_h/2-50;	
//wireframes_mode
if(document.getElementById("x3dsection").hotkeys=="true"){
if(event.keyCode==82){if(!wireframes_key_up){wireframes_key_up=true;
if(!wireframes_key){mode_str="<b>wireframes</b> mode<br>enabled"; camera_yaw=camera_pitch=camera_roll=0; camera_x=camera_y=camera_z=0;
document.getElementById("des_mode").innerHTML="<section id='t1' width="+200+"px style='position:absolute; left:"+cl_x+"px; top:"+cl_y+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+200+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px;-moz-user-select: none; -khtml-user-select: none; user-select: none; -webkit-user-select: none'>"+mode_str+"</section>"; do_mode_screen();	
document.getElementById("x3dsection").wireframes="true"; render(Fshape); wireframes_key=true; 
}else{mode_str="<b>wireframes</b> mode<br>disabled"; camera_yaw=camera_pitch=camera_roll=0; camera_x=camera_y=camera_z=0;
document.getElementById("des_mode").innerHTML="<section id='t1' width="+200+"px style='position:absolute; left:"+cl_x+"px; top:"+cl_y+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+200+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px;-moz-user-select: none; -khtml-user-select: none; user-select: none; -webkit-user-select: none;'>"+mode_str+"</section>"; do_mode_screen();	
document.getElementById("x3dsection").wireframes="false"; render(Fshape); wireframes_key=false;}}}}
//status bar mode
if(document.getElementById("x3dsection").hotkeys=="true"){
if(event.keyCode==83){if(!statusbar_key_up){statusbar_key_up=true;	
if(!statusbar_key){document.getElementById("widget").style.visibility = "visible"; statusbar_key=true;
}else{document.getElementById("widget").style.visibility = "hidden"; statusbar_key=false;}}}}
//WALK mode
if(document.getElementById("x3dsection").hotkeys=="true"){
if(event.keyCode==87){if(!walkmode_key_up){walkmode_key_up=true;	
if(!walkmode_key){camera_yaw=camera_pitch=camera_roll=0; camera_x=camera_y=camera_z=0; walk_int=setInterval("mshowit5()",1/1000);
mode_str="<b>walk</b> mode<br>activated";
document.getElementById("des_mode").innerHTML="<section id='t1' width="+200+"px style='position:absolute; left:"+cl_x+"px; top:"+cl_y+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+200+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px;-moz-user-select: none; -khtml-user-select: none; user-select: none; -webkit-user-select: none;'>"+mode_str+"</section>"; 
do_mode_screen(); do_WALK_navigation(); examinemode_key=false; }else{ }}}}
//EXAMINE mode
if(document.getElementById("x3dsection").hotkeys=="true"){
if(event.keyCode==69){if(!examinemode_key_up){examinemode_key_up=true;	
if(!examinemode_key){camera_x=camera_y=camera_z=0; camera_yaw=camera_pitch=camera_roll=0; clearInterval(walk_int);
mode_str="<b>examine</b> mode<br>activated";
document.getElementById("des_mode").innerHTML="<section id='t1' width="+200+"px style='position:absolute; left:"+cl_x+"px; top:"+cl_y+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+200+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px;-moz-user-select: none; -khtml-user-select: none; user-select: none; -webkit-user-select: none'>"+mode_str+"</section>"; 
do_mode_screen(); do_EXAMINE_navigation(); examinemode_key=true;}else{ }}}}
//Viewpoint
if(document.getElementById("x3dsection").hotkeys=="true"){
if(event.keyCode==86){if(!viewpoint_key_up){viewpoint_key_up=true;	
if(!viewpoint_key){change_camera(); viewpoint_key=true; 
}else{change_camera(); viewpoint_key=false;}}}}
//Collision
if(document.getElementById("x3dsection").hotkeys=="true"){
if(event.keyCode==67){if(!collision_key_up){collision_key_up=true;	
if(!collision_key){mode_str="<b>collision</b> detection<br>enabled";
document.getElementById("des_mode").innerHTML="<section id='t1' width="+200+"px style='position:absolute; left:"+cl_x+"px; top:"+cl_y+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+200+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px;-moz-user-select: none; -khtml-user-select: none; user-select: none; -webkit-user-select: none'>"+mode_str+"</section>"; 
do_mode_screen();  global_collision=true; collision_key=true; 
}else{ mode_str="<b>collision</b> detection<br>disabled";
document.getElementById("des_mode").innerHTML="<section id='t1' width="+200+"px style='position:absolute; left:"+cl_x+"px; top:"+cl_y+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+200+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px;-moz-user-select: none; -khtml-user-select: none; user-select: none; -webkit-user-select: none'>"+mode_str+"</section>"; 
do_mode_screen(); global_collision=false; collision_key=false;}}}}
//Zoom In / Zoom Out
if(!walk_mode){if(event.keyCode==38){zoomin=true;}else if(event.keyCode==40){zoomout=true;}else{camera_x=camera_z=0;}
//Walk motion if(motiontextures=="false"){dotextures=false;};
}else if(walk_mode){
brows=navigator.userAgent.toLowerCase();if(brows.indexOf("firefox")!=-1){window.scrollTo(0,0);}
camera=true; if(event.keyCode==37){
	//if(walk_mode){walk_int=setInterval("mshowit5()",1/1000);};
	mentiontextures=true;moveleft=true;}else if(event.keyCode==39){
	//if(walk_mode){walk_int=setInterval("mshowit5()",1/1000);};
	mentiontextures=true;moveright=true;}
else if(event.keyCode==38){
	//if(walk_mode){walk_int=setInterval("mshowit5()",1/1000);};
	mentiontextures=true;moveup=true;}else if(event.keyCode==40){
	//if(walk_mode){walk_int=setInterval("mshowit5()",1/1000);};
	mentiontextures=true;movedown=true;}else{camera_x=camera_z=0;}}}
function hotkeys_up(event){//clearInterval(clearInterval(walk_int));
mentiontextures=false;
if(event.keyCode==82){wireframes_key_up=false;render(Fshape);} if(event.keyCode==83){statusbar_key_up=false;render(Fshape);} if(event.keyCode==87){walkmode_key_up=false;render(Fshape);}
if(event.keyCode==69){examinemode_key_up=false;render(Fshape);} if(event.keyCode==86){viewpoint_key_up=false;} if(event.keyCode==67){collision_key_up=false;render(Fshape);}
if(!walk_mode){if(event.keyCode==38){zoomin=false;render(Fshape);} if(event.keyCode==40){zoomout=false;render(Fshape);}
}else if(walk_mode){if(event.keyCode==37){left_key_up=false;moveleft=false;render(Fshape);} if(event.keyCode==39){right_key_up=false;moveright=false;render(Fshape);}	
if(event.keyCode==38){up_key_up=false;moveup=false;render(Fshape);} if(event.keyCode==40){down_key_up=false;movedown=false;render(Fshape);}
//if(event.keyCode==86){viewpoint_up=false;movedown=false;}
};//if(event.keyCode==86){}else{mentiontextures=false; render(Fshape);}
}

wireframes_key=false; wireframes_key_up=false; statusbar_key=false; statusbar_key_up=false; walkmode_key=false; walkmode_key_up=false;
examinemode_key=false; examinemode_key_up=false; left_key=false; left_key_up=false; right_key=false; right_key_up=false;
up_key=false; up_key_up=false; down_key=false; down_key_up=false; viewpoint_key=false; viewpoint_key_up=false;
collision_key=false; collision_key_up=false;

// *******************************************************************************************
//iPad / iPhone accelerometer
can_x=Number(String(document.getElementById("x3dsection").style.left).substr(0,String(document.getElementById("x3dsection").style.left).indexOf("px")));
can_y=Number(String(document.getElementById("x3dsection").style.top).substr(0,String(document.getElementById("x3dsection").style.top).indexOf("px")));
our_w=Number(String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("px")));	
our_h=Number(String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("px")));	
cl_x=our_w/2-100; cl_y=our_h/2-50;	
if(!walk_mode && render_permission){
orientationchange=1;
function detectIPadOrientation(){
if(orientation==90){orientationchange=0;}else if(orientation==-90){orientationchange=1;}}
window.onorientationchange = detectIPadOrientation; ax=ay=az=0;bacx=bacy=bacz=0;scot=0;
window.addEventListener("devicemotion", function(event){
if(orientationchange==1){ax+=event.accelerationIncludingGravity.x; ay+=event.accelerationIncludingGravity.y; az+=event.accelerationIncludingGravity.z;}
else if(orientationchange==0){ax-=event.accelerationIncludingGravity.x; ay-=event.accelerationIncludingGravity.y; az-=event.accelerationIncludingGravity.z;}
if(event.accelerationIncludingGravity.z>-5){zoomin=false;zoomout=true;}
else if(event.accelerationIncludingGravity.z<-7 && event.accelerationIncludingGravity.z>-9){zoomout=false;zoomin=true;}else{zoomin=false;zoomout=false;}
if(Math.abs(event.accelerationIncludingGravity.x)>1){if(ax<bacx){if(scot==0){change_camera();};scot++;}}else{scot=0;}
/*if(Math.abs(event.accelerationIncludingGravity.x)>1){if(ax<bacx){zoomin=false;zoomout=true;}else{zoomout=false;zoomin=true;}}else{zoomin=false;zoomout=false;}
if(Math.abs(event.accelerationIncludingGravity.y)>1){if(ay<bacy){if(scot==0){change_camera();};scot++;}}else{scot=0;}*/
bacx=ax;bacy=ay;bacz=az;}, true);}else if(walk_mode && render_permission){
orientationchange=1;
function detectIPadOrientation(){
if(orientation==90){orientationchange=0;}else if(orientation==-90){orientationchange=1;}}
window.onorientationchange = detectIPadOrientation; ax2=ay2=az2=0;bacx2=bacy2=bacz2=0;scot2=0;
window.addEventListener("devicemotion", function(event){
if(orientationchange==1){ax2+=event.accelerationIncludingGravity.x; ay2+=event.accelerationIncludingGravity.y; az2+=event.accelerationIncludingGravity.z;}
else if(orientationchange==0){ax2-=event.accelerationIncludingGravity.x; ay2-=event.accelerationIncludingGravity.y; az2-=event.accelerationIncludingGravity.z;}
if(event.accelerationIncludingGravity.z>-5){moveup=false;movedown=true;}
else if(event.accelerationIncludingGravity.z<-7 && event.accelerationIncludingGravity.z>-9){movedown=false;moveleft=false;moveright=false;moveup=true;}else{moveup=false;moveleft=false;moveright=false;movedown=false;}
if(Math.abs(event.accelerationIncludingGravity.y)>1){if(ay2<bacy2){moveright=false;movedown=false;moveup=false;moveleft=true;}else{moveleft=false;movedown=false;moveup=false;moveright=true;}}else{moveleft=false;moveright=false;}
if(Math.abs(event.accelerationIncludingGravity.x)>1){if(ax2<bacx2){if(scot2==0){change_camera();};scot2++;}}else{scot2=0;}
bacx2=ax2;bacy2=ay2;bacz2=az2;}, true);}

// *******************************************************************************************
//iPad / iPhone gestures
function gesture(){
can_x=Number(String(document.getElementById("x3dsection").style.left).substr(0,String(document.getElementById("x3dsection").style.left).indexOf("px")));
can_y=Number(String(document.getElementById("x3dsection").style.top).substr(0,String(document.getElementById("x3dsection").style.top).indexOf("px")));
our_w=Number(String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("px")));	
our_h=Number(String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("px")));	
cl_x=our_w/2-100; cl_y=our_h/2-50;	
if(document.getElementById("x3dsection").wireframes=="false"){ document.getElementById("x3dsection").wireframes="true";
mode_str="<b>wireframes</b> mode<br>enabled"; camera_yaw=camera_pitch=camera_roll=0; camera_x=camera_y=camera_z=0;
document.getElementById("des_mode").innerHTML="<section id='t1' width="+200+"px style='position:absolute; left:"+cl_x+"px; top:"+cl_y+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+200+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px;-moz-user-select: none; -khtml-user-select: none; user-select: none; -webkit-user-select: none;'>"+mode_str+"</section>"; do_mode_screen();
}else if(document.getElementById("x3dsection").wireframes=="true"){ document.getElementById("x3dsection").wireframes="false";
mode_str="<b>wireframes</b> mode<br>disabled"; camera_yaw=camera_pitch=camera_roll=0; camera_x=camera_y=camera_z=0;
document.getElementById("des_mode").innerHTML="<section id='t1' width="+200+"px style='position:absolute; left:"+cl_x+"px; top:"+cl_y+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+200+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px; -moz-user-select: none; -khtml-user-select: none; user-select: none; -webkit-user-select: none'>"+mode_str+"</section>"; do_mode_screen();}
canvas=document.getElementById("canvas"); context=canvas.getContext("2d");
context.clearRect(0,0,newcanvas.width,newcanvas.height);
context.strokeStyle="rgba("+c1+","+c2+","+c3+",1)"; context.lineJoin="round"; transformMatrix=""; render(Fshape);}
//end of hotkeys

// *******************************************************************************************
//links, anchors
function CreateAABBFromVertices_local2(Vertices,mode,ikk){ var vMin=vMax=[];
can_x=Number(String(document.getElementById("x3dsection").style.left).substr(0,String(document.getElementById("x3dsection").style.left).indexOf("px")));
can_y=Number(String(document.getElementById("x3dsection").style.top).substr(0,String(document.getElementById("x3dsection").style.top).indexOf("px")));
can_w=Number(String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("px")));
can_h=Number(String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("px")));
vMax[0]=vMa0=parseInt(Vertices[0][0]);vMax[1]=vMa1=parseInt(Vertices[0][1]);
vMin[0]=vMi0=parseInt(Vertices[0][0]);vMin[1]=vMi1=parseInt(Vertices[0][1]);
for(var e=0;e<Vertices.length;e++) { vMax[0]=vMa0; vMax[1]=vMa1; vMin[0]=vMi0; vMin[1]=vMi1; 
vMin[0]=Math.min(vMi0,parseInt(Vertices[e][0])); vMi0=vMin[0]; vMax[0]=Math.max(vMa0,parseInt(Vertices[e][0])); vMa0=vMax[0];
vMin[1]=Math.min(vMi1,parseInt(Vertices[e][1])); vMi1=vMin[1]; vMax[1]=Math.max(vMa1,parseInt(Vertices[e][1])); vMa1=vMax[1];}
vMa0s=vMa0; vMa1s=vMa1; vMi0s=vMi0; vMi1s=vMi1; E={}; E.width=(vMa0s-vMi0s)/2; E.height=(vMa1s-vMi1s)/2; E.x=vMi0s+E.width; E.y=vMi1s+E.height;
if(ecx>E.x+can_x-E.width && ecx<(E.x+can_x+E.width) && ecy>E.y+can_y-E.height && ecy<(E.y+can_y+E.height)){
document.getElementById("canvas").style.cursor="pointer";
if(mode=="move"){
over_me=function(des){
//do_actions(0);
if(des!=""){
can_x=Number(String(document.getElementById("x3dsection").style.left).substr(0,String(document.getElementById("x3dsection").style.left).indexOf("px")));
can_y=Number(String(document.getElementById("x3dsection").style.top).substr(0,String(document.getElementById("x3dsection").style.top).indexOf("px")));
our_w=Number(String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("px")));	
our_h=Number(String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("px")));
if(des_perm){des_perm=false; st_l=String(des).length*10; //cl_x=mouse_x-can_x+10; cl_y=mouse_y-can_y+10; 
document.getElementById("des_wnd").innerHTML="<section id='t1' width="+our_w+"px style='position:absolute; left:"+mouse_xx+"px; top:"+mouse_yy+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+st_l+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px;-moz-user-select: none; -khtml-user-select: none; user-select: none; -webkit-user-select: none'>"+des+"</section>"; v=0;
showit=function(){des_perm2=false;		
v++; document.getElementById("des_wnd").style.opacity=0.02*v; if(v==50){des_perm2=true;clearInterval(iddd);}}
if(des_perm2){iddd=setInterval("showit()",20);}}}}; 
pd=""; if(String(objanchorarraynames[ikk][2])=="undefined"){pd="";}else{pd=objanchorarraynames[ikk][2];};over_me(pd);	
}else if(mode=="down"){//clearInterval(iddd);
over_me3=function(ul,ut){if(ut=="_blank"){window.open(ul);}else if(ut=="_self"){window.location=ul;}}
if(objanchorarraynames[ikk][3]=="'target=_blank'" || objanchorarraynames[ikk][3]=="target=_blank"){tb="_blank";}else{tb="_self";} 
urll=String(objanchorarraynames[ikk][1]);
if(urll.indexOf("javascript:")!=-1){
window[String(urll.substring(11,urll.indexOf("(")))](String(urll.substring(urll.indexOf("(")+1,urll.lastIndexOf(")"))));
}else{over_me3(urll,tb);}}
}else{document.getElementById("canvas").style.cursor="default";
document.getElementById("des_wnd").style.opacity=0;document.getElementById("des_wnd").innerHTML="";}};

// *******************************************************************************************
//mouse rotation
/*
curTheta=curPhi=0;
m_y=0; m_x=0; des_perm=true;
function boardDown(event) {
//Fshape.Fside=down_sides;
can_x=Number(String(document.getElementById("x3dsection").style.left).substr(0,String(document.getElementById("x3dsection").style.left).indexOf("px")));
can_y=Number(String(document.getElementById("x3dsection").style.top).substr(0,String(document.getElementById("x3dsection").style.top).indexOf("px")));
can_w=Number(String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("px")));
can_h=Number(String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("px")));
if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
if(event.touches.length==1){
event.preventDefault(); // the default behaviour is scrolling	
var touch = event.touches[0];
prevX=(can_w/2)-(touch.pageX-can_x); 
prevY=(can_h/2)-(touch.pageY-can_y);	
}}else{
prevX=(can_w/2)-(event.clientX-can_x);
prevY=(can_h/2)-(event.clientY-can_y);
}prevY=-prevY;
doRotate=true;}

function getURL(){window.location=AABB[1];}

function boardMove(event) {

brows=navigator.userAgent.toLowerCase();if(brows.indexOf("opera")!=-1 && anchors==true){

if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
if(event.touches.length==1){
event.preventDefault(); // the default behaviour is scrolling	
var touch = event.touches[0];
mouse_x=(can_w/2)-(touch.pageX-can_x); 
mouse_y=(can_h/2)-(touch.pageY-can_y);		
}}else{
mouse_x=(can_w/2)-(event.clientX-can_x);
mouse_y=(can_h/2)-(event.clientY-can_y);}
minx=AABB[0].x-(AABB[0].width);
maxx=AABB[0].x+(AABB[0].width);
miny=AABB[0].y-(AABB[0].height);
maxy=AABB[0].y+(AABB[0].height);
if(-mouse_x<minx || -mouse_x>maxx || -mouse_y<miny || -mouse_y>maxy){
document.getElementById("canvas").style.cursor="default";

document.getElementById("des_wnd").innerHTML="";

v=0;		
showit2=function(){
des_perm=false;		
v++; document.getElementById("des_wnd").style.opacity=1-(0.02*v);
if(v==50){des_perm=true;clearInterval(iddd);}}

if(des_perm2){
var iddd=setInterval("showit2()",20);}

//}

elem = document.getElementById("canvas");
removeEvent(elem, "mousedown", getURL);
	
}else{
document.getElementById("canvas").style.cursor="pointer";
elem = document.getElementById("canvas");
addEvent(elem, "mousedown", getURL);

//if(des_perm){des_perm=false;
st_l=String(AABB[2]).length*10;
document.getElementById("des_wnd").innerHTML="<section id='t1' width="+st_l+"px style='position:absolute; left:"+(event.clientX-can_x+5)+"px; top:"+(event.clientY-can_y+5)+"px; color:whitesmoke; font-family:Arial; text-align:center; width:"+st_l+"px; background-color:rgba(0,0,0,0.6); padding: 5px 5px 5px 5px; border-radius:6px; -moz-border-radius:6px; -webkit-border-radius:6px;'>"+AABB[2]+"</section>";
v=0;
showit=function(){
des_perm2=false;		
v++; document.getElementById("des_wnd").style.opacity=0.02*v;
if(v==50){des_perm2=true;clearInterval(iddd);}}

if(des_perm){
var iddd=setInterval("showit()",20);
}
//}

}

}else{mouse_x=event.clientX; mouse_y=event.clientY;}
locX=prevX;locY=prevY;
if(doRotate){
if((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {		
if(event.touches.length==1){
event.preventDefault();//the default behaviour is scrolling	
var touch = event.touches[0];
prevX=(can_w/2)-(touch.pageX-can_x);prevY=(can_h/2)-(touch.pageY-can_y);}}else{	
prevX=(can_w/2)-(event.clientX-can_x);prevY=(can_h/2)-(event.clientY-can_y);}
prevY=-prevY;curTheta=(prevX-locX);curPhi=(prevY-locY);m_y=curTheta;m_x=curPhi;}
if(doRotate==true){transformMatrix=""; if(how_many_objects>1){
if(!walk_mode){
translate(-shiftx,-shifty,-shiftz-camera_dist);
cameraX(-shiftpitch);cameraY(-shiftyaw);cameraZ(-shiftroll);
translate(0,0,camera_dist);
render(Fshape,"calculate");
transformMatrix="";
translate(nav_speed*(delta_cam_x),-camera_y,nav_speed*(delta_cam_z));
render(Fshape,"calculate");
transformMatrix="";
rotateXY(m_x,m_y);
render(Fshape,"calculate");
transformMatrix="";
translate(-nav_speed*(delta_cam_x),camera_y,-nav_speed*(delta_cam_z));
render(Fshape,"calculate");
transformMatrix="";
translate(0,0,-camera_dist);
cameraX(shiftpitch);cameraY(shiftyaw);cameraZ(shiftroll);;
translate(shiftx,shifty,shiftz+camera_dist);}else{
//walk_mode
camera_y=camera_z=camera_x=0;camera_roll=0;
if(delta_pitch>60){
delta_pitch=60;camera_pitch=0;camera_yaw=-m_y/5;delta_yaw-=m_y/5;render(Fshape);	
}else if(delta_pitch<-60){
delta_pitch=-60;camera_pitch=0;camera_yaw=-m_y/5;delta_yaw-=m_y/5;render(Fshape);	
}else{
camera_yaw=-m_y/5; delta_yaw-=m_y/5;render(Fshape);}}}else{
if(!walk_mode){
transformMatrix="";
translate(-camera_x,-camera_y,-camera_z);
cameraY(-camera_yaw);
translate(nav_speed*(delta_cam_x),-camera_y,nav_speed*(delta_cam_z));
render(Fshape,"calculate");
transformMatrix="";
rotateX(m_x);
render(Fshape,"calculate");
transformMatrix="";
rotateY(m_y);
render(Fshape,"calculate");
transformMatrix="";
translate(-nav_speed*(delta_cam_x),camera_y,-nav_speed*(delta_cam_z));
render(Fshape,"calculate");
transformMatrix="";
cameraY(camera_yaw);
translate(camera_x,camera_y,camera_z);
}else{
act_mouse=true;
camera_y=camera_z=camera_x=0;
camera_roll=0;camera_pitch=-m_x/5;delta_pitch-=m_x/5;
if(delta_pitch>60){
delta_pitch=60;camera_pitch=0;camera_yaw=-m_y/5;delta_yaw-=m_y/5;render(Fshape);	
}else if(delta_pitch<-60){
delta_pitch=-60;camera_pitch=0;camera_yaw=-m_y/5;delta_yaw-=m_y/5;render(Fshape);	
}else{camera_yaw=-m_y/5;delta_yaw-=m_y/5;render(Fshape);}}}}
if(doRotate==false){transformMatrix="";}
camera_x=camera_y=camera_z=0;camera_yaw=camera_pitch=camera_roll=0; render(Fshape);}

function boardUp(event) {doRotate=false; camera_x=camera_y=camera_z=0; camera_yaw=camera_pitch=camera_roll=0; render(Fshape);}	
function addEvent(obj,type,fn){if(obj.addEventListener){
obj.addEventListener(type,fn,true);}else if(obj.attachEvent) { obj.attachEvent( "on"+type, fn );}else{obj["on"+type] = fn;}}
function removeEvent(obj,type,fn){obj.removeEventListener(type,fn,true);}
*/
curTheta=curPhi=0;
m_y=0; m_x=0; des_perm=true;
function boardDown(event) {

can_x=Number(String(document.getElementById("x3dsection").style.left).substr(0,String(document.getElementById("x3dsection").style.left).indexOf("px")));
can_y=Number(String(document.getElementById("x3dsection").style.top).substr(0,String(document.getElementById("x3dsection").style.top).indexOf("px")));
can_w=Number(String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("px")));
can_h=Number(String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("px")));

//mouse_x=(can_w/2)-(event.clientX-can_x); mouse_y=(can_h/2)-(event.clientY-can_y);
mouse_xx=(event.clientX-can_x)+5; mouse_yy=(event.clientY-can_y)+5; ecx=event.clientX; ecy=event.clientY;

if(objanchorarraynames.length!=0){for(ik=0; ik<objanchorarraynames.length; ik++){CreateAABBFromVertices_local2(objanchorarraynames[ik][4],"down",ik);}}

if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
if(event.touches.length==1){event.preventDefault(); var touch = event.touches[0];
prevX=(can_w/2)-(touch.pageX-can_x); prevY=(can_h/2)-(touch.pageY-can_y);}}else{
prevX=(can_w/2)-(event.clientX-can_x); prevY=(can_h/2)-(event.clientY-can_y);}prevY=-prevY;doRotate=true;

function addEvent(obj,type,fn){if(obj.addEventListener){
obj.addEventListener(type,fn,true);}else if(obj.attachEvent) { obj.attachEvent( "on"+type, fn );}else{obj["on"+type] = fn;}}
addEvent(document.getElementById("canvas"), "mousemove", boardMove);
addEvent(document.getElementById("navigationring_cover"), "mousemove", boardMove);
addEvent(document.getElementById("canvas"), "touchmove", boardMove);
addEvent(document.getElementById("navigationring_cover"), "touchmove", boardMove);
}


//function getURL(){window.location=AABB[1];}
kug=0;
function boardMove(event) {

can_x=Number(String(document.getElementById("x3dsection").style.left).substr(0,String(document.getElementById("x3dsection").style.left).indexOf("px")));
can_y=Number(String(document.getElementById("x3dsection").style.top).substr(0,String(document.getElementById("x3dsection").style.top).indexOf("px")));
can_w=Number(String(document.getElementById("x3dsection").style.width).substr(0,String(document.getElementById("x3dsection").style.width).indexOf("px")));
can_h=Number(String(document.getElementById("x3dsection").style.height).substr(0,String(document.getElementById("x3dsection").style.height).indexOf("px")));
		
mouse_x=(can_w/2)-(event.clientX-can_x); mouse_y=(can_h/2)-(event.clientY-can_y);
mouse_xx=(event.clientX-can_x)+5; mouse_yy=(event.clientY-can_y)+5; ecx=event.clientX; ecy=event.clientY;

if(objanchorarraynames.length!=0){for(ik=0; ik<objanchorarraynames.length; ik++){CreateAABBFromVertices_local2(objanchorarraynames[ik][4],"move",ik);}}

if(anchors==true){

if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
if(event.touches.length==1){event.preventDefault(); var touch = event.touches[0];
mouse_x=(can_w/2)-(touch.pageX-can_x); mouse_y=(can_h/2)-(touch.pageY-can_y);}}else{
mouse_x=(can_w/2)-(event.clientX-can_x); mouse_y=(can_h/2)-(event.clientY-can_y);}

}else{mouse_x=event.clientX; mouse_y=event.clientY;}

locX=prevX;locY=prevY;
if(doRotate){
//if(motiontextures=="false"){dotextures=false;}
mentiontextures=true;

if((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {		
if(event.touches.length==1){
event.preventDefault();//the default behaviour is scrolling	
var touch = event.touches[0];
prevX=(can_w/2)-(touch.pageX-can_x);prevY=(can_h/2)-(touch.pageY-can_y);}}else{
prevX=(can_w/2)-(event.clientX-can_x);prevY=(can_h/2)-(event.clientY-can_y);
}
prevY=-prevY;curTheta=(prevX-locX);curPhi=(prevY-locY);m_y=curTheta;m_x=curPhi;}

camera_yaw=-parseInt(m_y); 
delta_yaw-=parseInt(m_y);
//render(Fshape);

if(doRotate==true){transformMatrix=""; if(how_many_objects>1){
if(!walk_mode){
translate(-shiftx,-shifty,-shiftz-camera_dist);
cameraX(-shiftpitch);cameraY(-shiftyaw);cameraZ(-shiftroll);
translate(0,0.7,camera_dist);
render(Fshape,"calculate");
transformMatrix="";
translate(nav_speed*(delta_cam_x),-camera_y,nav_speed*(delta_cam_z));
render(Fshape,"calculate");
transformMatrix="";
rotateXY(m_x,m_y);
render(Fshape,"calculate");
transformMatrix="";
translate(-nav_speed*(delta_cam_x),camera_y,-nav_speed*(delta_cam_z));
render(Fshape,"calculate");
transformMatrix="";
translate(0,0.7,-camera_dist);
cameraX(shiftpitch);cameraY(shiftyaw);cameraZ(shiftroll);;
translate(shiftx,shifty,shiftz+camera_dist);}else{

camera_y=camera_z=camera_x=0;camera_roll=0;camera_pitch=delta_pitch;	
	//camera_yaw=delta_yaw;

//if(navigator.userAgent.toLowerCase().indexOf("safari")!=-1){

if((prevX-locX)<0){kug+=5;}else{kug-=5;}
document.getElementById("navigationring").style.webkitTransform='rotate('+kug+'deg)';
document.getElementById("navigationring").style.MozTransform='rotate('+kug+'deg)';
document.getElementById("navigationring").style.OTransform='rotate('+kug+'deg)';
document.getElementById("navigationring").style.Transform='rotate('+kug+'deg)';
	
translate(-shiftx,-shifty,-shiftz-camera_dist);
cameraX(-shiftpitch);//cameraY(-shiftyaw);cameraZ(-shiftroll);
translate(0,0,camera_dist);
render(Fshape,"calculate");
transformMatrix="";
//translate(nav_speed*(delta_cam_x),-camera_y,nav_speed*(delta_cam_z));
render(Fshape,"calculate");
transformMatrix="";
rotateXY(0,m_y);
render(Fshape,"calculate");
transformMatrix="";
//translate(-nav_speed*(delta_cam_x),camera_y,-nav_speed*(delta_cam_z));
render(Fshape,"calculate");
transformMatrix="";
translate(0,0,-camera_dist);
cameraX(shiftpitch);//cameraY(shiftyaw);cameraZ(shiftroll);;
translate(shiftx,shifty,shiftz+camera_dist);

//camera_yaw=-parseInt(m_y); delta_yaw-=parseInt(m_y);
render(Fshape);
/*}else{

if(delta_pitch>60){
delta_pitch=60;camera_pitch=0;camera_yaw=-parseInt(m_y/5);delta_yaw-=parseInt(m_y/5);
}else if(delta_pitch<-60){
delta_pitch=-60;camera_pitch=0;camera_yaw=-parseInt(m_y/5);delta_yaw-=parseInt(m_y/5);	
}else{camera_yaw=-parseInt(m_y/5); delta_yaw-=parseInt(m_y/5);};
camera_yaw=-parseInt(m_y/5); delta_yaw-=parseInt(m_y/5);
render(Fshape);
	
}*/
}}}
//walk_mode


/*
camera_y=camera_z=camera_x=0;camera_roll=0;
if(delta_pitch>60){
delta_pitch=60;camera_pitch=0;camera_yaw=-parseInt(m_y/5);delta_yaw-=parseInt(m_y/5);
}else if(delta_pitch<-60){
delta_pitch=-60;camera_pitch=0;camera_yaw=-parseInt(m_y/5);delta_yaw-=parseInt(m_y/5);	
}else{camera_yaw=-parseInt(m_y/5); delta_yaw-=parseInt(m_y/5);};
camera_yaw=-parseInt(m_y); delta_yaw-=parseInt(m_y);
render(Fshape);}}else{
if(!walk_mode){
transformMatrix="";
translate(-camera_x,-camera_y,-camera_z);
cameraY(-camera_yaw);
translate(nav_speed*(delta_cam_x),-camera_y,nav_speed*(delta_cam_z));
render(Fshape,"calculate");
transformMatrix="";
rotateX(m_x);
render(Fshape,"calculate");
transformMatrix="";
rotateY(m_y);
render(Fshape,"calculate");
transformMatrix="";
translate(-nav_speed*(delta_cam_x),camera_y,-nav_speed*(delta_cam_z));
render(Fshape,"calculate");
transformMatrix="";
cameraY(camera_yaw);
translate(camera_x,camera_y,camera_z);
}else{
act_mouse=true;
camera_y=camera_z=camera_x=0;
camera_roll=0;camera_pitch=-m_x/5;delta_pitch-=m_x/5;
if(delta_pitch>60){
delta_pitch=60;camera_pitch=0;camera_yaw=-m_y/5;delta_yaw-=parseInt(m_y/5);	
}else if(delta_pitch<-60){
delta_pitch=-60;camera_pitch=0;camera_yaw=-m_y/5;delta_yaw-=parseInt(m_y/5);
}else{camera_yaw=-m_y/5;delta_yaw-=m_y/5;};render(Fshape);}}}
if(doRotate==false){transformMatrix="";}//document.getElementById("x3dsection").wireframes="false";
//camera_x=camera_y=camera_z=0;camera_yaw=camera_pitch=camera_roll=0; 
//render(Fshape);
*/
}

function boardUp(event) {
mentiontextures=false;doRotate=false; camera_x=camera_y=camera_z=0; camera_yaw=camera_pitch=camera_roll=0; 
removeEvent(document.getElementById("canvas"), "mousemove", boardMove);
removeEvent(document.getElementById("navigationring_cover"), "mousemove", boardMove);
removeEvent(document.getElementById("stamp"), "mousemove", boardMove);
removeEvent(document.getElementById("navigationring"), "mousemove", boardMove);

removeEvent(document.getElementById("canvas"), "touchmove", boardMove); 
removeEvent(document.getElementById("navigationring_cover"), "touchmove", boardMove); 
mentiontextures=false;
render(Fshape);}
	
function addEvent(obj,type,fn){if(obj.addEventListener){
obj.addEventListener(type,fn,true);}else if(obj.attachEvent) { obj.attachEvent( "on"+type, fn );}else{obj["on"+type] = fn;}}
function removeEvent(obj,type,fn){obj.removeEventListener(type,fn,true);}

function do_actions(v){
brows=navigator.userAgent.toLowerCase();
if(!anchors){elem = document.getElementById("canvas");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
elem = document.getElementById("widget");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
elem=document.getElementById("des_mode");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
elem=document.getElementById("stamp");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
elem=document.getElementById("navigationring_cover");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
elem=document.getElementById("navigationring");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
}else if(anchors==true){if(v!=0){
elem = document.getElementById("canvas");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
elem=document.getElementById("des_wnd");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
elem=document.getElementById("stamp");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
addEvent(elem, "mouseout", boardUp);
elem=document.getElementById("navigationring_cover");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
elem=document.getElementById("navigationring");
addEvent(elem, "mousedown", boardDown); //addEvent(elem, "mousemove", boardMove); 
addEvent(elem, "mouseup", boardUp); //addEvent(elem, "mouseout", boardUp);
addEvent(elem, "mouseout", boardUp);
}else{
//elem = document.getElementById("canvas");
removeEvent(elem, "mousedown", boardDown); removeEvent(elem, "mousemove", boardMove); removeEvent(elem, "mouseup", boardUp);removeEvent(elem, "mouseout", boardUp);	
elem=document.getElementById("des_wnd");
removeEvent(elem, "mousedown", boardDown); removeEvent(elem, "mousemove", boardMove); removeEvent(elem, "mouseup", boardUp);removeEvent(elem, "mouseout", boardUp);
}};if(!anchors){
//Apple iPhone iPod iPad Touch API events
elem = document.getElementById("canvas");
addEvent(elem, "touchstart", boardDown); addEvent(elem, "touchend", boardUp); addEvent(elem, "gesturestart", gesture);
elem=document.getElementById("stamp");
addEvent(elem, "touchstart", boardDown);
addEvent(elem, "touchend", boardUp);
elem=document.getElementById("navigationring_cover");
addEvent(elem, "touchstart", boardDown);
addEvent(elem, "touchend", boardUp);
elem=document.getElementById("navigationring");
addEvent(elem, "touchstart", boardDown);
addEvent(elem, "touchend", boardUp);
}else if(anchors==true){if(v!=0){
elem = document.getElementById("canvas");
addEvent(elem, "touchstart", boardDown); addEvent(elem, "touchmove", boardMove); addEvent(elem, "touchend", boardUp); addEvent(elem, "gesturestart", gesture);}}
//addEvent(elem, "touchcancel", boardUp);
elem = window;
addEvent(elem, "keydown", hotkeys_down); addEvent(elem, "keyup", hotkeys_up);}
loading_waiting=function(){if(render_permission){clearInterval(onenter); if(!anchors){do_actions();}else{do_actions(1);}}}; 
onenter = setInterval("loading_waiting()",1);
}//end of xml
}//end of X3Daily :-)
