//************************************************************
//  MEMCO INTERACTIVE ATMOSPHERE (MIA)
//  MiaScript access module
//  MiaScript - MIA internal scripting language for scene 
//  manipulation
//  N O T I C E
//  THIS MODULE IS FREE FOR USE AND EDUCATION
//************************************************************


isMacOS=false;

ttFlat = 3;
ttRound = 0;
ttPlane = 1;
ttPlanar=2;
ttPlanarVX=5;
ttPlanarVY=12;  
ttCylinderV=4;
ttCylinderHX=6;
ttCubix=7;
ttRugHX=8;
ttRugHY=9;
ttRugVX=10;
ttRugVY=11;
ttPanoramic=13;
ttAutoFit=14;
ttCube=15;


var UnitName="@NoUnitObject";
var EnableAnimations=true;
var EnableNavigation=true;
var miaObject=0;
var IsThreadingMode=false;
var commandValue='';
var commandDone=true;
var MapCleaner=0;
var serverName="";

var SW_HIDE=0;var SW_SHOWNORMAL=1;var SW_NORMAL=1;var SW_SHOWMINIMIZED=2;var SW_SHOWMAXIMIZED=3;var SW_MAXIMIZE=3;var SW_SHOWNOACTIVATE=4;var SW_SHOW=5;var SW_MINIMIZE=6;var SW_SHOWMINNOACTIVE=7;var SW_SHOWNA=8;var SW_RESTORE=9;var SW_SHOWDEFAULT=10;var SW_FORCEMINIMIZE=11;var SW_MAX=11;
VK_LBUTTON        =0x01;VK_RBUTTON        =0x02;
VK_CANCEL         =0x03;
VK_MBUTTON        =0x04;    
VK_BACK           =0x08;
VK_TAB            =0x09;
VK_CLEAR          =0x0C;
VK_RETURN         =0x0D;
VK_SHIFT          =0x10;
VK_CONTROL        =0x11;
VK_MENU           =0x12;
VK_PAUSE          =0x13;
VK_CAPITAL        =0x14;
VK_ESCAPE         =0x1B;
VK_CONVERT        =0x1C;
VK_NONCONVERT     =0x1D;
VK_ACCEPT         =0x1E;
VK_MODECHANGE     =0x1F;
VK_SPACE          =0x20;
VK_PRIOR          =0x21;
VK_NEXT           =0x22;
VK_END            =0x23;
VK_HOME           =0x24;
VK_LEFT           =0x25;
VK_UP             =0x26;
VK_RIGHT          =0x27;
VK_DOWN           =0x28;
VK_SELECT         =0x29;
VK_PRINT          =0x2A;
VK_EXECUTE        =0x2B;
VK_SNAPSHOT       =0x2C;
VK_INSERT         =0x2D;
VK_DELETE         =0x2E;
VK_HELP           =0x2F;
VK_SLEEP          =0x5F;
VK_NUMPAD0        =0x60;
VK_NUMPAD1        =0x61;
VK_NUMPAD2        =0x62;
VK_NUMPAD3        =0x63;
VK_NUMPAD4        =0x64;
VK_NUMPAD5        =0x65;
VK_NUMPAD6        =0x66;
VK_NUMPAD7        =0x67;
VK_NUMPAD8        =0x68;
VK_NUMPAD9        =0x69;
VK_MULTIPLY       =0x6A;
VK_ADD            =0x6B;
VK_SEPARATOR      =0x6C;
VK_SUBTRACT       =0x6D;
VK_DECIMAL        =0x6E;
VK_DIVIDE         =0x6F;
VK_F1             =0x70;
VK_F2             =0x71;
VK_F3             =0x72;
VK_F4             =0x73;
VK_F5             =0x74;
VK_F6             =0x75;
VK_F7             =0x76;
VK_F8             =0x77;
VK_F9             =0x78;
VK_F10            =0x79;
VK_F11            =0x7A;
VK_F12            =0x7B;
VK_F13            =0x7C;
VK_F14            =0x7D;
VK_F15            =0x7E;
VK_F16            =0x7F;
VK_F17            =0x80;
VK_F18            =0x81;
VK_F19            =0x82;
VK_F20            =0x83;
VK_F21            =0x84;
VK_F22            =0x85;
VK_F23            =0x86;
VK_F24            =0x87;

VK_NUMLOCK        =0x90;
VK_SCROLL         =0x91;
VK_LSHIFT         =0xA0;
VK_RSHIFT         =0xA1;
VK_LCONTROL       =0xA2;
VK_RCONTROL       =0xA3;
VK_LMENU          =0xA4;
VK_RMENU          =0xA5;

VK_VOLUME_MUTE         =0xAD;
VK_VOLUME_DOWN         =0xAE;
VK_VOLUME_UP           =0xAF;
VK_MEDIA_NEXT_TRACK    =0xB0;
VK_MEDIA_PREV_TRACK    =0xB1;
VK_MEDIA_STOP          =0xB2;
VK_MEDIA_PLAY_PAUSE    =0xB3;


function command(str){  
	miaObject.ExecuteCommand=str;
	return miaObject.LastResult;
}

function postcommand(str)
{  
	miaObject.PostCommand=str; 
}


function getHTMLLoc()
{
	var loc=window.parent.name.toString();	
	if (loc.indexOf("file:/")==-1) loc=document.location.href.toString();
	return loc;
}

function GetSize(object, size)
{
	if (isMacOS)
		return mac_GetSize(object,size);
	miaObject.GetObjectSize(object,size,UnitName);

	var k=miaObject.LastResult.toString();
	lastResult = k;
	var i=k.indexOf(",");
	if (i>=0)
	{
		k=k.substring(0,i)+"."+k.substring(i+1);     
	}

	return parseFloat(k);
}

function GetIntSize(object, size)
{
	miaObject.GetObjectSize(object,size,UnitName);
	var k=miaObject.LastResult.toString();
	lastResult = k;
	var i=k.indexOf(",");
	if (i>=0)
	{
		k=k.substring(0,i)+"."+k.substring(i+1);     
	}
	return parseInt(k);
}

function GetWidth(object)
{
	return GetSize(object,"Width");
}

function GetState(object)
{
	return GetSize(object,"state");
}

function SetState(object, state)
{
	command('setobjectstate name="'+object+'" state='+state);
}


function GetObjectPath(object)
{
	miaObject.GetObjectSize(object,"objectpath",UnitName);
	return miaObject.LastResult.toString();
}

function GetObjectName(object)
{
	miaObject.GetObjectSize(object,"objectname",UnitName);
	return miaObject.LastResult.toString();
}

function GetRootPath()
{
	miaObject.GetObjectSize("","rootpath",""); 
	return miaObject.LastResult.toString();
}

function GetTop(object)
{
	return GetSize(object,"top");
}

function GetBottom(object)
{
	return GetSize(object,"bottom");
}

function GetLeft(object)
{
	return GetSize(object,"left");
}

function GetRight(object)
{
	return GetSize(object,"right");
}

