コード例 #1
0
ファイル: iffPpmCmd.cpp プロジェクト: DimondTheCat/xray
MStatus iffPpm::doIt( const MArgList& args )
{
    MString componentName;
	if (args.length () < 2 || args.length () > 3) {
		displayError ("Syntax: iffPpm ifffile ppmfile [-depth]");
		return MS::kFailure;
	}

	args.get (0, fileName);
	args.get (1, ppmFile);
	if (args.length () == 3)
	{
		MString lastArg;
		args.get (2, lastArg);
		if (lastArg != MString ("-depth")) {
			displayError ("Syntax: iffPpm ifffile ppmfile [-depth]");
			return MS::kFailure;
		}
		useDepth = true;
	}
	else
		useDepth = false;

    return redoIt();
}
コード例 #2
0
ファイル: apiMeshData.cpp プロジェクト: vasilenkomike/xray
MStatus apiMeshData::readVerticesASCII( const MArgList& argList,
                                        unsigned& index )
{
    MStatus result;
    MString geomStr;
    MPoint vertex;
    int vertexCount = 0;

    result = argList.get( index, geomStr );

    if ( result && (geomStr == kVertexKeyword) ) {
        result = argList.get( ++index, vertexCount );

        for ( int i=0; i<vertexCount; i++ )
        {
            if ( argList.get( ++index, vertex ) ) {
                fGeometry->vertices.append( vertex );
            }
            else {
                result = MS::kFailure;
            }
        }
    }

    return result;
}
コード例 #3
0
ファイル: apiMeshData.cpp プロジェクト: vasilenkomike/xray
MStatus apiMeshData::readNormalsASCII( const MArgList& argList,
                                       unsigned& index )
{
    MStatus result;
    MString geomStr;
    MPoint normal;
    int normalCount = 0;

    result = argList.get( index, geomStr );

    if ( result && (geomStr == kNormalKeyword) ) {
        result = argList.get( ++index, normalCount );
        for ( int i=0; i<normalCount; i++ )
        {
            if ( argList.get( ++index, normal ) ) {
                fGeometry->normals.append( normal );
            }
            else {
                result = MS::kFailure;
            }
        }
    }

    return result;
}
コード例 #4
0
ファイル: apiMeshData.cpp プロジェクト: vasilenkomike/xray
MStatus apiMeshData::readFacesASCII( const MArgList& argList,
                                     unsigned& index )
{
    MStatus result = MS::kSuccess;
    MString geomStr;
    int faceCount = 0;
    int vid;

    while( argList.get(index,geomStr) && (geomStr == kFaceKeyword) )
    {
        result = argList.get( ++index, faceCount );
        fGeometry->face_counts.append( faceCount );

        for ( int i=0; i<faceCount; i++ )
        {
            if ( argList.get( ++index, vid ) ) {
                fGeometry->face_connects.append( vid );
            }
            else {
                result = MS::kFailure;
            }
        }
        index++;
    }

    fGeometry->faceCount = fGeometry->face_counts.length();
    return result;
}
コード例 #5
0
ファイル: createClipCmd.cpp プロジェクト: BigRoy/Maya-devkit
MStatus createClip::parseArgs( const MArgList& args )
//
// No arguments to parse.
//
{
	MStatus     	stat = MS::kSuccess;
	MString     	arg;
	MSelectionList	list;
	bool			charNameUsed = 0;
	MString			charName;
	const MString	charFlag			("-c");
	const MString	charFlagLong		("-char");

	// Parse the arguments.
	for ( unsigned int i = 0; i < args.length(); i++ ) {
		arg = args.asString( i, &stat );
		if (!stat)              
			continue;
				
		if ( arg == charFlag || arg == charFlagLong ) {
			// get the char name
			//
			if (i == args.length()-1) {
				arg += ": must specify a character name";
				displayError(arg);
				return MS::kFailure;
			}
			i++;
			args.get(i, charName);
			list.add(charName);
			charNameUsed = 1;
		}
		else {
			arg += ": unknown argument";
			displayError(arg);
			return MS::kFailure;
		}
	}

	if (charNameUsed) {
		// get the character corresponding to the node name
		//
		MItSelectionList iter (list);
		for ( /* nothing */ ; !iter.isDone(); iter.next() ) {
			MObject node;
			iter.getDependNode(node);
			if (node.apiType() == MFn::kCharacter) {
				fCharacter = node;
				break;
			}
		}
		if (fCharacter.isNull()) {
			MString errMsg("Character flag must specify a character node.");
			displayError(errMsg);
			return MS::kFailure;
		}
	}
	
	return stat;
}
コード例 #6
0
// parseArgs
//
MStatus viewCallbackTest::parseArgs(const MArgList& args)
{
	MStatus			status;
	MArgDatabase	argData(syntax(), args);

	// Buffer operation argument variables
	mBufferOperation = kInvertColorBuffer;
	MString operationString;

	MString     	arg;
	for ( unsigned int i = 0; i < args.length(); i++ ) 
	{
		arg = args.asString( i, &status );
		if (!status)              
			continue;

		if ( arg == MString(bufferOperationShortName) || arg == MString(bufferOperationLongName) ) 
		{
			if (i == args.length()-1) {
				arg += ": must specify a buffer operation.";
				displayError(arg);
				return MS::kFailure;
			}
			i++;
			args.get(i, operationString );

			bool validOperation = false;
			for (unsigned int k=0; k<_NUMBER_BUFFER_OPERATIONS_; k++)
			{
				if (bufferOperationStrings[i] == operationString)
				{
					mBufferOperation = bufferOperations[k];
					validOperation = true;
				}
			}
			if (!validOperation)
				status.perror("Invalid operation specified. Using invert by default.");
		}
	}

	// Read off the panel name
	status = argData.getCommandArgument(0, mPanelName);
	if (!status)
	{
		status.perror("No panel name specified as command argument");
		return status;
	}
	return MS::kSuccess;
}
コード例 #7
0
MStatus dagPoseInfo::parseArgs( const MArgList& args )
//
// There is one mandatory flag: -f/-file <filename>
//
{
    MStatus     	stat;
    MString     	arg;
    MString			fileName;
    const MString	fileFlag			("-f");
    const MString	fileFlagLong		("-file");

    // Parse the arguments.
    for ( unsigned int i = 0; i < args.length(); i++ ) {
        arg = args.asString( i, &stat );
        if (!stat)
            continue;

        if ( arg == fileFlag || arg == fileFlagLong ) {
            // get the file name
            //
            if (i == args.length()-1) {
                arg += ": must specify a file name";
                displayError(arg);
                return MS::kFailure;
            }
            i++;
            args.get(i, fileName);
        }
        else {
            arg += ": unknown argument";
            displayError(arg);
            return MS::kFailure;
        }
    }

    file = fopen(fileName.asChar(),"wb");
    if (!file) {
        MString openError("Could not open: ");
        openError += fileName;
        displayError(openError);
        stat = MS::kFailure;
    }

    return stat;
}
コード例 #8
0
ファイル: apiMeshData.cpp プロジェクト: vasilenkomike/xray
MStatus apiMeshData::readUVASCII( const MArgList &argList,
                                  unsigned &index )
{
    MStatus result = MS::kSuccess;
    MString uvStr;
    double u, v;
    int fvi;
    int faceVertexListCount = 0;
    int uvCount;

    fGeometry->uvcoords.reset();
    if ( argList.get(index,uvStr) && (uvStr == kUVKeyword) ) {
        result = argList.get( ++index, uvCount );
        if ( result ) {
            result = argList.get( ++index, faceVertexListCount );
        }
        int i;
        for ( i = 0; i < uvCount && result; i ++ ) {
            if ( argList.get( ++index, u ) && argList.get( ++index, v ) ) {
                fGeometry->uvcoords.append_uv( (float)u, (float)v );
            } else {
                result = MS::kFailure;
            }
        }

        for ( i = 0; i < faceVertexListCount && result; i++ ) {
            if ( argList.get( ++index, fvi ) ) {
                fGeometry->uvcoords.faceVertexIndex.append( fvi );
            } else {
                result = MS::kFailure;
            }
        }
    }

    return result;
}
コード例 #9
0
ファイル: intersectCmd.cpp プロジェクト: BigRoy/Maya-devkit
MStatus intersectCmd::doIt(const MArgList& args)

