상세 컨텐츠

본문 제목

How do I create and access a MMatrix attribute?

Maya API/Maya_API

by hwano 2014. 2. 6. 16:14

본문

 

 

http://www.comet-cartoons.com/3ddocs/mayaAPI/

 

 

How do I create and access a MMatrix attribute?

	// For creation:
	//
	#include <maya/MFnNumericAttribute.h>

	// Then inside of the initialize function for your plugin:
	MFnMatrixAttribute  mAttr ;
	aMatrix = mAttr.create( "myMatrix", "m" );

	// To access it from an MDataHandle inside of a compute or deform call
	// where the MDataBlock is called data:
	//
	MDataHandle hMatrix = data.inputValue(aMatrix, &stat );
	MMatrix mat = hMatrix.asMatrix();	// Now get it
	MMatrix invmat = mat.inverse();		// and the inverse too.


	// To access it from an MPlug in a node, you must include
	// MPlug.h and MFnMatrixData.h and then do something as follows:
	//
	MObject thisNode = thisMObject();	// Get this actual plugin node's MObject...that's us!

	MPlug plugMat( thisNode, aMatrix );	// find our attribute plug on ourselves
	MObject oMat ;
	plugMat.getValue( oMat );		// For matrix plugs, have to get as MObject
	MFnMatrixData fnMat( oMat );	// Then take that to a MfnMatrix Data.    
	MMatrix mat = fnMat.matrix() ;  // Then finally get the matrix out from that.
	MMatrix invmat = mat.inverse() ; // and get inverse too...

 

관련글 더보기