MStatus liqAttachPrefAttribute::doIt(const MArgList& args)
{
  MStatus status;
  MArgParser argParser(syntax(), args);

  MString tempStr;
  status = argParser.getObjects(objectNames);
  if (!status) 
  {
    MGlobal::displayError("error parsing object list");
    return MS::kFailure;
  }

  worldSpace = false;
  int flagIndex = args.flagIndex("ws", "worldSpace");
  if (flagIndex != MArgList::kInvalidArgIndex) 
    worldSpace = true;

  exportN = false;
  flagIndex = args.flagIndex("en", "exportN");
  if (flagIndex != MArgList::kInvalidArgIndex) 
    exportN = true;

  //printf(">> got %d objects to PREF !\n",objectNames.length() );

  return redoIt();
}
MStatus liqWriteArchive::doIt(const MArgList& args)
{
  MStatus status;
  MArgParser argParser(syntax(), args);

  MString tempStr;
  status = argParser.getCommandArgument(0, tempStr);
  if (!status) {
    MGlobal::displayError("error parsing object name argument");
    return MS::kFailure;
  }
  objectNames.append(tempStr);

  status = argParser.getCommandArgument(1, outputFilename);
  if (!status) {
    MGlobal::displayError("error parsing rib filename argument");
    return MS::kFailure;
  }

  outputRootTransform = false;
  int flagIndex = args.flagIndex("rt", "rootTransform");
  if (flagIndex != MArgList::kInvalidArgIndex) {
    outputRootTransform = true;
  }

  outputChildTransforms = true;
  flagIndex = args.flagIndex("ct", "childTransforms");
  if (flagIndex != MArgList::kInvalidArgIndex) {
    outputChildTransforms = true;
  }

  debug = false;
  flagIndex = args.flagIndex("d", "debug");
  if (flagIndex != MArgList::kInvalidArgIndex) {
    debug = true;
  }

  binaryRib = false;
  flagIndex = args.flagIndex("b", "binary");
  if (flagIndex != MArgList::kInvalidArgIndex) {
    binaryRib = true;
  }

  return redoIt();
}
示例#3
0
MStatus setupRGBShaders::doIt( const MArgList & args )
{
    unsigned int FIndex = args.flagIndex( "fp", "folderPath" );
    unsigned int fIndex = args.flagIndex( "fn", "fileName" );

    if( FIndex == MArgList::kInvalidArgIndex || fIndex == MArgList::kInvalidArgIndex ) {
        MGlobal::displayError( "Error specifying flag or flag values. \n-fp, -folderPath <folder_path> \t -fn, -fileName <file_name>" );
        return MS::kFailure;
    }

    folderPath = args.asString( FIndex );
    fileName = args.asString( fIndex );

    MItDag meshIt( MItDag::kDepthFirst, MFn::kMesh );

    for( ; !meshIt.isDone(); meshIt.next() ) {
        MDagPath dagPath;

        meshIt.getPath( dagPath );
        meshObjs.append( dagPath.transform() );
    }

    MItDag camIt( MItDag::kDepthFirst, MFn::kCamera );

    for( ; !camIt.isDone(); camIt.next() ) {
        MDagPath dagPath;

        camIt.getPath( dagPath );
        MFnDependencyNode camFn( dagPath.node() );

        bool isRenderable;
        camFn.findPlug( "renderable" ).getValue( isRenderable );

        if( isRenderable )
            camObjs.append( dagPath.transform() );
    }

    MGlobal::executeCommand( "setAttr miDefaultFramebuffer.datatype 5" );

    return redoIt();
}
MStatus vixo_hairCacheExport::doIt(const MArgList& args)
{
	MString vixoHairNode;
	int startFrame,endFrame;
	unsigned index;
	index=args.flagIndex("vhn","vixoHairNode");
	if(MArgList::kInvalidArgIndex!=index)
	{
		args.get(index+1,vixoHairNode);
	}
	index=args.flagIndex("sf","startFrame");
	if(MArgList::kInvalidArgIndex!=index)
	{
		args.get(index+1,startFrame);
	}
	index=args.flagIndex("ef","endFrame");
	if(MArgList::kInvalidArgIndex!=index)
	{
		args.get(index+1,endFrame);
	}

	//get hairCacheFileName
	MSelectionList slist;
	MGlobal::getSelectionListByName(vixoHairNode,slist);
	MDagPath vixoHairNodeDag;
	slist.getDagPath(0,vixoHairNodeDag);
	vixoHairNodeDag.extendToShape();
	MFnDagNode fnVixoHair(vixoHairNodeDag);
	MPlug plugCacheFileName=fnVixoHair.findPlug("hairCacheFileName");
	MString cacheFileName=plugCacheFileName.asString();
	//~get hairCacheFileName

	//get staticMesh
	MPlug plugStaticMesh=fnVixoHair.findPlug("staticInMesh");
	MObject staticMeshObj=MFnMeshData(plugStaticMesh.asMObject()).object();
	//~get staticMesh

	//build out dataBase
	MFnMesh fnStaticMesh(staticMeshObj);
	map<int,set<outInVertexRelationInfo>> outVertexDataBase;
	map<int,vector<outVIDCtrlInfo>> outVertexControlData;
	for(int i=0;i<fnStaticMesh.numVertices();i++)
	{
		set<outInVertexRelationInfo> temp;
		temp.clear();
		outVertexDataBase.insert(pair<int,set<outInVertexRelationInfo>>(i,temp));
	}
	//build out dataBase

	//get inCurveVID
	map<int,int> plugMapVID;
	map<int,int> VIDMapPlug;
	map<int,inVertexBasicInfo> inVIDMapInVertexDataBase;
	MPlug plugAllInCurve=fnVixoHair.findPlug("inCtrlCurveData");
	MIntArray existIndex;
	plugAllInCurve.getExistingArrayAttributeIndices(existIndex);
	for(int i=0;i<existIndex.length();i++)
	{
		MPlugArray arr;
		plugAllInCurve.elementByLogicalIndex(existIndex[i]).connectedTo(arr,true,false);
		MFnDependencyNode fnHairSystem(arr[0].node());
		MPlug inputHairs=fnHairSystem.findPlug("inputHair");
		arr.clear();
		inputHairs.elementByLogicalIndex(existIndex[i]).connectedTo(arr,true,false);
		MFnDependencyNode fnFolli(arr[0].node());
		int vid=fnFolli.findPlug("vertexID").asInt();
		plugMapVID.insert(pair<int,int>(existIndex[i],vid));
		VIDMapPlug.insert(pair<int,int>(vid,existIndex[i]));
		initBasicStepInfo(vid,staticMeshObj,inVIDMapInVertexDataBase);
	}	
	//~get inCurveVID

	//build in out relation
	map<int,inVertexBasicInfo>::iterator inDBIter;
	for(inDBIter=inVIDMapInVertexDataBase.begin();inDBIter!=inVIDMapInVertexDataBase.end();inDBIter++)
	{
		buileRelationBetweenInOut(inDBIter->first,inVIDMapInVertexDataBase,outVertexDataBase);
	}

	map<int,set<outInVertexRelationInfo>>::iterator outDBIter;
	for(outDBIter=outVertexDataBase.begin();outDBIter!=outVertexDataBase.end();outDBIter++)
	{
		sortControlOrder(outDBIter->first,outVertexDataBase,outVertexControlData);
	}
	//~build in out relation

	for(int i=startFrame;i<=endFrame;i++)
	{
		MString currentTime;
		currentTime.set(i);
		MGlobal::executeCommand("currentTime "+currentTime);
		MGlobal::executeCommand("dgeval "+vixoHairNode+".hiddenOutput");

		//get dynamic mesh
		MPlug plugDynamicMesh=fnVixoHair.findPlug("dynamicInMesh");
		MObject dynamicMeshObj=MFnMeshData(plugDynamicMesh.asMObject()).object();
		//~get dynamic mesh

		//export cache
		//faceid triid vid position normal tangent
		vector<forExportHairCache> exportData;
		exportBasicData(dynamicMeshObj,exportData);
		//curve tangent
		//get in curve infos
		map<int,MVectorArray> inCurveShape;
		getInCurveInfo(plugMapVID,vixoHairNode,inCurveShape);
		//~get in curve infos

		vector<vec3> outCurveCacheData;
		vec3 init;
		init.x=0;
		init.y=0;
		init.z=0;
		outCurveCacheData.resize(fnStaticMesh.numVertices()*inCurveShape.begin()->second.length(),init);
		buildCache(inCurveShape.begin()->second.length(),dynamicMeshObj,outCurveCacheData,inCurveShape,outVertexControlData);
		//~export cache

		//write to file
		MString fileName=getFileName(cacheFileName,i);
		fstream fout(fileName.asChar(),ios_base::out|ios_base::binary);
		int triNumvertexNum[3];
		triNumvertexNum[0]=exportData.size();
		triNumvertexNum[1]=fnStaticMesh.numVertices();
		triNumvertexNum[2]=inCurveShape.begin()->second.length();
		fout.write((char*)triNumvertexNum,sizeof(int)*3);
		fout.write((char*)&exportData[0],sizeof(forExportHairCache)*exportData.size());
		fout.write((char*)&outCurveCacheData[0],sizeof(vec3)*outCurveCacheData.size());
		fout.flush();
		fout.close();
		/*
		MString fileNameDebug=fileName+".dbg";
		fout.open(fileNameDebug.asChar(),ios_base::out);
		for(int i=0;i<outCurveCacheData.size();i++)
		{
			fout<<outCurveCacheData[i].x<<" "<<outCurveCacheData[i].y<<" "<<outCurveCacheData[i].z<<endl;
		}
		fout.flush();
		fout.close();
		*/
		//~write to file
	}

	return MS::kSuccess;
}
示例#5
0
文件: ribGenCmd.cpp 项目: redbug/CPP
MStatus ribGenCmd::doIt( const MArgList& args)
{
	/*=========================================*
	  *		the parameters of command															
	  *	=========================================*/
	MString ribPath, shaderPath;					
	unsigned index;
	index = args.flagIndex("p", "ribPath");

	if(MArgList::kInvalidArgIndex != index)
		args.get(index+1, ribPath);
	
	index = args.flagIndex("sp", "shaderPath");
	if(MArgList::kInvalidArgIndex != index)
		args.get(index+1, shaderPath);

	/*=========================================*
	  *		shaderPath & ribPath																		
	  *=========================================*/
	RtToken shader= new char[50] , path=new char[50];
	strcpy(shader, shaderPath.asChar());
	strcpy(path, ribPath.asChar());

	char *curve[] = {"curves"};	

	RtMatrix identityMatrix =
	{	{ 1, 0, 0, 0 },
		{ 0, 1, 0, 0 },
		{ 0, 0, 1, 0 },
		{ 0, 0, 0, 1 }}; 
	
	RtInt ustep, vstep;
	ustep = vstep =1;

  /*=====================================*
	*		Begenning of writting out the .rib file.														
	*=====================================*/	
	RiBegin(path);
		RiAttributeBegin();
			RiTransformBegin();
				//RiSurface(shader);
			RiTransformEnd();


			//RiAttribute("identifier", "name", curve);
			RiConcatTransform(identityMatrix);
			RiShadingInterpolation(RI_SMOOTH);
			RiBasis(RiBezierBasis, ustep, RiBezierBasis, vstep);			



	int nodeId	= 0, knotNum = 0;
	float baseWidth = 0.0f, tipWidth	= 0.0f;
	MObject surface, node;
	/*=========================================*
	  *		get the informations of selected Objects in scene.																		
	  *=========================================*/	
	MSelectionList selection;
	MGlobal::getActiveSelectionList(selection);
	MItSelectionList iter(selection, MFn::kNurbsSurface );

	for(; !iter.isDone(); iter.next())
	{
		RtInt numCurves = 0;
		RtInt numVertexs = 0;

		/*======================================*
		  *		get the drawHairNode from selected NurbsSurface. 
		  *======================================*/
		iter.getDependNode(surface);
		MFnDependencyNode surfaceFn(surface);
		MStatus state;
		MPlug plug = surfaceFn.findPlug("worldSpace",false, &state);

		plug = plug.elementByLogicalIndex(0);
		MPlugArray desPlugs;
		plug.connectedTo(desPlugs,false,true);
		plug = desPlugs[0];
		node = plug.node();				//drawHairNode has found here!!

		/*=====================================*
		  *		get the attributes of drawHairNode. 
		  *=====================================*/
		MFnDependencyNode hairNodeFn(node);
		plug = hairNodeFn.findPlug("nodeId");
		plug.getValue(nodeId);
		MGlobal::displayInfo(MString(" nodeId: ")+nodeId);

		plug = hairNodeFn.findPlug("number");
		plug.getValue(numCurves);

		plug= hairNodeFn.findPlug("smooth");
		plug.getValue(knotNum);

		plug = hairNodeFn.findPlug("baseWidth");
		plug.getValue(baseWidth);

		plug = hairNodeFn.findPlug("tipWidth");
		plug.getValue(tipWidth);

		/*=====================================*
		  *		caculate the linear interpolate of the width of the curve.
		  *=====================================*/
		numVertexs = numCurves * knotNum;
		int widthNum = numCurves * (knotNum -2 );
		float *curveWidth = new float[widthNum];
		
		float widthStep = 0.0f;
		for(int c=0; c<widthNum; ++c){
			widthStep = ((c%(knotNum-2)) / (float)(knotNum-3)) *(tipWidth - baseWidth);
			if(widthStep < epslion)
				widthStep = 0.0f;
			curveWidth[c] = baseWidth + widthStep;
		}
		

		RtInt *nvertices = new RtInt[numCurves];						//the numbers of vertices on each curve.
		RtPoint *vertexs = new RtPoint[numVertexs];				//the total vertexs.

		/*=====================================*
		  *		nvertices[] assignment.														
		  *=====================================*/
		for(int j=0; j<numCurves ; ++j){
			nvertices[j] = knotNum;
		}



		/*=====================================*
		  *		get the hair's datas from the static member 
		  *		named "nodeManager" of the drawHairNode class. 
		  *=====================================*/
		nodeMap::iterator  iter =  drawHairNode::nodeManager.find(nodeId);
		vector<MPointArray> helixVec = iter->second;
		

		/*=====================================*
		  *		vertexs[] assignment.														
		  *=====================================*/	
		float x=0, y=0, z=0;
		int countVT=0;
		for(vector<MPointArray>::iterator it=helixVec.begin();  it != helixVec.end();  ++it){
			MPointArray helixCurve = (MPointArray)(*it);

			for(int k=0; k <  helixCurve.length() ; ++k){
				x = helixCurve[k].x;
				if(fabs(x) < epslion)
					vertexs[countVT][0] = 0;
				else
					vertexs[countVT][0] = helixCurve[k].x;
			
				y = helixCurve[k].y;
				if(fabs(y) < epslion)
					vertexs[countVT][1] = 0;
				else
					vertexs[countVT][1] = helixCurve[k].y;
			
				z = helixCurve[k].z;			
				if(fabs(z) < epslion)
					vertexs[countVT++][2] = 0;
				else
					vertexs[countVT++][2] = helixCurve[k].z;
			}
		}
		RiCurves( RI_CUBIC, numCurves, nvertices, RI_NONPERIODIC, RI_P, vertexs, RI_WIDTH, curveWidth, RI_NULL);
	}
	


		RiAttributeEnd();
	RiEnd();

	return redoIt();
}
示例#6
0
MStatus testExCameraSetCmd::parseArgs( const MArgList& args)
//
// Parses the command line arguments.
//
{
	MStatus status;

	//	Get the flags.  If the create or help flags are used, return success and ignore the other flags.
	createUsed = (args.flagIndex(kCreateFlag, kCreateFlagLong) != MArgList::kInvalidArgIndex);
	editUsed = (args.flagIndex(kEditFlag, kEditFlagLong) != MArgList::kInvalidArgIndex);
	queryUsed = (args.flagIndex(kQueryFlag, kQueryFlagLong) != MArgList::kInvalidArgIndex);
	helpUsed = (args.flagIndex(kHelpFlag, kHelpFlagLong) != MArgList::kInvalidArgIndex);
	numLayersUsed = (args.flagIndex(kNumLayersFlag, kNumLayersFlagLong) != MArgList::kInvalidArgIndex);

	// If flags are used which require no other information, return now.
	if (createUsed || helpUsed)
		return MS::kSuccess;

	unsigned int maxArg = args.length() - 1;
	unsigned int activeIndex = args.flagIndex(kActiveFlag, kActiveFlagLong);
	unsigned int appendCameraIndex = args.flagIndex(kAppendCameraFlag, kAppendCameraFlagLong);
	unsigned int appendCameraAndSetIndex = args.flagIndex(kAppendCameraAndSetFlag, kAppendCameraAndSetFlagLong);
	unsigned int cameraIndex = args.flagIndex(kCameraFlag, kCameraFlagLong);
	unsigned int deleteLayerIndex = args.flagIndex(kDeleteLayerFlag, kDeleteLayerFlagLong);
	unsigned int layerIndex = args.flagIndex(kLayerFlag, kLayerFlagLong);
	unsigned int layerTypeIndex = args.flagIndex(kLayerTypeFlag, kLayerTypeFlagLong);
	unsigned int setIndex = args.flagIndex(kSetFlag, kSetFlagLong);
	activeUsed = (activeIndex != MArgList::kInvalidArgIndex);
	appendCameraUsed = (appendCameraIndex != MArgList::kInvalidArgIndex);
	appendCameraAndSetUsed = (appendCameraAndSetIndex != MArgList::kInvalidArgIndex);
	cameraUsed = (cameraIndex != MArgList::kInvalidArgIndex);
	deleteLayerUsed = (deleteLayerIndex != MArgList::kInvalidArgIndex);
	layerUsed = (layerIndex != MArgList::kInvalidArgIndex);
	layerTypeUsed = (layerTypeIndex != MArgList::kInvalidArgIndex);
	setUsed = (setIndex != MArgList::kInvalidArgIndex);

	// Process each flag.
	bool maxArgUsed = false;
	if (activeUsed)
	{
		if (editUsed)
		{
			activeVal = args.asBool((activeIndex+1), &status);
			if (status != MS::kSuccess)
			{
				MGlobal::displayError("-active must be either true or false");
				return status;
			}
			if ((layerTypeIndex+1) == maxArg)
				maxArgUsed = true;
		}
	}
	if (appendCameraUsed)
	{
		camName = args.asString((appendCameraIndex+1), &status);
		if (status != MS::kSuccess)
		{
			MGlobal::displayError("-appendCamera must have a valid camera node specified");
			return status;
		}

		if ((appendCameraIndex+1) == maxArg)
			maxArgUsed = true;
	}
	if (appendCameraAndSetUsed)
	{
		camName = args.asString((appendCameraAndSetIndex+1));
		setName = args.asString((appendCameraAndSetIndex+2));
		if ((appendCameraAndSetIndex+2) == maxArg)
			maxArgUsed = true;
	}
	if (cameraUsed)
	{
		if (editUsed)
		{
			camName = args.asString(cameraIndex+1);
			if ((cameraIndex+1) == maxArg)
				maxArgUsed = true;
		}
	}
	if (deleteLayerUsed)
	{
		cameraLayer = args.asInt(deleteLayerIndex+1);
		if ((deleteLayerIndex+1) == maxArg)
			maxArgUsed = true;
	}
	if (layerUsed)
	{
		cameraLayer = args.asInt(layerIndex+1);
		if ((layerIndex+1) == maxArg)
			maxArgUsed = true;
	}
	if (layerTypeUsed)
	{
		if (editUsed)
		{
			layerTypeVal = args.asString(layerTypeIndex+1);
			if ((layerTypeIndex+1) == maxArg)
				maxArgUsed = true;
		}
	}
	if (setUsed)
	{
		if (editUsed)
		{
			setName = args.asString(setIndex+1);
			if ((setIndex+1) == maxArg)
				maxArgUsed = true;
		}
	}

	// If all of the arguments have been used, get the cameraSet node from the selection list.
	// Otherwise, get it from the last argument.
	if (maxArgUsed)
		MGlobal::getActiveSelectionList(list);
	else
		list.add(args.asString(maxArg));

	return MS::kSuccess;
}