Beispiel #1
0
Value*
my_file_in_cf(Value** arg_list, int count)
{
	// myFileIn "filename" [quiet:true]

	// pick up arguments
	check_arg_count_with_keys(myFileIn, 1, count);
	two_typed_value_locals(ReadonlyTextFileStream* file, Value* result);
	Value* quiet = key_arg_or_default(quiet, &true_value);
	type_check(quiet, Boolean, _T("myFileIn quiet:"));

	// open a fileStream instance on the file
	vl.file = new ReadonlyTextFileStream();
	vl.file = vl.file->open(arg_list[0]->to_string());
	if (vl.file == (CharStream*)&undefined)
		throw RuntimeError (_T("fileIn cannot open file: "), arg_list[0]);

	// pass it to the stream-based fileIn utility function
	try
	{
		vl.result = file_in(vl.file, (quiet == &true_value));
	}
	catch (...)
	{
		// catch any errors and close the temp filestream
		vl.file->close();
		throw;
	}

	// pop value locals & return fileIn result
	return_value(vl.result);
}
Beispiel #2
0
Value*
clearScreen_cf(Value** arg_list, int count)
{
	check_arg_count_with_keys(clearScreen, 1, count);
	Box2			rect	= arg_list[0]->to_box2();
	GraphicsWindow	*gw		= MAXScript_interface->GetActiveViewExp().getGW();
	
	if (MaxSDK::Graphics::IsRetainedModeEnabled() && gw->querySupport(GW_SPT_NUM_LIGHTS) == 0)
	{
		return &undefined;
	}

	gw->clearScreen(&rect, key_arg_or_default(useBkg, &false_value)->to_bool());
	return &ok;
}
Value* ExportCalMesh_cf(Value** arg_list, int count)
{	
	char*	Filefullpathfilename		;
	char*	Skeletonfullpathfilename	;
	int		MaxNumOfBones				;
	float	WeightThreshold				;
	int		bUseLODCreation				;
	int		bUseSpringsystem			;
	INode*	MeshNode					;
  bool bUseAxisGL=false;


  // Cedric Pinson, now we can export in gl coordinates
	check_arg_count_with_keys(ExportCalMesh, 7, count);
	Value* transform= key_arg_or_default(transform, &false_value);
	type_check(transform, Boolean, "[The axisGL argument of ExportCalMesh should be a boolean that is true if you want to export in openGL axis]");

  type_check(arg_list[0], String		, "[The first argument of ExportCalMesh should be a string that is a full path name of the file to export]");
	type_check(arg_list[1], String		, "[The 2nd argument of ExportCalMesh should be a string that is the fullpath name of the skeleton file]");
	type_check(arg_list[2], MAXNode		, "[The 3rd argument of ExportCalMesh should be an mesh node that is the mesh to be exported]");
	type_check(arg_list[3], Integer		, "[The 3rd argument of ExportCalMesh should be an integer that is the maximum number of bones per vertex]");
	type_check(arg_list[4], Float		, "[The 4th argument of ExportCalMesh should be a float that is the weight threshold]");
	type_check(arg_list[5], Boolean		, "[The 5th argument of ExportCalMesh should be a boolean that is true if you want LOD creation]");
	type_check(arg_list[6], Boolean		, "[The 6th argument of ExportCalMesh should be a boolean that is true if you want to use spring system]");
	
	try
	{
		Filefullpathfilename		= arg_list[0]->to_string();
		Skeletonfullpathfilename	= arg_list[1]->to_string();
		MeshNode					= arg_list[2]->to_node();
		MaxNumOfBones				= arg_list[3]->to_int();
		WeightThreshold				= arg_list[4]->to_float();
		bUseLODCreation				= arg_list[5]->to_bool();
		bUseSpringsystem			= arg_list[6]->to_bool();
    bUseAxisGL       = (transform->to_bool() != 0);


		if (! strcmp(Filefullpathfilename,"")) return new Integer(1);
		if (! strcmp(Skeletonfullpathfilename,"")) return new Integer(2);

		//Does skeleton file exist ? 
		FILE* _stream;
		_stream = fopen(Skeletonfullpathfilename,"r");
		if (! _stream)return new Integer(3); //Error code number 3
		fclose(_stream);

		if ((MaxNumOfBones <= 0))return new Integer (4);

		if (WeightThreshold < 0.f) return new Integer (5);  

		if (! MeshNode) return new Integer (6); //Null pointer

		//Check if it is a mesh ?
		Object *obj = MeshNode->EvalWorldState(GetCOREInterface()->GetTime()).obj;
		if (! obj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0))) return new Integer (7); //Not a Mesh
				
		//Create the parameter structure to be sent to the function ExportMeshFromMaxscriptCall
		MeshMaxscriptExportParams	param ( MeshNode, Skeletonfullpathfilename,	MaxNumOfBones, WeightThreshold,bUseLODCreation,bUseSpringsystem);

    theExporter.SetAxisGL(bUseAxisGL); // set axis wanted
    if ( CMaxMeshExport::ExportMeshFromMaxscriptCall(Filefullpathfilename, param) ) {
      // reset to default
      theExporter.SetAxisGL(false);
			return new Integer(0);
    }
		
    theExporter.SetAxisGL(false);
		return new Integer(-1);
	}


	catch(...)
	{	
    theExporter.SetAxisGL(false);

		//MessageBox(NULL,"Exception catched in ExportCalMesh C++ function","Error",MB_OK);
		return new Integer(-2);
	}
}
Value* ExportCalSkel_cf(Value** arg_list, int count)
{	
	int			i;
	INodeTab	tabnode;
	char*		fullpathfilename;
	int			ArraySize		;
	bool		bShowUI			;
  bool bUseAxisGL=false; 

  // Cedric Pinson, now we can export in gl coordinates
	check_arg_count_with_keys(ExportCalSkel, 3, count);
	Value* transform= key_arg_or_default(transform, &false_value);
	type_check(transform, Boolean, "[The axisGL argument of ExportCalSkel should be a boolean that is true if you want to export in openGL axis]");

	type_check(arg_list[0], String, "[The first argument of ExportCalSkel should be a string that is a full path name of the file to export]");
	type_check(arg_list[1], Array , "[The 2nd argument of ExportCalSkel should be an array of nodes]");
	type_check(arg_list[2], Boolean,"[The 3rd argument of ExportCalSkel should be a boolean that tells if you want to use the UI or not to select nodes of skeleton]");
	
	try
	{
		fullpathfilename	= arg_list[0]->to_string();
    bUseAxisGL       = (transform->to_bool() != 0);

		//Get Array
		Array* BonesArray	= static_cast<Array*>(arg_list[1]);
		ArraySize			= BonesArray->size;	

		bShowUI				= !!(arg_list[2]->to_bool());

		if (! strcmp(fullpathfilename,"")) return new Integer (1);
		if (! ArraySize)		return new Integer (2);
 
		for (i=0;i<ArraySize;i++)
		{
			if (BonesArray->data[i]->is_kind_of(class_tag(MAXNode)) )
			{
				INode* _node	= 	BonesArray->data[i]->to_node();
				if (! _node)return new Integer (3);

				tabnode.Append(1,&_node);
			}
		}

    theExporter.SetAxisGL(bUseAxisGL);


		//Call the exporter from Maxscript
    if (CMaxSkeletonExport::ExportSkeletonFromMaxscriptCall(fullpathfilename,tabnode, bShowUI) ) {
      // reset axis gl
      theExporter.SetAxisGL(false);
			return new Integer (0);
    }
    theExporter.SetAxisGL(false);
		return new Integer (-1);
	}
	catch(...)
	{	
    theExporter.SetAxisGL(false);

		//MessageBox(NULL,"Exception catched in ExportCalSkel C++ function","Error",MB_OK);
		return new Integer (-2);
	}
}
Beispiel #5
0
Value*
mouse_track_cf(Value** arg_list, int count)
{
	// mouseTrack [on:node|#any] [prompt:"msg"] [snap:#2D|#3D] [trackCallback:fn|#(fn,arg)]

	// set up value local array to hold mouse tracker command mode Value*'s
	Value** vavl;
	value_local_array(vavl, sizeof(tmvl) / sizeof(Value*));
	tmvl* vl = (tmvl*)vavl;
	// show any prompt
	Value*	pv = key_arg(prompt);
	const TCHAR*	prompt = NULL;
	if  (pv != &unsupplied)
	{
		prompt = pv->to_string();
		mprintf(_T("%s "), prompt);
		mflush();
	}
	// setup snap
	Value* sv = key_arg_or_default(snap, n_2D);
	if (sv != n_2D && sv != n_3D)
		throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_BAD_SNAP_MODE), sv);
	// setup track callback fn
	Value* tcb = NULL;
	Value* tcbarg = NULL;
	Value *tcbv = key_arg(trackCallback);
	if (tcbv != &unsupplied)
	{
		if (is_array(tcbv))  // an array,  #(fn, arg), dig out fn & arg
		{
			Array* tcba = (Array*)tcbv;
			if (tcba->size != 2)
				throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_BAD_MOVE_CALLBACK_ARGS), tcbv);
			tcb = tcba->data[0];
			if (!is_function(tcb))
				throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_BAD_MOVE_CALLBACK_ARGS), tcb);
			tcbarg = tcba->data[1];
		}
		else  // just the fn
		{
			tcb = tcbv;
			if (!is_function(tcb))
				throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_BAD_MOVE_CALLBACK_ARGS), tcbv);
		}
	}

	// pickup any node to track on
	vl->node_val = key_arg(on);

	NodeTab& nodeTab = theTrackMouseCommandMode.proc.nodeTab;
	nodeTab.SetCount(0);
	if( vl->node_val->_is_collection() ) { //Multiple nodes specified
		Value* args[2] = { NULL, (Value*)&nodeTab };
		node_map m = { NULL, collect_nodes, args, 2 };
		vl->node_val->map(m);
	}
	else if( vl->node_val != &unsupplied ) { //Single node specified
		INode* node = vl->node_val->to_node();
		nodeTab.Append( 1, &node );
	}
	for( int i=(nodeTab.Count()-1); i>=0; i--)
		if( nodeTab[i]==NULL ) nodeTab.Delete(i,1); //Delete null nodes

	// set up pickpoint options, enter trackmouse command mode & wait for it to signal completion
	end_track_mouse = FALSE;
	theTrackMouseCommandMode.proc.vl = vl;
	theTrackMouseCommandMode.proc.snap_mode = sv;
	theTrackMouseCommandMode.proc.track_callback = tcb;
	theTrackMouseCommandMode.proc.track_callback_arg = tcbarg;
	theTrackMouseCommandMode.proc.start_track();
	//Changed from Set to Push to prevent an exception when the maxscript code changes the command mode
	//Similar to fix done to MouseTool.cpp - line 661
	MAXScript_interface->PushCommandMode(&theTrackMouseCommandMode);

	// process windows messages until point picked or canceled or keyboard message
    MSG wmsg;
    while (GetMessage(&wmsg, NULL, 0,0))
	{		
		if (wmsg.message == WM_KEYUP && (TCHAR)wmsg.wParam == VK_ESCAPE)
			end_track_mouse = TRUE;
		else if (wmsg.message == WM_KEYUP || wmsg.message == WM_KEYDOWN)
			continue;
		else if (wmsg.message != WM_RBUTTONUP)  // ignore rmousebuttonup's - they mess focus
			MAXScript_interface->TranslateAndDispatchMAXMessage(wmsg);

		if (end_track_mouse)
			break;
	}
	if (!end_track_mouse)
	{
		// we came out of message loop because of a quit, repost the quit and throw a SignalException
		theTrackMouseCommandMode.proc.end_track();
		MAXScript_interface->DeleteMode(&theTrackMouseCommandMode);
		throw SignalException();
	}

	// pickup result value & dismiss input modes
	theTrackMouseCommandMode.proc.end_track();
	MAXScript_interface->DeleteMode(&theTrackMouseCommandMode);
	Value* result = vl->result;
	pop_value_local_array(vavl);
	return_protected(result);
}
Value* ExportCalAnim_cf(Value** arg_list, int count)
{	
	int i								;
	char*	Filefullpathfilename		;
	char*	Skeletonfullpathfilename	;
	Array*	BonesArray					;
	int		StartFrame					;
	int		EndFrame					;
	int		FrameOffset					;
	int		FrameRate					;
  bool   bUseAxisGL=false;

  // Cedric Pinson, now we can export in gl coordinates
	check_arg_count_with_keys(ExportCalAnim, 7, count);
	Value* transform= key_arg_or_default(transform, &false_value);
	type_check(transform, Boolean, "[The axisGL argument of ExportCalAnim should be a boolean that is true if you want to export in openGL axis]");

	type_check(arg_list[0], String	, "[The first argument of ExportCalAnim should be a string that is a full path name of the file to export]");
	type_check(arg_list[1], String	, "[The 2nd argument of ExportCalAnim should be a string that is the fullpath name of the skeleton file]");
	type_check(arg_list[2], Array	, "[The 3rd argument of ExportCalAnim should be an array of nodes to get anim from]");
	type_check(arg_list[3], Integer	, "[The 4th argument of ExportCalAnim should be an integer that is the start frame number]");
	type_check(arg_list[4], Integer	, "[The 5th argument of ExportCalAnim should be an integer that is the end frame number]");
	type_check(arg_list[5], Integer , "[The 6th argument of ExportCalAnim should be an integer that is the frame offset]");
	type_check(arg_list[6], Integer , "[The 7th argument of ExportCalAnim should be an integer that is the framerate]");
	
	try
	{
  bool   bUseAxisGL=false;

  // Cedric Pinson, now we can export in gl coordinates
	check_arg_count_with_keys(ExportCalAnim, 7, count);
	Value* transform= key_arg_or_default(transform, &false_value);
	type_check(transform, Boolean, "[The axisGL argument of ExportCalAnim should be a boolean that is true if you want to export in openGL axis]");
		Filefullpathfilename		= arg_list[0]->to_string();
		Skeletonfullpathfilename	= arg_list[1]->to_string();
		BonesArray					= static_cast<Array*>(arg_list[2]);
		StartFrame					= arg_list[3]->to_int();
		EndFrame					= arg_list[4]->to_int();
		FrameOffset					= arg_list[5]->to_int();
		FrameRate					= arg_list[6]->to_int();

		if (! strcmp(Filefullpathfilename,""))return new Integer(1);

		if (! strcmp(Skeletonfullpathfilename,"")) return new Integer(2);

		//Does skeleton file exist ?
		FILE* _stream;
		_stream = fopen(Skeletonfullpathfilename,"r");
		if (! _stream)return new Integer(3); //Error code number 3
		fclose(_stream);

		//Get the elements of the bones array
		int ArraySize;
    bUseAxisGL       = (transform->to_bool() != 0);

		ArraySize = BonesArray->size;

		if (! ArraySize) return new Integer(4);
		
		if (StartFrame < 0)	return new Integer(5);

		if (EndFrame < 0)return new Integer(6);

		if (StartFrame > EndFrame ) return new Integer(7);

		if (FrameOffset < 0) return new Integer(8);

		if (FrameRate < 0) return new Integer(9);

		INodeTab	tabnode;
		for (i=0;i<ArraySize;i++)
		{
			if (BonesArray->data[i]->is_kind_of(class_tag(MAXNode)) )
			{
				INode* _node	= 	BonesArray->data[i]->to_node();
				if (! _node)return new Integer(10);
				tabnode.Append(1,&_node);
			}
		}		
		
		AnimExportParams param(Skeletonfullpathfilename, tabnode, StartFrame, EndFrame, FrameOffset, FrameRate);

    theExporter.SetAxisGL(bUseAxisGL); // set axis wanted
    if (CMaxAnimationExport::ExportAnimationFromMaxscriptCall(Filefullpathfilename, &param)) {
      //reset to default
      theExporter.SetAxisGL(false);
			return new Integer(0);
    }


    theExporter.SetAxisGL(false);
		return new Integer(-1);
	}


	catch(...)
	{	
    theExporter.SetAxisGL(false);
		//MessageBox(NULL,"Exception catched in ExportCalAnim C++ function","Error",MB_OK);
		return new Integer(-2);
	}
}