function GetFront(object)
{
	return GetSize(object,"front");
}

function GetBack(object)
{
	return GetSize(object,"back");
}

function GetMidX(object)
{
	return GetSize(object,"midx");
}

function GetMidY(object)
{
	return GetSize(object,"midy");
}


function GetMidZ(object)
{
	return GetSize(object,"midz");
}

function GetCentX(object)
{
	return GetSize(object,"ocentx");
}

function GetCentY(object)
{
	return GetSize(object,"ocenty");
}

function GetCentZ(object)
{
	return GetSize(object,"ocentz");
}

function GetHeight(object)
{
	var val=GetSize(object,"Height");
	return val;
}

function GetDepth(object)
{
	return GetSize(object,"Depth");
}

function AddBalance(ObjectName,BalName)
{
	command('AddBalance Name="'+ObjectName+'" BalName="'+BalName);
}


function SetBalanceX(ObjectName,BalName,top)
{
	command('SetBalance Name="'+ObjectName+'" AllowX=1 BalName="'+BalName+'" top='+top);
}


function SetBalanceY(ObjectName,BalName,top)
{
	command('SetBalance Name="'+ObjectName+'" AllowY=1 BalName="'+BalName+'" top='+top);
}


function SetBalanceZ(ObjectName,BalName,top)
{
	command('SetBalance Name="'+ObjectName+'" AllowZ=1 BalName="'+BalName+'" top='+top);
}


function SetBalance(ObjectName,BalName,top)
{
	command('SetBalance Name="'+ObjectName+'" AllowX=1 AllowY=1 AllowZ=1 BalName="'+BalName+'" top='+top);
}


function SetVisible(name,status)
{
	command('SetVisible name="'+name+'" RealTime='+status+' RenderTime='+status); 
}


function SetPolygonsVisible(name,status)
{
	command('SetTmpVisible name="'+name+'" RealTime='+status+' RenderTime='+status); 
}

function StdUnit()
{
	UnitName='UnitSize';
}

function GrowUnit()
{
	UnitName='@Grow';
}


var AngleYZ=0;
var AngleXZ=0;
var AngleZX=0;
var AngleZY=0;
var AngleXY=0;
var AngleYX=0;

function AnglesStr()
{
	return "   angleyz="+AngleYZ+" anglexz="+AngleXZ+" anglezx="+AngleZX;
}

function SetObjectWidthLeft(objectName, width, fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" name="'+objectName+'" SizeX='+width+' FixedPart="XRight" UnitName='+UnitName+' ScaleAll=0 AllowX=1 AllowY=0 AllowZ=0'+AnglesStr());
}


function SetObjectWidthMid(objectName, width, fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" name="'+objectName+'" SizeX='+width+' FixedPart="XMid" UnitName='+UnitName+' ScaleAll=0 AllowX=1 AllowY=0 AllowZ=0' + AnglesStr());
}

function SetObjectWidthRight(objectName, width,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" name="'+objectName+'" SizeX='+width+' FixedPart="XLeft" UnitName='+UnitName+' ScaleAll=0 AllowX=1 AllowY=0 AllowZ=0' + AnglesStr());
}


function SetObjectHeightBottom(objectName, height, fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" name="'+objectName+'" SizeZ='+height+' FixedPart="ZBottom" UnitName='+UnitName+' ScaleAll=0 AllowX=0 AllowY=0 AllowZ=1'+ AnglesStr());
}

function SetObjectHeightTop(objectName, height,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" name="'+objectName+'" SizeZ='+height+' FixedPart="ZTop" UnitName='+UnitName+' ScaleAll=0 AllowX=0 AllowY=0 AllowZ=1'+ AnglesStr());
}

function SetObjectHeightMid(objectName, height,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" name="'+objectName+'" SizeZ='+height+' FixedPart="ZMid" UnitName='+UnitName+' ScaleAll=0 AllowX=0 AllowY=0 AllowZ=1'+ AnglesStr());
}

function SetObjectDepthBack(objectName, depth,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" name="'+objectName+'" SizeY='+depth+' FixedPart="YBack" UnitName='+UnitName+' ScaleAll=0 AllowX=0 AllowY=1 AllowZ=0'+ AnglesStr());
}


function SetObjectDepthFront(objectName, depth,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" name="'+objectName+'" SizeY='+depth+' FixedPart="YFront" UnitName='+UnitName+' ScaleAll=0 AllowX=0 AllowY=1 AllowZ=0'+ AnglesStr());
}

function SetObjectDepthMid(objectName, depth,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" name="'+objectName+'" SizeY='+depth+' FixedPart="YMid" UnitName='+UnitName+' ScaleAll=0 AllowX=0 AllowY=1 AllowZ=0'+ AnglesStr());
}


SmoothLevel=0;
SmoothMaxX=0;
SmoothMaxY=0;
SmoothMaxZ=0;

function SetLinkWidthLeft(targetName,objectName, width,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" targetsize="'+targetName+'" name="'+objectName+'" SizeX='+width+' FixedPart="XRight" UnitName='+UnitName+' ScaleAll=0 AllowX=1 AllowY=0 AllowZ=0 Link=1 MaxX='+SmoothMaxX+' SmoothLevel='+SmoothLevel+ AnglesStr());
}

function SetLinkWidthMid(targetName,objectName, width,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" targetsize="'+targetName+'" name="'+objectName+'" SizeX='+width+' FixedPart="XMid" UnitName='+UnitName+' ScaleAll=0 AllowX=1 AllowY=0 AllowZ=0 Link=1 MaxX='+SmoothMaxX+' SmoothLevel='+SmoothLevel+ AnglesStr());
}


function SetLinkWidthRight(targetName,objectName, width,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" Link=1 targetsize="'+targetName+'" name="'+objectName+'" SizeX='+width+' FixedPart="XLeft" UnitName='+UnitName+' ScaleAll=0 AllowX=1 AllowY=0 AllowZ=0 MaxX='+SmoothMaxX+' SmoothLevel='+SmoothLevel+ AnglesStr());
}

function SetLinkHeightBottom(targetName,objectName, height,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" Link=1 targetsize="'+targetName+'" name="'+objectName+'" SizeZ='+height+' FixedPart="ZBottom" UnitName='+UnitName+' ScaleAll=0 AllowX=0 AllowY=0 AllowZ=1 MaxZ='+SmoothMaxZ+' SmoothLevel='+SmoothLevel+ AnglesStr());
}

function SetLinkHeightTop(targetName,objectName, height,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" Link=1 targetsize="'+targetName+'" name="'+objectName+'" SizeZ='+height+' FixedPart="ZTop" UnitName='+UnitName+' ScaleAll=0 AllowX=0 AllowY=0 AllowZ=1 MaxZ='+SmoothMaxZ+' SmoothLevel='+SmoothLevel+ AnglesStr());
}