// Description:
// 		Determine if the ray from the spotlight intersects the mesh.
//		If it does, display the intersection points.

{
	MStatus stat = MStatus::kSuccess;

	if (args.length() != 2) 
	{
		MGlobal::displayError("Need 2 items!");
		return MStatus::kFailure;
	}

	MSelectionList activeList;
	int i;
	
	for ( i = 0; i < 2; i++)
	{
		MString strCurrSelection;
		stat = args.get(i, strCurrSelection);
		if (MStatus::kSuccess == stat) activeList.add(strCurrSelection);
	}

	MItSelectionList iter(activeList);
	MFnSpotLight fnLight;  
	MFnMesh fnMesh;
	MFnDagNode dagNod;
	MFnDependencyNode fnDN;

	float fX = 0;
	float fY = 0;
	float fZ = 0;

	for ( ; !iter.isDone(); iter.next() )
	{
		MObject tempObjectParent, tempObjectChild;
		iter.getDependNode(tempObjectParent);

		if (tempObjectParent.apiType() == MFn::kTransform)
		{
			dagNod.setObject(tempObjectParent);
			tempObjectChild = dagNod.child(0, &stat);
		}

		// check what type of object is selected
		if (tempObjectChild.apiType() == MFn::kSpotLight)
		{
			MDagPath pathToLight;
			MERR_CHK(MDagPath::getAPathTo(tempObjectParent, pathToLight), "Couldn't get a path to the spotlight");
			MERR_CHK(fnLight.setObject(pathToLight), "Failure on assigning light");
			
			stat = fnDN.setObject(tempObjectParent);

			MPlug pTempPlug = fnDN.findPlug("translateX", &stat);
			if (MStatus::kSuccess == stat)
			{
				pTempPlug.getValue(fX);
			}

			pTempPlug = fnDN.findPlug("translateY", &stat);
			if (MStatus::kSuccess == stat)
			{
				pTempPlug.getValue(fY);
			}

			pTempPlug = fnDN.findPlug("translateZ", &stat);
			if (MStatus::kSuccess == stat)
			{
				pTempPlug.getValue(fZ);
			}	
		}
		else if (tempObjectChild.apiType() == MFn::kMesh)
		{
			MDagPath pathToMesh;
			MERR_CHK(MDagPath::getAPathTo(tempObjectChild, pathToMesh), "Couldn't get a path to the spotlight");
			MERR_CHK(fnMesh.setObject(pathToMesh), "Failure on assigning light");	
		}
		else
		{
			MGlobal::displayError("Need a spotlight and a mesh");
			return MStatus::kFailure;
		}
	}

	MFloatPoint fpSource(fX, fY, fZ);
	MFloatVector fvRayDir = fnLight.lightDirection(0, MSpace::kWorld, &stat);
	MFloatPoint hitPoint;
	
	MMeshIsectAccelParams mmAccelParams = fnMesh.autoUniformGridParams();
	
	float fHitRayParam, fHitBary1, fHitBary2;
	int nHitFace, nHitTriangle;

	// a large positive number is used here for the maxParam parameter
	bool bAnyIntersection = fnMesh.anyIntersection(fpSource, fvRayDir, NULL, NULL, false,				MSpace::kWorld, (float)9999, false, &mmAccelParams, hitPoint, &fHitRayParam, &nHitFace, &nHitTriangle, 		&fHitBary1, &fHitBary2, (float)1e-6, &stat);
	
	if (! bAnyIntersection) 
	{
		MGlobal::displayInfo("There were no intersection points detected");
		return stat;
	}

	MFloatPointArray hitPoints;
	MFloatArray faHitRayParams;
	MIntArray iaHitFaces;
	MIntArray iaHitTriangles;
	MFloatArray faHitBary1;
	MFloatArray faHitBary2;

	bool bAllIntersections = fnMesh.allIntersections(fpSource, fvRayDir, NULL, NULL, false, MSpace::kWorld, 9999, false, NULL, false, hitPoints, &faHitRayParams, &iaHitFaces, &iaHitTriangles, &faHitBary1, &faHitBary2, 0.000001f, &stat);
	
	if (! bAllIntersections)
	{
		MGlobal::displayInfo("Error getting all intersections");
		return stat;
	}
	
	// check how many intersections are found
	unsigned int nNumberHitPoints = hitPoints.length();

	if (! nNumberHitPoints)
	{
		MGlobal::displayInfo("No hit points detected");
		return MStatus::kSuccess;
	}

	// Intersection exists; display intersections as spheres
	MString strCommandString = "string $strBall[] = `polySphere -r 0.5`;";
	strCommandString += "$strBallName = $strBall[0];";

	float x = 0;
	float y = 0;
	float z = 0;

	for (i = 0; i < (int)nNumberHitPoints; i++)
	{
		// get the points
		x = hitPoints[i][0];
		y = hitPoints[i][1];
		z = hitPoints[i][2];

		// execute some MEL to create a small sphere
		strCommandString += "setAttr ($strBallName + \".tx\") ";
		strCommandString += x;
		strCommandString += ";";

		strCommandString += "setAttr ($strBallName + \".ty\") ";
		strCommandString += y;
		strCommandString += ";";

		strCommandString += "setAttr ($strBallName + \".tz\") ";
		strCommandString += z;
		strCommandString += ";";

		MGlobal::executeCommand(strCommandString);
	}

	return stat;
}
コード例 #10
0
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;
}
コード例 #11
0
ファイル: viewCaptureCmd.cpp プロジェクト: BigRoy/Maya-devkit
MStatus viewCapture::doIt( const MArgList& args )
{
	MStatus status = MS::kSuccess;

	if ( args.length() != 1 ) {
		// Need the file name argument
		//
		return MS::kFailure;
	}

	MString fileName;
	args.get( 0, fileName );

	// Get the active 3D view
	//
	M3dView view = M3dView::active3dView();

	// Capture the current view
	//
	view.refresh();
	view.beginGL();
 
	// Set the target for our pixel read to be the front buffer.  First, the
	// current state is saved using the glPushAttrib call.  It is important
	// to leave the OpenGL in the same state that we found it.
	//
	glPushAttrib( GL_PIXEL_MODE_BIT ); 

	int width = view.portWidth();
	int height = view.portHeight(); 

	// Allocate buffers for the pixel data
	//
	GLfloat * red   = new GLfloat[width*height];
	GLfloat * green = new GLfloat[width*height];
	GLfloat * blue  = new GLfloat[width*height];

	// Read the values from the OpenGL frame buffer
	//
	glReadBuffer( GL_FRONT );
	glReadPixels( 0, 0, width, height, GL_RED, GL_FLOAT, red );
	glReadPixels( 0, 0, width, height, GL_GREEN, GL_FLOAT, green );
	glReadPixels( 0, 0, width, height, GL_BLUE, GL_FLOAT, blue );
	
	// Put the gl read target back
	//
	glPopAttrib(); 

	view.endGL();

	// Write file as a PPM
	//
	Pic_Pixel * line = PixelAlloc( width );
	int idx;

	Pic * file = PicOpen( fileName.asChar(), (short) width, (short) height );
	if ( NULL != file ) { 
		for ( int row = height - 1; row >= 0; row-- ) {
			// Covert the row of pixels into PPM format
			//
			for ( int col = 0; col < width; col++ ) {
				// Find the array elements for this pixel
				//
				idx = ( row * width ) + ( col );
				line[col].r = (Pic_byte)( red[idx]   * 255.0 );
				line[col].g = (Pic_byte)( green[idx] * 255.0 );
				line[col].b = (Pic_byte)( blue[idx] * 255.0 );
			}
			// Write the line
			//
			if ( !PicWriteLine( file, line ) ) {
				status = MS::kFailure; 
				return MS::kFailure;
			}
		}
		PicClose( file ); 
	}
 
	delete []red;
	delete []green;
	delete []blue;
	PixelFree( line );

	return status;
}
コード例 #12
0
ファイル: iffPixelCmd.cpp プロジェクト: BigRoy/Maya-devkit
MStatus iffPixel::doIt( const MArgList& args )
{
    MString componentName;
	if (args.length () < 3 || args.length () > 4) {
		displayError ("Syntax: iffPixel file x y [-depth]");
		return MS::kFailure;
	}

	int x,y;
	MString fileName;

	args.get (0, fileName);
	args.get (1, x);
	args.get (2, y);
	if (args.length () == 4)
	{
		MString lastArg;
		args.get (3, lastArg);
		if (lastArg != MString ("-depth")) {
			displayError ("Syntax: iffPixel file x y [-depth]");
			return MS::kFailure;
		}
		useDepth = true;
	}
	else
		useDepth = false;

	IFFimageReader reader;
	MStatus stat;

	stat = reader.open (fileName);
	IFFCHECKERR (stat, open);

	int w,h;
	stat = reader.getSize (w,h);
	IFFCHECKERR (stat, getSize);
	if (x < 0 || x > w || y < 0 || y > h) {
		MString message ("Co-ordinates out of range. Size of image is ");
		message += itoa (w);
		message += "+";
		message += itoa (h);
		displayError (message);
		return MS::kFailure;
	}

	stat = reader.readImage ();
	IFFCHECKERR (stat, readImage);
	if (useDepth)
	{
		if (!reader.hasDepthMap ()) {
			displayError ("Image has no depth map");
			return MS::kFailure;
		}
		stat = reader.getDepth (x,y,&d);
	}
	else
	{
		if (!reader.isRGB () && !reader.isGrayscale ()) {
			displayError ("Image has no RGB data");
			return MS::kFailure;
		}
		stat = reader.getPixel (x,y,&r,&g,&b,&a);
	}
	IFFCHECKERR (stat, getPixel);

	stat = reader.close ();
	IFFCHECKERR (stat, close);

    return redoIt();
}
コード例 #13
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();
}
コード例 #14
0
MStatus findFileTextures::doIt( const MArgList& args )
{

	MSelectionList list;
    MStatus        status;

	if ( args.length() > 0 ) {
		// Arg list is > 0 so use objects that were passes in
		//
		MString argStr;

		unsigned last = args.length();
		for ( unsigned i = 0; i < last; i++ ) {
			// Attempt to find all of the objects matched
			// by the string and add them to the list
			//
			args.get( i, argStr );  
			list.add( argStr ); 
		}
	} else {
		// Get arguments from Maya's selection list.
		MGlobal::getActiveSelectionList( list );
    }

	MObject             node;
    MFnDependencyNode   nodeFn,dgNodeFnSet;
    MItDependencyGraph* dgIt; 
    MObject             currentNode;
	MObject 			thisNode;
    MObjectArray        nodePath;

	for ( MItSelectionList iter( list ); !iter.isDone(); iter.next() ) {

		iter.getDependNode( node );

        //
        // The following code shows how to navigate the DG manually without
        // using an iterator.  First, find the attribute that you are 
        // interested.  Then connect a plug to it and see where the plug 
        // connected to.  Once you get all the connections, you can choose 
        // which route you want to go.
        //
        // In here, we wanted to get to the nodes that instObjGroups connected
        // to since we know that the shadingEngine connects to the instObjGroup
        // attribute.
        //

        nodeFn.setObject( node );
        MObject iogAttr = nodeFn.attribute( "instObjGroups", &status);
		if ( !status ) {
			cerr << nodeFn.name() << ": is not a renderable object, skipping\n";
			continue;
		}

        MPlug iogPlug( node, iogAttr );
        MPlugArray iogConnections;

        //
        // instObjGroups is a multi attribute.  In this example, just the
        // first connection will be tried.
        //
        iogPlug.elementByLogicalIndex(0).connectedTo( iogConnections, false, true, &status );

		if ( !status ) {
			cerr << nodeFn.name() << ": is not in a shading group, skipping\n";
			continue;
		}

        //
        // Now we would like to traverse the DG starting from the shadingEngine
        // since most likely all file texture nodes will be found.  Note the 
        // filter used to initialize the DG iterator.  There are lots of filter
        // type available in MF::Type that you can choose to suite your needs.
        //
		bool foundATexture = false;
        for ( unsigned int i=0; i<iogConnections.length(); i++ ) {

            currentNode = iogConnections[i].node();

            // 
            // Note that upon initilization, the current pointer of the 
            // iterator already points to the first valid node.
            //
            dgIt = new MItDependencyGraph( currentNode, 
                               MFn::kFileTexture,
                               MItDependencyGraph::kUpstream, 
                               MItDependencyGraph::kBreadthFirst,
                               MItDependencyGraph::kNodeLevel, 
                               &status );
			if ( !status ) {
				delete dgIt;
				continue;
			}
            dgIt->disablePruningOnFilter();

            for ( ; ! dgIt->isDone(); dgIt->next() ) {
              
			   	thisNode = dgIt->thisNode();
                dgNodeFnSet.setObject( thisNode ); 
                status = dgIt->getNodePath( nodePath );

                if ( !status ) {
					status.perror("getNodePath");
					continue;
                }

                //
                // append the starting node.
                //
                nodePath.append(node);
                dumpInfo( thisNode, dgNodeFnSet, nodePath );
				foundATexture = true;
            }
            delete dgIt;
        }
		
		if ( !foundATexture ) {
			cerr << nodeFn.name() << ": is not connected to a file texture\n";
		}
    }
    return MS::kSuccess; 
}
コード例 #15
0
MStatus getAttrAffects::doIt( const MArgList& args )
{
	MStatus stat;
	MSelectionList list;

	if ( args.length() > 0 ) {
		// Arg list is > 0 so use objects that were passes in
		//
		MString argStr;

		unsigned last = args.length();
		for ( unsigned i = 0; i < last; i++ ) {
			// Attempt to find all of the objects matched
			// by the string and add them to the list
			//
			args.get( i, argStr );  
			list.add( argStr ); 
		}
	} else {
		// Get the geometry list from what is currently selected in the 
		// model
		//
		MGlobal::getActiveSelectionList( list );
	} 
	MItSelectionList iter( list );

	// Iterate over all selected dependency nodes
	//
	for ( ; !iter.isDone(); iter.next() ) 
	{
		MObject object;

		stat = iter.getDependNode( object );
		if ( !stat ) {
			stat.perror("getDependNode");
			continue;
		}

		// Create a function set for the dependency node
		//
		MFnDependencyNode node( object );

		cout << node.name() << ":\n";
		unsigned i, numAttributes = node.attributeCount();

		for (i = 0; i < numAttributes; ++i) {
			MObject attrObject = node.attribute(i);
			MFnAttribute attr;
			unsigned j, affectedLen, affectedByLen;

			attr.setObject (attrObject);

			// Get all attributes that this one affects
			MObjectArray affectedAttributes;
			node.getAffectedAttributes( attrObject, affectedAttributes );
			affectedLen = affectedAttributes.length();

			// Get all attributes that affect this one
			MObjectArray affectedByAttributes;
			node.getAffectedByAttributes( attrObject, affectedByAttributes );
			affectedByLen = affectedByAttributes.length();

			if ( affectedLen > 0 || affectedByLen > 0 ) {
				cout << "  " << attr.name() << ":\n";

				// List all attributes that are affected by the current one
				if ( affectedLen > 0 ) {
					cout << "    Affects(" << affectedLen << "):";

					for (j = 0; j < affectedLen; ++j ) {
						attr.setObject ( affectedAttributes[j] );
						cout << " " << attr.name();
					}
					cout << endl;
				}

				// List all attributes that affect the current one
				if ( affectedByLen > 0 ) {
					cout << "    AffectedBy(" << affectedByLen << "):";

					for (j = 0; j < affectedByLen; ++j ) {
						attr.setObject ( affectedByAttributes[j] );
						cout << " " << attr.name();
					}
					cout << endl;
				}
			}
		}
	}
	return MS::kSuccess;
}
コード例 #16
0
ファイル: cvPosCmd.cpp プロジェクト: BigRoy/Maya-devkit
MStatus cvPos::doIt( const MArgList& args )
{

    MString componentName;
	MSpace::Space transformSpace = MSpace::kWorld;

	for (unsigned int i = 0; i < args.length (); i++)
	{
		MString argStr;
		args.get (i, argStr);
		if (MString ("-l") == argStr || MString ("-local") == argStr)
			transformSpace = MSpace::kObject;
		else if (MString ("-w") == args.asString (i) ||
				 MString ("-world") == argStr)
			transformSpace = MSpace::kWorld;
		else
			componentName = argStr;
	}

    MObject     component;
    MDagPath    dagPath;

	if (!componentName.length ()) {
		MSelectionList activeList;

		MGlobal::getActiveSelectionList (activeList);

		MItSelectionList iter (activeList, MFn::kComponent);
		if (iter.isDone ())	{
			displayError ("No components selected");
			return MS::kFailure;
		} else {
			iter.getDagPath (dagPath, component);
			iter.next ();
			if (!iter.isDone ()) {
				displayError ("More than one component is selected");
				return MS::kFailure;
			}
		}
	} else {
		MSelectionList list;

		if (! list.add( componentName ) ) {
			componentName += ": no such component";
			displayError(componentName);
			return MS::kFailure; // no such component
		}
		MItSelectionList iter( list );
        iter.getDagPath( dagPath, component );
	}

	if (component.isNull()) {
		displayError("not a component");
		return MS::kFailure;
	}

	switch (component.apiType()) {
	case MFn::kCurveCVComponent:
		{
			MItCurveCV curveCVIter( dagPath, component );
			point = curveCVIter.position(transformSpace );
			curveCVIter.next();
			if (!curveCVIter.isDone()) {
				displayError ("More than one component is selected");
				return MS::kFailure;
			}
			break;
		}

	case MFn::kSurfaceCVComponent:
		{
			MItSurfaceCV surfCVIter( dagPath, component, true );
			point = surfCVIter.position(transformSpace );
			surfCVIter.next();
			if (!surfCVIter.isDone()) {
				displayError ("More than one component is selected");
				return MS::kFailure;
			}
			break;
		}

	case MFn::kMeshVertComponent:
		{
			MItMeshVertex vertexIter( dagPath, component );
			point = vertexIter.position(transformSpace );
			vertexIter.next();
			if (!vertexIter.isDone()) {
				displayError ("More than one component is selected");
				return MS::kFailure;
			}
			break;
		}

	default:
		cerr << "Selected unsupported type: (" << component.apiType()
			 << "): " << component.apiTypeStr() << endl;
	}

    return redoIt();
}
コード例 #17
0
ファイル: poseSpaceCmd.cpp プロジェクト: ahmidou/aphid
MStatus CBPoseSpaceCmd::parseArgs( const MArgList& args )
{
    _operation = tCreate;
    _cacheName = "";
    _poseName = "";
    _bindName = "";
    // Parse the arguments.
    MStatus stat = MS::kSuccess;
    MString     	arg;
    const MString	createCacheFlag			("-cc");
    const MString	createCacheFlagLong		("-createCache");
    const MString	loadCacheFlag			("-lc");
    const MString	loadCacheFlagLong		("-loadCache");
    const MString	savePoseFlag			("-sp");
    const MString	savePoseFlagLong		("-savePose");
    const MString	loadPoseFlag			("-lp");
    const MString	loadPoseFlagLong		("-loadPose");
    const MString	poseAtFlag			("-pa");
    const MString	poseAtFlagLong		("-poseAt");
    const MString	bindToFlag			("-bt");
    const MString	bindToFlagLong		("-bindTo");
    for ( unsigned int i = 0; i < args.length(); i++ ) {
        arg = args.asString( i, &stat );
        if (!stat)
            continue;

        if ( arg == createCacheFlag || arg == createCacheFlagLong ) {
            _operation = tCreate;
        }
        else if ( arg == loadCacheFlag || arg == loadCacheFlagLong ) {
            if (i == args.length()-1)
                continue;
            i++;
            _operation = tLoad;
            args.get(i, _cacheName);
        }
        else if ( arg == savePoseFlag || arg == savePoseFlagLong ) {
            if (i == args.length()-1)
                continue;
            i++;
            _operation = tSavePose;
            args.get(i, _cacheName);
        }
        else if ( arg == loadPoseFlag || arg == loadPoseFlagLong ) {
            if (i == args.length()-1)
                continue;
            i++;
            _operation = tLoadPose;
            args.get(i, _cacheName);
        }
        else if ( arg == poseAtFlag || arg == poseAtFlagLong ) {
            if (i == args.length()-1)
                continue;
            i++;
            args.get(i, _poseName);
        }
        else if ( arg == bindToFlag || arg == bindToFlagLong ) {
            if (i == args.length()-1)
                continue;
            i++;
            args.get(i, _bindName);
        }
        else {
            MGlobal::displayInfo(MString("unknown flag ") + arg);
        }
    }

    if(_operation == tLoad)
    {
        if( _cacheName == "") {
            MGlobal::displayError("must give -lc cacheFileName to load pose cache");
            return MS::kFailure;
        }
        if(_poseName == "") {
            MGlobal::displayError("must give -pa poseMeshName to create pose cache");
            return MS::kFailure;
        }
    }
    else if(_operation == tSavePose)
    {
        if(_cacheName == "") {
            MGlobal::displayError("must give -sp cacheFileName to save pose cache");
            return MS::kFailure;
        }
        if(_poseName == "") {
            MGlobal::displayError("must give -pa poseMeshName to save pose cache");
            return MS::kFailure;
        }
    }
    else if(_operation == tLoadPose)
    {
        if(_cacheName == "") {
            MGlobal::displayError("must give -lp cacheFileName to load pose cache");
            return MS::kFailure;
        }
        if(_poseName == "") {
            MGlobal::displayError("must give -pa poseMeshName to load pose cache");
            return MS::kFailure;
        }
    }
    else if(_operation == tCreate) {
        if(_poseName == "" || _bindName == "") {
            MGlobal::displayError("must give -pa poseMeshName and -bt bindMeshName to create pose cache");
            return MS::kFailure;
        }
    }

    return stat;
}