[API] groupId not recognized


#1

This is probably a question for you, keilun : )
I am referring to this thread :
http://forums.cgsociety.org/showthread.php?f=89&t=658510&highlight=groupId

I am facing the same problem as flaiver.
So, I created a ‘executeCommandOnIdle’, successfully created the groupId nodes and connected them to my node. In the next ‘compute’ cycle, them mesh was created and the face components ( for the shadingEngine ) were added.
But when I wanted to add the groupId with ‘MFnMeshData::addObjectGroup’, Maya tells me that the object does not exist.
I know it exists because I got the groupId data from the connected groupId node and the value is fine.

So, what did I forget to do?

here`s the code

for( unsigned i=0; i<faceIndicesInObjectGroupArr.size(); i++ )
{
 MFnComponentListData polygonComponentListFn;
 MObject polygonComponentData = polygonComponentListFn.create();

 MFnSingleIndexedComponent singleIndexedComponentFn;
 MObject polygonFacesM = singleIndexedComponentFn.create( MFn::kMeshPolygonComponent, &stat_ ); ME( stat_ );
 ME( singleIndexedComponentFn.addElements( faceIndicesInObjectGroupArr[i] ) );
 ME( meshDataFn.addObjectGroup( (unsigned)groupIdVec[i] ) ); -> error : object does not exist

thanks for your help!


#2

The last couple posts in the flaiver thread cover the error that you’re running into. You don’t want to be using MFnComponentListData. That’s for attributes of type component list. To populate an MFnSingleIndexedComponent you just need to pass in the integer array. Have a look at that 2nd last post in the thread you linked and post back if you’re still having troubles.

You also need to create the MFnMeshData first. You’re missing the MFnMeshData.create() call before you addObjectGroup to the mesh data. Or at least it isn’t shown in your code snippet.


#3

Oops, the ‘MFnComponentListData’ does nothing, I never used it (I know its for compacting the indices).

I didn`t show the code for that, but its there:

MFnMeshData meshDataFn( omesh );

And it also owns a true mesh.

So, actually the code is as you suggested…


#4

Can you confirm you’re getting the correct groupIds from the nodes you’ve generated and connected and double check it against the groupId node that you’ve created?

Also double check the mesh data to make sure it’s valid just before you add your objectGroup. Read some data off of it with MFnMesh. Do more double checking on all of your data. I’m afraid that’s the best advice I can give now as it seems to me it just needs some debugging. Nothing in the code you’ve shown stands out as problematic.


#5

Keilun,

the mesh data is fine ( I get the correct polygon mesh ).
The groupId nodes and their groupId data are fine.

steps:

  1. compute counter: 1 -> create the relevant groupId nodes, connect the necessary attributes (done with Mel : MGlobal::executeCommandOnIdle).
  2. compute counter: 2 -> create the output mesh, add the component/groupId data.

#6

I would put a debug statement right before you call the erroneous addObjectGroup and do something like:

MStatus stat;
MFnMesh meshFn( meshDataFn.object(), &stat );
ME( stat );

See if that works. The only case where addObjectGroup returns an error is if the MObject that your MFnGeometryData/MFnMeshData is invalid.

Also, your posts seem to indicate that this node generates a mesh, but your code looks like it’s modifying an existing mesh. If this were a generator, I would expect to see an MFnMeshData.create() not:

MFnMeshData meshDataFn( omesh );

#7

Keilun,

that solved it!
The mesh was created with another MFnMeshData in another code location.
Here, I created a new MFnMeshData with the constructor : MFnMeshData(const MObject &object).
Unfortunately, my mesh is obviously currently not a valid Maya object…so that didn`t work.

So, many thanks for your great help, it works now : ) ) )

edit : I grabbed the other MFnMeshData for the groupId operations, which worked.