function SetLinkDepthBack(targetName,objectName, height,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" Link=1 targetsize="'+targetName+'" name="'+objectName+'" SizeY='+height+' FixedPart="YBack" UnitName='+UnitName+' ScaleAll=0 AllowX=0 AllowY=1 AllowZ=0 MaxY='+SmoothMaxY+' SmoothLevel='+SmoothLevel+ AnglesStr());
}

function SetLinkDepthFront(targetName,objectName, height,fixedObject)
{
	command('ScaleToSize fixedObject="'+fixedObject+'" Link=1 targetsize="'+targetName+'" name="'+objectName+'" SizeY='+height+' FixedPart="YFront" UnitName='+UnitName+' ScaleAll=0 AllowX=0 AllowY=1 AllowZ=0 MaxY='+SmoothMaxY+' SmoothLevel='+SmoothLevel+ AnglesStr());
}

function MoveObject(Object, DX,DY,DZ)     
{
	command('Move name="'+Object+'" DX='+DX+' DY='+DY+' DZ='+DZ+
		' UnitName='+UnitName+' AllowX=1 AllowY=1 AllowZ=1'); 
}

function RotateObject(name,center,vx,vz)
{
	command('Rotate center="'+center+'" name="'+name+'" VX='+vx+' YZRotate=1 VY='+vz);
}


function RotateAroundAxes(name,center,anglex,angley,anglez)
{
	command('RotateMatrix center="'+center+'" name="'+name+'" anglex='+anglex+' angley='+angley+' anglez='+anglez);
}

function RotateAroundVector(name,center,angle,x,y,z)
{
	command('rotatematrixvector center="'+center+'" name="'+name+'" angle='+angle+' x='+x+' y='+y+' z='+z);
}


function RotateFCObject(name,center,vx,vz)
{                        
	if (GetObjectAttribute(name,"isCenterFixed")!="true")
	{    
		SetObjectAttribute(name,"isCenterFixed","true");
		RotateObject(name,center+" fixcenter",vx,vz);
	}
	else
		RotateObject(name,"fixx fixy fixz",vx,vz);
}

function RotateFCAroundAxes(name,center,anglex,angley,anglez)
{                        
	if (GetObjectAttribute(name,"isCenterFixed")!="true")
	{    
		SetObjectAttribute(name,"isCenterFixed","true");
		RotateAroundAxes(name,center+" fixcenter",anglex,angley,anglez);
	}
	else
		RotateAroundAxes(name,"fixx fixy fixz",anglex,angley,anglez);
}

function RotateFCAroundVector(name,center,angle,x,y,z)
{                        
	if (GetObjectAttribute(name,"isCenterFixed")!="true")
	{    
		SetObjectAttribute(name,"isCenterFixed","true");
		RotateAroundVector(name,center+" fixcenter",angle,x,y,z);
	}
	else
		RotateAroundVector(name,"fixx fixy fixz",angle,x,y,z);
}


function RotateFCObjectXZ(name,center,vx,vy)
{                        
	if (GetObjectAttribute(name,"isCenterFixed")!="true")
	{    
		SetObjectAttribute(name,"isCenterFixed","true");
		RotateObjectXZ(name,center+" fixcenter",vx,vy);
	}
	else
		RotateObjectXZ(name,"fixx fixy fixz",vx,vy);
}

function RotateObjectXZ(name,center,vx,vy)
{
	command('Rotate center="'+center+'" name="'+name+'" VX='+vy+' VY='+vx);
}

function MoveToFit(name,TargetName,FixedPart,OrientName)
{
	command('movefit Orient="'+OrientName+'" name="'+name+'" target='+TargetName+' fixedpart='+FixedPart);
}

function MoveTouch(ObjectName,TargetName,DX,DY,DZ)
{
	command('MoveTouch name="'+ObjectName+'"  targetname="'+TargetName+'" unitname=UnitSize DX='+DX+' DY='+DY+' DZ='+DZ);
}


function SetBottomPos(ObjectName, Pos)
{
	var m=GetBottom(ObjectName);
	MoveObject(ObjectName,0,0,Pos-m);
}

function SetTopPos(ObjectName, Pos)
{
	var m=GetTop(ObjectName);
	MoveObject(ObjectName,0,0,Pos-m);
}

function SetLeftPos(ObjectName, Pos)
{
	var m=GetLeft(ObjectName);
	MoveObject(ObjectName,Pos-m,0,0);
}

function SetRightPos(ObjectName, Pos)
{
	var m=GetRight(ObjectName);
	MoveObject(ObjectName,Pos-m,0,0);
}

function SetMidXPos(ObjectName, Pos)
{
	var m=GetMidX(ObjectName);
	MoveObject(ObjectName,Pos-m,0,0);
}

function SetMidYPos(ObjectName, Pos)
{
	var m=GetMidY(ObjectName);
	MoveObject(ObjectName,0,Pos-m,0);
}

function SetMidZPos(ObjectName, Pos)
{
	var m=GetMidZ(ObjectName);
	MoveObject(ObjectName,0,0,Pos-m);
}


function SetFrontPos(ObjectName, Pos)
{
	var m=GetFront(ObjectName);
	MoveObject(ObjectName,0,Pos-m,0);
}

function SetBackPos(ObjectName, Pos)
{
	var m=GetBack(ObjectName);
	MoveObject(ObjectName,0,Pos-m,0);
}


function SetCentXPos(ObjectName, Pos)
{
	var m=GetCentX(ObjectName);
	MoveObject(ObjectName,Pos-m,0,0);
}

function SetCentYPos(ObjectName, Pos)
{
	var m=GetCentY(ObjectName);
	MoveObject(ObjectName,0,Pos-m,0);
}

function SetCentZPos(ObjectName, Pos)
{
	var m=GetCentZ(ObjectName);
	MoveObject(ObjectName,0,0,Pos-m);
}

function RefreshPlanes()
{
	command("RefreshPlanes");
}

function RefreshObject(ObjectName)
{
	RefreshObjectPlanes(ObjectName);
	RefreshObjectLightning(ObjectName);
}

function RefreshObjectPlanes(objectname)
{
	command('refreshobjectplanes objectname="'+objectname+'" ');
}


function RefreshObjectLightning(objectname)
{
	command('refreshobjectligtning objectname="'+objectname+'" ');
}


function RefreshObjectSizes(objectname)
{
	command('refreshobjectsizes objectname="'+objectname+'" ');
}

function RefreshSizes()
{
	command("RefreshSizes");
}

function Preview()
{
	SetActions(1);
	command("Preview");
}

function FastPreview()
{
	command("FastPreview");
}

function Previewhq()
{
	command("Previewhq");
	SetActions(1);
}

function ClearMap(ObjectName)
{
	command("ClearTextureMap type="+MapCleaner+" name="+ObjectName);
}

function ClearSceneMap()
{
	command("ClearTextureMap type="+MapCleaner+" name=@All");
}

function SetTexture(ObjectName,TextureName,Level,ClMap)
{
	command('SetTexture name="'+ObjectName+'" texturename="'+TextureName+'" Level='+Level+' ClearMap='+ClMap);
}

