PDA

View Full Version : Getting transform matrix data handle


onticd
12-14-2012, 03:29 AM
I know the transformation components could be retrieved individually, but I'm trying to get a reference to a single matrix output. The code below ends up producing an invalid handle type and 0 matrix.

Also, is it not possible to pipe a matrix as an input to a transform?

if ( plug == aOutput )
{
MDataHandle hInMatrix = data.inputValue( aInMatrix, &status );

cout << "data type: " << hInMatrix.type() << endl;

if ( status != MS::kSuccess )
{
cout << "ERROR getting data" << endl;
}
else
{
MObject oInMatrix = hInMatrix.data();
MFnMatrixData fnInMatrix( oInMatrix, &status );
MTransformationMatrix oInTranMatrix = fnInMatrix.transformation( &status );
MVector vInTran = oInTranMatrix.getTranslation( MSpace::kWorld, &status );

zoharl
12-14-2012, 07:32 AM
Make sure you connected the aInMatirx in the init. To retrieve a matrix the code would be something like:

MDataHandle matrixHandle = spheresMatricesArray.inputValue();
MMatrix mat = matrixHandle.asMatrix();

You didn't say where it failed. Maybe your connection is wrong. Anyway, this connecting a matrix to a deformer is a standard procedure, and you should be able to find in the devkit enough examples.

onticd
12-14-2012, 08:41 PM
Thanks Zohar. Creating an MMatrix object instead of an MObject to MFnMatrixData object worked. I was basing the design off the MFnMatrixData reference.

If a user written dependency node either accepts or produces MMatrix, then this class is used to extract or create the data that comes from or goes to other dependency graph nodes. The MDataHandle::type method will return kMatrix when data of this type is present. To access it, the MDataHandle::data method is used to get an MObject for the data and this should then be used to initialize an instance of MFnMatrixData.

MDataHandle hInMatrix = data.inputValue( aInMatrix, &status );

cout << "data type: " << hInMatrix.type() << endl;
Using the above, I was getting a kInvalid type return. I was thinking the handle would know that a matrix was connected. Maybe I'm misunderstanding the reference material.

MObject oInMatrix = hInMatrix.data();
MFnMatrixData fnInMatrix( oInMatrix, &status );
MTransformationMatrix oInTranMatrix = fnInMatrix.transformation( &status );
MVector vInTran = oInTranMatrix.getTranslation( MSpace::kWorld, &status );
Is the above section not how the reference intends for the setup to be made?

zoharl
12-14-2012, 10:33 PM
I didn't suggest that what you did is wrong, I only suggested that you are trying to do a basic thing (you asked if it's possible), and there might be a few reasons why it doesn't work for you, and I offered a way that worked for me.

I must admit that I just copied the code from somewhere, it worked, and I was fine with it. I didn't delve into it too much, because it's just an arbitrary interface. Looks to me that your code should work, especially according to the doc. The example torusField.cpp in the devkit seems to work this way. But maybe there is a difference between MFnMatrixData and MMatrix, and it matters in the context that you use it. Anyway, I don't have something under my hand at the moment to play with and get to the bottom of this. But if it interests you, I suggest you would take a working example like the torusField and replace the MFnMatirxData with MMatrix data, and verify if the two methods are synonyms. If they are, then try to understand why your code doesn't work. If they aren't, then try to understand how the plugins nodes are different, and how are the matrix objects are different.

CGTalk Moderation
12-14-2012, 10:33 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.