MFnMesh.getPoints returns only (0,0,0) when using MSpace::kWorld

Anonymous

MFnMesh.getPoints returns only (0,0,0) when using MSpace::kWorld

Anonymous
Not applicable

When I use getPoints in MSpace::kObject like this, I get the right (object) points:

 

	MSelectionList selList;
	MGlobal::getActiveSelectionList(selList, true);
	MItSelectionList selListIt(selList);
	if(!selListIt.isDone()) {
		MDagPath mesh_dagpath;
		selListIt.getDagPath(mesh_dagpath);
		mesh_dagpath.extendToShape();
		MObject maya_mesh = mesh_dagpath.node();
		MFnMesh meshFn(maya_mesh);
		meshFn.getPoints(points, MSpace::kObject);
		// Do something with the points
	} else {
		MError("No mesh selected.");
	}

But when I use MSpace::kWorld instead of MSpace::kObject, all vertices are (0,0,0).

I already tried to use

MFnDagNode dagNodeFn(maya_mesh);
maya_mesh = dagNodeFn.parent(0);

because I suspect that getPoints is missing the transform node of the mesh, but it did not work either.

What do I need to do to get the right world coordinates?

0 Likes
Reply
Accepted solutions (1)
631 Views
2 Replies
Replies (2)

zewt
Collaborator
Collaborator
Accepted solution

Check the return value of getPoints.  It's returning a "Must have a DAG path to do world space transforms" error.  To fix it, just construct the MFnMesh with the MDagPath object rather than the shape node's MObject, so it knows which instance of the mesh you're working with.

 

0 Likes

Anonymous
Not applicable

Thank you, that was indeed the problem (and shame on me for not checking the status).

Working code snippet:

// in: MObject maya_mesh; MSpace space;
// out: MPointArray points;
MFnMesh meshFn(maya_mesh); if(space == MSpace::kWorld) { MDagPath dagPath = MDagPath::getAPathTo(maya_mesh, &status); MCheckStatus(status, "Could not find a DagPath to the mesh."); meshFn.setObject(dagPath); }
MPointArray points; status = meshFn.getPoints(points, space); MCheckStatus(status, "Could not get mesh points.");
0 Likes