function SetShadow(ObjectName,TextureName,Level,ClMap)
{
	command('SetShadow name="'+ObjectName+'" texturename="'+TextureName+'" Level='+Level+' ClearMap='+ClMap);
}

function SetMapping(ObjectName,Mapping,Tiling,ClMap)
{
	command('SetTexture name="'+ObjectName+'" Mapping="'+Mapping+'" Tiling='+Tiling+' ClearMap='+ClMap);
}


function SetShadow2(ObjectName,TextureName,Level,Mapping,ClMap)
{
	command('SetShadow name="'+ObjectName+'" Mapping="'+Mapping+'" texturename="'+TextureName+'" Level='+Level+' ClearMap='+ClMap);
}

function SetMaterial(ObjectName,BlinkLevel,BlinkFocus,Lightness)
{
	command('SetMaterial FlowR=0 FlowG=0 FlowB=0 name="'+ObjectName+'" BlinkLevel="'+BlinkLevel+'" BlinkFocus='+BlinkFocus+' Lightness='+Lightness);
}

function SetMaterial2(ObjectName,BlinkLevel,BlinkFocus,Lightness,FlowR,FlowG,FlowB)
{
	command('SetMaterial FlowR='+FlowR+' FlowG='+FlowG+' FlowB='+FlowB+' name="'+ObjectName+'" BlinkLevel="'+BlinkLevel+'" BlinkFocus='+BlinkFocus+' Lightness='+Lightness);
}

function SetAngles(ObjectName,RX,RY,RZ)
{
	command('SetAngles name="'+ObjectName+'" RX='+RX+' RY='+RY+' RZ='+RZ);
}

function SetColor(name,R,G,B)
{
	command("SetColor name="+name+" R="+R+" G="+G+" B="+B +" Style=0");
}                                             

function SetColorNT(name,R,G,B)
{
	command("SetColor name="+name+" R="+R+" G="+G+" B="+B +" Style=1");
}

function AddTrans(ObjectName,V)
{
	command("AddTrans name="+ObjectName+" Value="+V); 
}

function SetOpacity(ObjectName,V)
{
	command("SetTrans name="+ObjectName+" Value="+V); 
}

function AddColor(name,R,G,B)
{
	command("AddColor name="+name+" R="+R+" G="+G+" B="+B +" Style=0");
}


function AddColorNT(name,R,G,B)
{
	command("AddColor name="+name+" R="+R+" G="+G+" B="+B +" Style=1");
}


function SetVisMode()
{
	command("setloadmode mode=visible");
}

function LoadMIAScene(room)
{ 
	command('loadfile name="'+serverName+room+'"');
}

function LoadAutoScale(room)
{ 
	command('loadfileautoscale name="'+serverName+room+'"');
}

function GetLightX(L)
{
	return GetSize(L,"lightx");
}

function GetLightY(L)
{
	return GetSize(L,"lighty");
}

function GetLightZ(L)
{
	return GetSize(L,"lightz");
}

function SetLColor(L,R,G,B)
{
	command('SetLightColor index="'+L+'" R='+R+' G='+G+' B='+B);
}

function SetLightBr(L,brightness,secondary,rays,R,G,B)
{
	command('setbr index="'+L+'" brightness='+brightness+' secondary='+secondary+' rays='+rays+' r='+R+' g='+G+' b='+B);
}

function MoveLight(L,dx,dy,dz)
{
	command('movelight index="'+L+'" dx='+dx+' dy='+dy+' dz='+dz);
}

function SetLight(L,Int,Cont)
{
	command('SetLight index="'+L+'"  Intensity='+Int+' Contrast='+Cont);
}

function ActivateLight(L)
{
	command('SetLight index="'+L+'" active=2 intensity=-1 contrast=-1');
}

function DisableLight(L)
{
	command('SetLight index="'+L+'" active=1 intensity=-1 contrast=-1');
}

function ShowMsg(title,msg)
{
	command('ShowMessage title="'+title+'"  msg="'+msg+'"');
}

function HideMsg()
{
	command('HideMessage');
}

function HideImg()
{
	command('HideImages');
}

function NavigateCamera(name,steps,finalpreview)
{
	if (!EnableNavigation) return;
	if (!EnableAnimations)
		SetCamera(name);
	else
		command('navigatecamera name="'+name+'" steps='+steps+' finalpreview='+finalpreview);
}

function NavigateToObject(object,steps,level)
{
	AddCamera("@CurrentView");
	HideSelection();
	SelectObject(object);
	FitScene(level);
	HideSelection();
	AddCamera("@FitView");
	SetCamera("@CurrentView");
	NavigateCamera("@FitView",steps,0);
}

function FitObject(object,level)
{
  HideSelection();
  SelectObject(object);
  FitScene(level);
  HideSelection();
}

function SetCamera(name)
{
	command('setcamera name="'+name+'" ');
}

function ImportMIA(name)
{
	command('import name="'+serverName+name+'"');
}

var EnableZonesDublication=true;

function GenerateZone(objects,name,x,y,z,x1,y1,z1)
{
	if (!EnableZonesDublication)
		command('ClearZone zonename="'+name+'"');

	command('GenerateZone ObjectsList="'+objects+'" zonename="'+name+'" X='+x+' Y='+y+'  Z='+z+' X1='+x1+' Y1='+y1+'  Z1='+z1);
}

function GenerateFacetsZone(objects,name,x,y,z,x1,y1,z1)
{
	if (!EnableZonesDublication)
		command('ClearZone zonename="'+name+'"');

	command('GenerateFacetsZone ObjectsList="'+objects+'" zonename="'+name+'" X='+x+' Y='+y+'  Z='+z+' X1='+x1+' Y1='+y1+'  Z1='+z1);
}



function GenerateObjectZone(objects,name,zoneobject)
{
	if (!EnableZonesDublication)
		command('ClearZone zonename="'+name+'"');
	command('GenerateObjectZone ObjectsList="'+objects+'" zonename="'+name+'" zoneobject='+zoneobject);
}


function GenerateTexuredZone(objects,name,texName)
{
	if (!EnableZonesDublication)
		command('ClearZone zonename="'+name+'"');
	command('GenerateTexturedZone ObjectsList="'+objects+'" zonename="'+name+'" textureName="'+texName+'"');
}

function ClearZone(name)
{
	command('ClearZone zonename="'+name+'"');
}

function ClearZones()
{
	command('ClearZones');
}

function FullScreen()
{
	command('FullScreen');
}

function SetSelection(val)
{
	if (val==1)
		command('EnableSelection');
	else
		command('DisableSelection');
}

function WriteJpeg(name,scale)
{
	command('WriteJpeg scale='+scale+' name="'+name+'"');
}

function IsExists(name)
{
	return GetWidth(name)!=0;
}

function IsVisible(name)
{
	return GetSize(name,"visible")!=0;
}

function IsVisibleInFrame(name)
{
	return GetSize(name,"visiblenow")!=0;
}

