View Full Version : read PP Attrs in node API
07-18-2011, 08:29 PM
I'm trying to write a custom maya particle (old style particle not nParticle) cache system. I've already got a prototype file format and cache reader working with hand written binary file and a custom emitter. However I'm now moving on to the exporter node and failing at the first hurdle.
Simply I want to read all PP attributes including user created. I've looked at using MFnParticleSystem inside a fieldNode for starters. Ideally i'll start from scratch with MPxNode derived class with a compound attribute input connected to out ppFieldData? however i'm open to any suggestion! Simply listing all the PP attributes of a particleShape has me stumped!
This is what i've tried so far for retrieving the standard position PP attr.:
MFnParticleSystem particleSystem(mInputPPData, &status);
for(int b=0; b < (int)vecArray.length(); b++)
std::cout << "position x: " << vecArray[b].x << std::endl;
std::cout << "position y: " << vecArray[b].y << std::endl;
std::cout << "position z: " << vecArray[b].z << std::endl;
any help or *pointers to the correct &location in the docs would be fantastic!
07-18-2011, 09:06 PM
it's been a long time since I dealt with pps. doesn't getPerParticleAttribute method give you what you need? if it does not, do you have any error from status?
07-19-2011, 04:17 PM
I'm passing the wrong MObject in the above code, i'll use a dagPath instead I think. The problem really stems from the fact that I can't find a way to list all the PP attributes (including custom user PP Attrs) . If I could get these I can just loop through the above for each attr.
I tried listing from fieldPPData input on a field but it only seems to list <nameOfFieldNode>_<AttributeName> from the PP Attrs eg: myField1_myPPAttr would output "myPPAttr"
int multiIndex = plug.logicalIndex( &status );
MArrayDataHandle mhInputPPData = block.inputArrayValue( mInputPPData, &status );
status = mhInputPPData.jumpToElement( multiIndex );
MDataHandle hInputPPData = mhInputPPData.inputValue( &status );
MObject dInputPPData = hInputPPData.data();
MFnArrayAttrsData inputPPArray( dInputPPData );
MStringArray listOfAtts = inputPPArray.list();
for(int d = 0; d < (int)listOfAtts.length(); d++)
std::cout << listOfAtts[d].asChar() <<std::endl;
There aren't any members of MFnParticleSystem to list PP Attrs either so im a little stumped... have I missed something somewhere?
I'm working back from the dynExprField from the api examples.
Again, any help would be much appreciated!
07-20-2011, 07:24 AM
you could list all the attributes of the node, and use MFnParticleSystem::isPerParticle*Attribute() to check if it is a PP attribute.
07-20-2011, 07:52 PM
Hi whisperwing thanks very much for that. Unfortunately I can't work out why isPerParticleVectorAttribute would cause maya to crash without error consistently. Commenting out the line and everything works perfectly listing attributes and from what I can see everything is initialized correctly. Really clueless to this bizarre crash.
MObject particleShapeNode = plugArray.node(&status);
MString partiNodeName = particleShapeDepNodeFn.name();
std::cout << "particleShapeNodeName: " << partiNodeName.asChar() << std::endl;
int attrNum = particleShapeDepNodeFn.attributeCount(&status);
std::cout << "Listing Attrs"<< std::endl;
MFnParticleSystem particleSystem(particleShapeNode, &status);
partiNodeName = particleSystem.name();
std::cout << "particleShapeNodeName2: " << partiNodeName.asChar() << std::endl;
for (int ii=0; ii < attrNum; ii++)
attrObject = particleShapeDepNodeFn.attribute(ii,&status);
MString attrName = attribute.name();
bool test = particleSystem.isPerParticleVectorAttribute(attrName,&status);
std::cout << attrName.asChar() << std::endl;
std::cout << "End listing attrs"<< std::endl;
Any help would be appreciated!
07-20-2011, 08:00 PM
Unfortunely I think Maya did crash sometimes if you use this function with the wrong type of attribute (ironic isn't it :p)
Maybe you could try check the attribute by MObject::apiType() and see if it is of type kVectorArrayData, etc, make sure the type is compatible and then use the corrensponding isPerParticle*Attribute() function to see if it is a PP attribute. Hope this would work.
07-23-2011, 04:43 PM
I've gotten there eventually... the was crash a pain and only happens when trying to create a new scene then calling the unload plugin mel command. Anyway I eventually got round it using isDynamic() as the fact that an attribute might not be dynamic would cause the is isPerParticle*Attribute function crash.
Cheers for the help!
07-23-2011, 04:43 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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.