PDA

View Full Version : Acessing normals in MpxDeformerNode::deform


sirpalee
02-29-2008, 12:13 PM
My question is, how can I access the normals of a vertex in the deformer node deform function with the MItGeometry class... I've looked into the API ref, but I couldn't find it... It's not there, or I'm too blind.

Or I should use something else?

Thank you for any help...

ticket01
03-02-2008, 04:42 PM
Simply put - you can't. The Geometry iterator is only vor CVs, vertices, ... There's an example in the API docs how to use a compute rather than the deform method in an MPxDeformer node. This also shows how to get the mesh info in a deformer.

GennadiyKorol
03-02-2008, 07:44 PM
Hmm, I think you could do that using the data block you get in the deform function. You'd need to create another attribute for your deformer, called inMesh. You will need to it access the incoming shape data.

From there there are 2 possible ways:

1. Get a handle to the out mesh attribute of the node, throw the MFnMesh function set at it and get the normals with it (or using MItMesh<component> iterators).

But this will probably be slow thanks to the need to copy arrays every time the deform is called.


2. Get the handle to the normalPerVertex attribute of the mesh and query it to get your normals.

The latter one should probably be faster, but will give you per vertexface normals you'd need to deal with later on.


The good question here is why you want to do what you want to do. By following the good node principle, the node should explicitly get all the data it needs to perform the job. So if you need normals to do the job, wouldn't it be logical to create an input array attribute containing the normals of the geometry?

kjaft
03-03-2008, 12:40 PM
I did it the following way in the deform method using, identifying the input geometry and than using an appropriate iterator class (like MItMehsVertex in the example below): ::deform( MDataBlock& block, MItGeometry &iter, const MMatrix &localToWorld, unsigned int geomIndex )
{
...
MArrayDataHandle inputArray = block.inputArrayValue(input, &stat );
inputArray.jumpToElement( geomIndex );
MDataHandle inputGeomData = inputArray.inputValue( &stat );
MDataHandle inputGeomDataHandle = inputGeomData.child(inputGeom);

MObject inputObject = inputGeomDataHandle.data();

MVectorArray normals(iter.count());
// Poly Mesh
//
if (inputObject.apiType() == MFn::kMeshData) {
MFnMesh myMesh ( inputObject, &stat);
MCheckStatus (stat, "Couldn't get input geometry as mesh");
MItMeshVertex meshIt(inputObject);
for ( ; !meshIt.isDone(); meshIt.next()) {
// get Normals
stat = meshIt.getNormal(normals[meshIt.index()], MSpace::kWorld);
if (MS::kSuccess != stat) cout << "Error getting polygon normals" << endl;
}
}
// NURBS...etc

I got it to work also without the iterator building the loop on my own and using MfnMesh::getVertexNormal(...).

sirpalee
03-03-2008, 04:19 PM
Thank you all for the help, I'm still new to the maya api, and I need to learn much... :banghead:

CGTalk Moderation
03-03-2008, 04:19 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.