function SetActions(val)
{
	if (val==0)
		command("disableactions");
	else
		command("enableactions");
}

function InstallDB(URL,Target,Msg)
{
	command('installdb url="'+URL+'" target="'+Target+'" msg="'+Msg+'"');
}


function BGInstallDB(URL,Target,Msg)
{
	command('bginstalldb url="'+URL+'" target="'+Target+'" msg="'+Msg+'"');
}

function IsActionDone()
{
	return GetSize("","action")==0;
}


function GetDBStatus()
{
	GetSize("","dbresult");
	return lastResult;
}

function UseThreadingMode()
{
	command("usethreadingmode");
}

function NoThreadingMode()
{
	command("nothreadingmode");
}

function SetTexScaling(factor)
{
	command("texturescaling factor="+factor+" ");
}

function Copy(inname,outname,outgrp)
{
	command('copy outgroup="'+outgrp+'"  objectname="'+inname+'" copyname="'+outname+'" ');
}

function Mirror(inname,inx,iny,inz)
{
	command('mirror objectname="'+inname+'" mirrorx="'+inx+'" mirrory="'+iny+'" mirrorz="'+inz+'"');
}

function AddToGroup(gname,objectname)
{
	command('addtogroup objectname="'+objectname+'" groupname="'+gname+'" ');
}

function ExecCommandList(name)
{
	command('runlist name="'+name+'"');
}  

function SaveFile(name)                                     
{
	command('savefile name="'+name+'"');
}

function CheckFile(room)
{
	return command('checkfile name="'+room+'"')=="1";
}

function LoadScene(room)
{
	SetActions(0);
	command('loadfile name="'+room+'"');
}

function SetZoomFactor(factor)
{
	command('setzoomfactor factor="'+factor+'"');
}


function GetComputerLevel()
{
	return GetSize("","ComputerLevel");
}

function EnableMenus(name,item)
{
	command('enablemenus name="'+name+'" item="'+item+'" enable=1');
}

/*

Выключает некторые элементы меню
*/


function DisableMenus(name,item)
{
	command('enablemenus name="'+name+'" item="'+item+'" enable=0');
}

/*
Не использовать. Только для совмести с пред. версиями
*/

function SetFastPreviewMode()
{
	command('fastpreviewmode');
}

/*
Только для режима без видеокарты, показ кадра с заданным уровнем антиалиаса
*/

function CPreview(level)
{
	command('custompreview level="'+level+'" ');
}

function ReplaceTexture(name,newname)
{
	command('replacetexture name="'+name+'" newname="'+newname+'" ');
}

function ReplaceObjectTexture(name,newname)
{
	command('replaceobjecttexture name="'+name+'" newname="'+newname+'" ');
}

function PredOn()
{
	command('setpredlighting value=1');
}


function PredOff()
{
	command('setpredlighting value=0');
}

function SetCameraLimits(name)
{
	command('setcamera limits=1 name="'+name+'" ');
}

function ReflOn()
{
	command('setrealtimereflections value=1');
}

function ReflOff()
{
	command('setrealtimereflections value=0');
}

function SetBkColor(R,G,B)
{
	command("SetBkColor R="+R+" G="+G+" B="+B);
}

function ConfigDF()
{
	command("ShowDFDialog");
}

function PerformPLA()
{
	command("PerformPLA");
}

function AutoPLA()
{
	if (!IsTurbo())
		TurboOn();
}

function RenderObject(name)
{
	command('renderobject name="'+name+'"');
}

function WalkOn()
{ 
	command('setwalkmode mode=1');
}

function WalkOff()
{
	command('setwalkmode mode=0');
}

function RealFullScreen(w,h)
{
	command("realfullscreen w="+w+" h="+h);
}


function Interlaced(on)
{
	command("interlaced on="+on);
}

function SelectColor(title,name)
{
	command('selectcolor title="'+title+'" name="'+name+'"');
}

function SelectColorNT(title,name)
{
	command('selectcolornt title="'+title+'" name="'+name+'"');
}                    

function SetSelectTextureDefaultPath(path)
{
	command('settextureselectdefault path="'+path+'"');
}

function SelectAndReplaceTextureEx(location,title,name,width,height)
{
	command('selectandreplacetexture location="'+location+'" title="'+title+'" name="'+name+'" width='+width+' height='+height);
}

function SelectAndReplaceTexture(location)
{
	command('selectandreplacetexture location="'+location+'" title="Select Material"');
}

function SelectTexture(location,title,name,width,height)
{
	command('selecttexture location="'+location+'" title="'+title+'" name="'+name+'" width='+width+' height='+height);
}

function FitScene(level)
{
	command("fitscene level="+level);
}

function ExpandVisGroup(x,y,z)
{
	command("expandvisgroup levelx="+x+" levely="+y+" levelz="+z);
}

function FindConnections(source,level)
{                                                         
	command('findconnections name="'+source+'" checklevel='+level);
}

function Unhideall()
{
	command("unhideall");
}

function SetConnectionsMode(details)
{
	command("setconnectionsmode detailed="+details);
}


function ModeSelectOn()
{
	command("modeselecton");
}

function ModeSelectOff()
{
	command("modeselectoff");
}


function SetDOF(distance,gradient,blur)
{
	command('setdepthoffield distance='+distance+' gradient='+gradient+' blur='+blur);
}

function ShowStereo(depth,blue_red)
{
	command('showstereo depth='+depth+' blurred='+blue_red);
}

function PlayVideo(name)
{
	command('playvideo name="'+name+'"');
}

function PlaySound(name,loop)
{
	command('playsound name="'+name+'" loop='+loop);
}

function StopAll()
{
	command("stopall");
}

function StopVideo()
{
	command("stopvideo");
}

function ShowMemoryStatus()
{
	command("showmemorystatus");
}

function SetLevelOfDetail(level)
{
	command('levelofdetail detail='+level);
}

function EnableCamLight()
{
	command("enablecamlight");
}

function DisableCamLight()
{
	command("disablecamlight");
}

function CallEvent(name,event)
{
	command('callevent name="'+name+'" event='+event);
}


function BlockEvent(name,event)
{
	command('blockevent name="'+name+'" event='+event);
}


function UnBlockEvent(name,event)
{
	command('unblockevent name="'+name+'" event='+event);
}


function MiaScriptExec(buffer)
{
	command('miascriptexec buf="'+buffer+'"');
}


function ThreadExec(buffer)
{
	var s=MiaScriptExecThread(buffer);
	ThreadRun(s.toInteger());
	return s.toInteger();
}

function ThreadInit(buffer)
{
	var s=MiaScriptExecThread(buffer);
	return s.toInteger();
}

function ThreadRun(id)
{
	command("threadrun id="+id);
}


function ThreadRunAll()
{
	command("threadrun id=-1");
}

function ThreadSuspend(ID)
{
	command('threadsuspend id='+ID); 
}


function ThreadSuspendPoint()
{
	command('threadsuspendposition'); 
}


function ThreadTerminate(ID)
{
	command('threadterminate id='+ID); 
}

