Feedback

What's your question?

By: [ Editor ] Asked from United States of America

Maya API...getting normal from the deform method?

I'm new to Maya API and I'm going around in circles. With the deform method, I'm using MItGeometry. This allows me to get the position of a vertex. But not the normal. How do I get the normal of the vertex?

I only have MDataBlock and MItGeometry and MMatrix to work with. What I find most frustrating about the API is the lack of feedback. With Mel, I can print back variables to see what I have to work with. With the API, I'm blind. Please point me in the right direction.

Thanks in advance

Add comment viewed 372 times Latest activity 11 months ago

or Cancel

2 answers

  • 0

maulik13 [ Editor ]

Deformer always has an incoming attribute inputGeom under input[i] compound attribute. You could get mesh as MObject like this:

// get the connected geometry mesh, it is connected to input[i].inputGeom
MArrayDataHandle hInputArr = data.inputArrayValue(input, &mstat);
hInputArr.jumpToElement(multiIndex);
// this is a data handle to index[multiIndex]
MDataHandle hInputData = hInputArr.inputValue(&mstat);
// this is a data handle to index[multiIndex].inputGeom
MDataHandle hInputGeom = hInputData.child(inputGeom);
MObject inputMesh = hInputGeom.asMesh();

multiIndex comes from deform method and inputGeom is inherited property from MPxDeformerNode

NN comments
manny
-

Thank you very much. I’ll try this out.

or Cancel
  • 0

julian [ Admin ]

Hi Manny, I think the problem is that the deform method gets points that could come from a surface or a curve or particles, or any combination of those, so there aren't always normals available. Having said that, if you know you will have normals available that match points you can get them in the deform method, but not from the MItGeometry. (I don't think MItGeometry knows what object it came from and it only holds points). Instead get the normals separately and check that the counts match.

In a simple implementation, when you know its a mesh, add a mesh attribute to the node and use the MDataBlock to get a dataHandle to the mesh object and create a MItMeshVertex from that object.

MItMeshVertex vtxIter(inMeshObject, &status); 

Then in the loop in the deform method you can use the index of the current point to get the normal from the equivalent element of the MItMeshVertex you just created:

MVector normal;
int uselessInt = 0;
for ( iter.reset(); !iter.isDone(); iter.next() ) {
    vtxIter.setIndex(iter.index(), uselessInt);
    vtxIter.getNormal(normal, MSpace::kWorld);
    // do something with the normal such as push the point along it
}

You should probably check that the MItMeshVertex has the same number of vertices as the MItGeometry. They both have a count() method.

--

to print out variable values you can use cerr. You need to include MIOStream.h

example:

MVector normal(1,0,0);
cerr << "value of normal is" << normal << endl; // prints the value of normal. endl is a new line.

it works for arrays and matrices and any MString and more.

For example

cerr << myDagPath.partialName() << endl;
cerr << myVectorArrayFunctionSet.array() << endl;

Hope it helps.

NN comments
manny
-

Hi Julian, I was trying to some how get to MItMeshVertex. But I can’t remember why I couldn’t. I was hoping you’d point me in the right direction. Now I know I was on the right path. Again, this whole process would be much easier for me if I could somehow print back values. Like in Mel. I guess it’s just a painful learning process. Again, thanks for your help as always.

manny
-

I am using the “yTwistNode.py” example and changing things to try to do what I wanted to do. Can anyone tell me how to create an MItMeshVertex in this example? I’m still trying to make sense of all this. Like what is “self”? When I look in MPxDeformerNode, there is no “init” function. Is there a book somewhere that I can read up on this to have it all make sense?

or Cancel