var private file ;
var private i = 1, ele[3], uv[2][2];
var private temp, suf_flag = OFF, atr_flag = OFF;

Bunkai(GetArg( 0 ), ele );
model_dir = ele[0];

if( MACHINE == "WINDOWS" )
	Child( model_dir+"exec_bin "+model_dir+"agcv_mdl.bin 8000 8100" );
if( atoi(Modelrc("Input_left")) != 0 )
	InputMode( MOUSE_LEFT, MOUSE_RIGHT );
else
	InputMode( MOUSE_RIGHT, MOUSE_LEFT );
MakeButton();
StatusInit();
if( buttondisp_flag == OFF )
	ButtonArea( 0 );
else
	ButtonArea(BUTTONAREA);
SetZoom( -zoomsize );
SetGrid( mesh_grid, mouse_grid );
PersAngle(pers_deg);
DefaultPers();
ControlEvent( _InputVertex );
AttrEvent( _AttrEvent );
ObjEvent( _ObjEvent );
CanCloseEvent( QuitModel );

while ( GetArg( i ) != "" )
{
	file = GetArg( i );
	if( ( substr( file, 1 ) == "-" ) | ( substr( file, 1 ) == "/" ) )
	{
		temp = toupper(substr( file, ((-1)*(!file)+1)));
		if( temp == "V" )
			housendisp_flag = ON;
	}
	else if ( toupper(substr( file, -4 )) == ".ATR" )
	{
		AttrReadFile( file );
		if( access( file ) == TRUE )
		{
			UpdateAttribute();
			atr_flag = ON;
		}
	}
	else
	{
		file = MakeFile( file, "suf" );
		if( access( file ) == TRUE )
		{
			ReadFile( file );
			file = substr( file, !file-4 ) + ".atr" ;
			if ( access( file ) )
				AttrReadFile( file );
			SelectAll( FALSE );
			suf_flag = ON;
			atr_flag = ON;
		}
		else
		{
			Warning();
			Message( file+"偑尒偮偐傝傑偣傫" );
		}
	}
	i++ ;
}
if( atr_flag == OFF )
{
	AttrAppend( default_atrname, default_atrcode );
	AttrFile( 0, default_atrfile );
	if( EXPERT != TRUE )
	{
		AttrMap( 0, TRUE );
		AttrMapFile( 0, MAPPINGFILE );
		uv[0] = {0,0};
		uv[1] = {MAPWIND-1, MAPWIND-1};
		SetAttrMapWind( 0, uv[0], uv[1] );
		uv[0] = {0,0};
		uv[1] = {UVmax,UVmax};
		SetAttrMapSize( 0, uv[0], uv[1] );
	}
}

if( suf_flag == OFF )
{
	ObjAppend( default_objname, default_filename );
	UpdateObject();
}

if( housendisp_flag == ON )
	VisibleVector( vecvisible_len );
if( tendisp_flag == ON )
	VisibleVertex( 1 );
if( houkoudisp_flag == ON )
	VisiblePolyVector( houkouvisible_len );
DrawFrontOnly( uradisp_flag );
DrawInvisible( drawinvisible_flag );
UpdateAll();
Polygon();

function main()
{
	var	key;
	while ( TRUE )
	{
		if( WaitEvent())
			CallKeyEvent(" ");
		else if( KeyCode() == 0 )
		{
			if( ( ShiftStat() & 1 ) == 1 )
			{
				cur = Cursor();
				TrimCursor( fix_vertex, MouseWindow());
				Cursor( cur );
			}
		}
		else
		{
			cur = Cursor();
			CallKeyEvent();
		}
	}
}