function ThreadTerminateAll()
{
	command('threadterminate id=-1'); 
}


function ThreadTerminatePoint()
{
	command('threadterminateposition'); 
}

function ThreadResume(ID)
{
	command('threadresume id='+ID); 
}


function ThreadSuspendAll()
{
	command('threadsuspend id=-1'); 
}

function ThreadResumeAll()
{
	command('threadresume id=-1'); 
}

function MiaScriptExecThread(buffer)
{
	return command('miascriptexecthread buf="'+buffer+'"');
}


function MiaExecTimer(buffer,timeInterval)
{
	command('miascriptexectimer buf="'+buffer+'" timeinterval='+timeInterval);
}

function MiaStopTimer()
{
	command("miascriptstoptimer");
}

function SetCatalogName(name)
{
	command('setcatalogname name="'+name+'"');
}



function AnimDrawOff()
{
	command("animatedredraw mode=0");
}

function AnimDrawOn()
{
	command("animatedredraw mode=1");
}

function WebOn()
{
	command("webmodeon");
}


function WebOff()
{
	command("webmodeoff");
}

function ShowHint(message,backColor,frontColor,x,y,w,h, time)
{
	command('showhint time='+time+' message="'+message+'" webbgcolor='+backColor+' webtextcolor=' +frontColor+' x='+x+' y='+y+' w='+w+' h='+h);
}

function ShowImage(path,x,y,w,h,time)
{
	command('showimage time='+time+' image="'+path+'" x='+x+' y='+y+' w='+w+' h='+h);
}

function HideImage(path)
{
	ShowImage(path,-1,-1,-1,-1,0);
}

function ShowMenu(path,pathMouseOver,pathMouseDown,pathMouseMask,eventExection,x,y,w,h)
{
	command('showmenu imageevent="'+eventExection+'" imagemousemask="'+pathMouseMask+'"  imagemousedown="'+pathMouseDown+'" imagemouseover="'+pathMouseOver+'" image="'+path+'" x='+x+' y='+y+' w='+w+' h='+h);
}

function ShowFixedMessage(message,backColor,frontColor,x,y,w,h)
{
	command('showfixedmessage message="'+message+'" webbgcolor='+backColor+' webtextcolor=' +frontColor+' x='+x+' y='+y+' w='+w+' h='+h);
}

function SetFont(name,size,bold,italic,underline,esc)
{
	command('setfont name="'+name+'" size='+size+' bold='+bold+' italic='+italic+' underline='+underline+' esc='+esc);
}

function SetTextBorder(r,g,b,width)
{
	command('settextborder r='+r+' g='+g+' b='+b+' width='+width);
}

function Background2D()
{
	command("2dback");
}

function Foreground2D()
{
	command("2dfor");
}

function GetMouseX()
{
	return GetSize("","mouseX");
}


function GetMouseY()
{
	return GetSize("","mouseY");
}

function GetKeyState(keyCode)
{
	return GetSize(keyCode,"keystate");
}

function GetTickCount()
{
	return GetSize("","tickcount");
}

function Pause(ms)
{
	command("pause length="+ms);
}

function AddCamera(name)
{
	command('addcamera name="'+name+'" ');
}


function GetCurrentCameraPosX()
{
	return GetSize("","vpxpos");
}


function GetCurrentCameraPosY()
{
	return GetSize("","vpypos");
}


function GetCurrentCameraPosZ()
{
	return GetSize("","vpzpos");
}

function GetCurrentCameraPosCentX()
{
	return GetSize("","centx");
}

function GetCurrentCameraPosCentY()
{
	return GetSize("","centy");
}

function GetCurrentCameraPosCentZ()
{
	return GetSize("","centz");
}

function GetCurrentCameraPosAngleX()
{
	return GetSize("","anglex");
}

function GetCurrentCameraPosAngleY()
{
	return GetSize("","angley");
}

function SetCurrentCameraPos(x,y,z)
{
	command('setcamerapos x='+x+' y='+y+' z='+z);
}

function SetCurrentCameraFocus(focus)
{
	command('setcamerafocus focus='+focus);
}


function GetCurrentCameraFocus(focus)
{
	return GetSize("","camerafocus");
}


function MoveCurrentCamera(dx,dy,dz)
{
	command('movecamera dx='+dx+' dy='+dy+' dz='+dz);
}

function SetCurrentCameraAngles(x,y)
{
	command('setcameraangles x='+x+' y='+y);
}

function SetCurrentCameraWallTouchLimit(limit)
{
	command("setwalltouch limit="+limit);
}

function SetCurrentCameraStep(step)
{
	command("setcamerastep step="+step);
}

function SetCurrentCameraRotationStep(vx,vy)
{
	command("setcameravxvy vx="+vx+" vy="+vy);
}


function MoveCurrentCameraAngles(dx,dy)
{
	command('movecameraangles dx='+dx+' dy='+dy);
}

function MoveCamera(name,dx,dy,dz)
{
	AddCamera("@CurrentView");
	SetCamera(name);
	MoveCurrentCamera(dx,dy,dz);
	AddCamera(name);
	SetCamera("@CurrentView");
}

function SetCameraAngles(name,x,y)
{
	AddCamera("@CurrentView");
	SetCamera(name);
	SetCurrentCameraAngles(x,y);
	AddCamera(name);
	SetCamera("@CurrentView");
}

function MoveCameraAngles(name,dx,dy)
{
	AddCamera("@CurrentView");
	SetCamera(name);
	MoveCurrentCameraAngles(dx,dy);
	AddCamera(name);
	SetCamera("@CurrentView");
}


function SetObjectName(name,newname)
{
	command('setname objectname="'+name+'" newname="'+newname+'"'); 
}


function FlipNormals(name)
{
	command('flipnormals objectname="'+name+'"'); 
}

function SelectObject(name)
{
	command('selectobject name="'+name+'"'); 
}

function HideSelection()
{
	command('hideselection');
}

function SetVisibilityDistance(dist)
{
	command("visdistance distance="+dist);
}

function ViewCoefX(value)
{
	command("viewcoefx value="+value);
}

function ViewCoefY(value)
{
	command("viewcoefy value="+value);
}

function SetViewMode(mode)
{
	command("setview view="+mode);
}

function TextureLoadOn()
{
	command("textureloadon");
}

function TextureLoadOff()
{
	command("textureloadoff");
}

function ClearNamesCache()
{
	command("clearnamescache");
}


function PostTimeRenderOff()
{
	command("smoothrender mode=0");
}


function PostTimeRenderOn()
{
	command("smoothrender mode=1");
}

function RefreshScene()
{
	command("refreshscene");
}

function GetScreenWidth()
{
	return GetSize('','screenwidth');
}

function GetScreenHeight()
{
	return GetSize('','screenheight');
}

function SetVideoViewport(x,y,x1,y1)
{
	command('videoviewport x='+x+' y='+y+' x1='+x1+' y1='+y1);
}

function NormalViewport()
{
	SetVideoViewport(-1,-1,-1,-1);
}

function ClearScreen()
{
	command("clearscreen");
}


function VCFastLoadOn()
{
	command("vcfastloadingon");
}

function VCFastLoadOff()
{
	command("vcfastloadingoff");
}


function GetEvent(object,eventname)
{
	miaObject.GetObjectSize(object,eventname,"eventname");
	return miaObject.LastResult.toString();
}

function SetEvent(object,eventname,buf)
{
	command('setevent name="'+object+'" eventname="'+eventname+'" buf="'+buf+'"');
}

function AutoLimit()
{ 
	command('autolimit');
}


function RefreshTextureMapping(object)
{
	command('refreshtexturemapping name="'+object+'"');
}


function GetFreePhysicalRam()
{
	return GetSize("","freeram");
}


function GetMemoryLoad()
{
	return GetSize("","memoryload");
}

function GetVariable(varX)
{
	miaObject.GetObjectSize(varX,"variable",""); 
	return miaObject.LastResult.toString();
}

function SetVariable(varX,varValue)
{
	miaObject.GetObjectSize(varX,"setvariable",varValue); 
}


function GetObjectProperty(object,property)
{
	miaObject.GetObjectSize(object,property,"property");
	return miaObject.LastResult.toString();
}



function SetObjectProperty(object,property, propertyvalue)
{
	miaObject.GetObjectSize(object,property,"setproperty"+propertyvalue);
	return miaObject.LastResult.toString();
}

function SetObjectHint(object,hint)
{
	SetObjectProperty(object,"hint",hint);
}

function GetObjectHint(object,hint)
{
	return GetObjectProperty(object,"hint");
}

function GetObjectAttribute(object,attribute)
{
	miaObject.GetObjectSize(object,attribute,"attribute");
	return miaObject.LastResult.toString();
}
function SetObjectAttribute(object,attribute,attributevalue)
{
	miaObject.GetObjectSize(object,attribute,"setattribute"+attributevalue);
	return miaObject.LastResult.toString();
}

function GetFPS()
{
	return GetSize("","fps");
}


function GetObjectFromPoint(x,y)
{
	miaObject.GetObjectSize(x,y,"objectfrompoint");
	return miaObject.LastResult.toString();
}


function GetSubObjectFromPoint(x,y)
{
	miaObject.GetObjectSize(x,y,"subobjectfrompoint");
	return miaObject.LastResult.toString();
}

function GetObjectFromCursor()
{
	var x=miaObject.GetMouseX();
	var y=miaObject.GetMouseY();
	miaObject.GetObjectSize(x,y,"objectfrompoint");
	return miaObject.LastResult.toString();
}

function GetSubObjectFromCursor()
{
	var x=miaObject.GetMouseX();
	var y=miaObject.GetMouseY();
	miaObject.GetObjectSize(x,y,"subobjectfrompoint");
	return miaObject.LastResult.toString();
}


function SetMoveDirections(x,y,z)
{
	command("setmovedirections x="+x+" y="+y+" z="+z);
}


function SelectionEnableShow()
{
	command("enableselectionshow");
}


function SelectionDisableShow()
{
	command("disableselectionshow");
}


function ClearReflections(name)
{
	command('clearreflections name="'+name+'"');
}



function GetScreenX(X,Y,Z)
{
	var str="X="+X+" Y="+Y+" Z="+Z;
	miaObject.GetObjectSize(str,"","screenx");
	return miaObject.LastResult.toString();
}

function GetScreenY(X,Y,Z)
{
	var str="X="+X+" Y="+Y+" Z="+Z;
	miaObject.GetObjectSize(str,"","screeny");
	return miaObject.LastResult.toString();
}

function SetAnimFrameCheck(count)
{
	command("setanimationframecheck count="+count+" ");
}

function MoveCameraWithFixedCenter(dx,dy,dz)
{
	command('movecamerafixedcenter dx='+dx+' dy='+dy+' dz='+dz);
}

function MoveCameraCentralPoint(dx,dy,dz)
{
	command('movecameracentralpoint dx='+dx+' dy='+dy+' dz='+dz);
}

function Zoom(step)
{
	command('zoom step='+step);
}

function WalkForward(step)
{
	var ax=GetCurrentCameraPosAngleX();
	var ay=GetCurrentCameraPosAngleY();
	MoveCurrentCamera((-1)*step*System.sin(ax),step*System.cos(ax),0);
}


function WalkLeftRight(step)
{
	var ax=GetCurrentCameraPosAngleX()-3.14/2;
	var ay=GetCurrentCameraPosAngleY();
	MoveCurrentCamera((-1)*step*System.sin(ax),step*System.cos(ax),0);
}

function ResetLimits()
{
	command("resetlimit");
}


function CustomLimits(ain,aout,upy,downy)
{
	command('customlimit in='+ain+' out='+aout+' upy='+upy+' downy='+downy);
}


function TurboOn()
{
	command("turboon");
}

function TurboOff()
{
	command("turbooff");
}

function IsTurbo()
{
	return GetIntSize("","isturbo");
}

function SetCacheMode(name,value)
{
	command('setcachemode name="'+name+'" value='+value);
}

function ExcludeFromLightCache(name)
{
	SetCacheMode(name,2);
}

function IncludeInLightCache(name)
{
	SetCacheMode(name,1);
}


function ExcludeFromTurboCache(name)
{
	SetCacheMode(name,3);
}

function IncludeInTurboCache(name)
{
	SetCacheMode(name,1);
}


function SetVideoVolume(name,volume)
{
	command('setvideovolume name="'+name+'" volume='+volume);
}

function SetVideoVolumeStatus(name,status)
{
	command('setvideovolumestatus name="'+name+'" status='+status);
}

function StopSound()
{
	command('stopsound');
}

function GetVideoVolume(name)
{
	miaObject.GetObjectSize(name,"","volume");
	return miaObject.LastResult.toString();
}


function SetFixedCameraSpeed(speedMsec)
{
	command("setfixedcameraspeed speed="+speedMsec);
}


function Terminate()
{
	command("terminate");
}

function GetVideoCardLevel()
{
	return GetIntSize("","vclevel");
}


function VSyncOn()
{
	command("vsyncon");
}

function VSyncOff()
{
	command("vsyncoff");
}

function Idle()
{
	command("idle");
}


function GetLightProperty(light,property)
{
	miaObject.GetObjectSize(light,property,"lightproperty");
	return miaObject.LastResult.toString();
}


function SetLightProperty(light,property, propertyvalue)
{
	miaObject.GetObjectSize(light,property,"lightsetproperty"+propertyvalue);
	return miaObject.LastResult.toString();
}

function GetLastPressedKey()
{
	return GetIntSize("","lastkey");
}

function GetLayersCount()
{
	return GetIntSize("","layerscount");
}

function GetLayerProperty(layer,property)
{
	miaObject.GetObjectSize(layer,property,"layerproperty");
	return miaObject.LastResult.toString();
}

function SetLayerProperty(layer,property, propertyvalue)
{
	miaObject.GetObjectSize(layer,property,"layersetproperty"+propertyvalue);
	return miaObject.LastResult.toString();
}

function ApplyMatrix(object,matrix)
{
	var s=matrix.toString2();
	command('applymatrix name="'+object+'" matrix="'+s+'"');
}

function RecoverObject(object)
{
	command('recoverobject name="'+object+'"');
}

function BackupObject(object)
{
	command('backupobject name="'+object+'"');
}

function BlockMultiKey()
{
	command('blockmultikeyentries');
}

function UnblockMultiKey()
{
	command('unblockmultikeyentries');
}

function IsPointInside(name,x,y,z)
{
	miaObject.GetObjectSize(name,"x="+x+" y="+y+" z="+z,"ispointinside");
	var k=parseInt(miaObject.LastResult.toString());
	return k;
}

function IsPointInsideBox(name,x,y,z)
{
	var k=miaObject.GetObjectSize(name,"x="+x+" y="+y+" z="+z,"ispointinsidebox");
	var k=parseInt(miaObject.LastResult.toString());
	return k;
}

function EnvReflectionsCompute()
{
	command("envreflectionscompute");	
}

function EnvReflectionsRefresh(id)
{
	command("envreflectionsrefresh id="+id);	
}

function PauseEnvReflections()
{
	command("disableenvautogeneration");
}

function NextAnimationEnable()
{
	command("nextanimationenable");
}

function GetVertexCount(object)
{
	return GetObjectSizeInt(object,"vertex","getvertexcount");
}

function GetFaceCount(object)
{
	return GetObjectSizeInt(object,"vertex","gefacecount");
}


function GetVertexX(object,vertex)
{
	return GetObjectSizeFloat(object,vertex,"getvertexx");
}

function GetVertexY(object,vertex)
{
	return GetObjectSizeFloat(object,vertex,"getvertexy");
}

function GetVertexZ(object,vertex)
{
	return GetObjectSizeFloat(object,vertex,"getvertexz");
}

function GetVertexNormalA(object,vertex)
{
	return GetObjectSizeFloat(object,vertex,"getvertexa");
}

function GetVertexNormalB(object,vertex)
{
	return GetObjectSizeFloat(object,vertex,"getvertexb");
}

function GetVertexNormalC(object,vertex)
{
	return GetObjectSizeFloat(object,vertex,"getvertexc");
}

function SetVertexPos(name,vertex,x,y,z)
{
	miaObject.GetObjectSize(name,"ind="+vertex+" x="+x+" y="+y+" z="+z,"setvertexpos");  
}

function SetVertexX(name,vertex,x)
{
	miaObject.GetObjectSize(name,"ind="+vertex+" x="+x,"setvertexposx");  
}

function SetVertexY(name,vertex,y)
{
	miaObject.GetObjectSize(name,"ind="+vertex+" y="+y,"setvertexposy");  
}

function SetVertexZ(name,vertex,z)
{
	miaObject.GetObjectSize(name,"ind="+vertex+" z="+z,"setvertexposz");  
}

function SetGlobalAttribute(attribute,value)
{
	SetObjectAttribute("@global",attribute,value);
}

function GetGlobalAttribute(attribute)
{
	return GetObjectAttribute("@global",attribute);
}

function GetObjectSizeInt(object,size,UnitName)
{
	miaObject.GetObjectSize(object,size,UnitName);
	var k=parseInt(miaObject.LastResult.toString());
	return k;
}

function GetObjectSizeFloat(object,size,UnitName)
{
	miaObject.GetObjectSize(object,size,UnitName);
	var k=parseFloat(miaObject.LastResult.toString());
	return k;
}


function ModifySurface(object,functionName)
{
	command('modifyvertexes name="'+object+'" function="'+functionName+'" visible=0');
}

function ModifyVisiblePartOfSurface(object,functionName)
{
	command('modifyvertexes name="'+object+'" function="'+functionName+'" visible=1');
}

function SimulateKeyPress(code)
{
	command("keyop code="+code);
}

function WCameraForward()                    
{
	SimulateKeyPress(VK_UP);
}

function WCameraBackward()
{
	SimulateKeyPress(VK_DOWN);
}

function WCameraRotateLeft()
{
	SimulateKeyPress(VK_LEFT);
}

function WCameraRotateRight()
{
	SimulateKeyPress(VK_LEFT);
}                               

function WCameraUp()
{
	SimulateKeyPress(VK_PRIOR);
}

function WCameraDown()
{
	SimulateKeyPress(VK_NEXT);
}

function WCameraRight()
{
	SimulateKeyPress(VK_HOME);
}

function WCameraLeft()
{
	SimulateKeyPress(VK_END);
}

function LensFlareDepthOn()
{
	command("lensdepthon");
}

function LensFlareDepthOff()
{
	command("lensdepthoff");
}

function MaterialBlending2D()
{
	command("imageblendon");
}

function StandardBlending2D()
{
	command("imageblendoff");
}

function SelectImageFile()
{
	miaObject.GetObjectSize("","","selectfile");
}

function NavigateToObject2(object,steps,level,dx,dy,dz)
{
  AddCamera("@CurrentView");
  HideSelection();
  SelectObject(object);
  FitScene(level);
  HideSelection();
  MoveCurrentCamera(dx,dy,dz);
  AddCamera("@FitView");
  SetCamera("@CurrentView");
  if (steps==0)
   SetCamera("@FitView");
  else
  NavigateCamera("@FitView",steps,0);
}

function EnableDebugConsole()
{
 command("enabledebugconsole");
}

function DisableDebugConsole()
{
 command("disabledebugconsole");
}

function ShellExecute(file,params,show)
{
 command('shellexecute file="'+file+'" params="'+params+'" show='+show);
}

function GetCurrentCameraHorizAngle()
{
  return GetSize("","danglex");
}

function GetCurrentCameraVertAngle()
{
  return GetSize("","dangley");
}

function KeepCentralPosition(object)
{
 var x=GetCentX(object);
 var y=GetCentY(object);
 var z=GetCentZ(object);

 SetObjectAttribute(object,"@xCenterSave",x);
 SetObjectAttribute(object,"@yCenterSave",y);
 SetObjectAttribute(object,"@zCenterSave",z);
}

function RecoverCentralPosition(object)
{
 var x=GetObjectAttribute(object,"@xCenterSave");
 var y=GetObjectAttribute(object,"@yCenterSave");
 var z=GetObjectAttribute(object,"@zCenterSave");
 x=x.toFloat();
 y=y.toFloat();
 z=z.toFloat();
 RefreshObjectSizes(object);
 SetCentPos(object,x,y,z);
}

function SetCentPos(ObjectName, PosX,PosY,PosZ)
{
  var mX=GetCentX(ObjectName);
  var mY=GetCentY(ObjectName);
  var mZ=GetCentZ(ObjectName);
  MoveObject(ObjectName,PosX-mX,PosY-mY,PosZ-mZ);
}
