Maya2egg and the <Tag> entry

Greetings all!

We have a couple of models that start in Maya in which we’d like to tag specific model components with some dynamic properties that range across a large set of options. In general, we have been using the egg-object-type tagging technique in Maya to accomplish goals like this: we define a new egg-object-type, add it to our .mel script that can tag Maya groups (using the ‘addAttr’ command), then add the necessary transformation to our .PRC file to cause the models imported with the flag to have sections of their entries substituted appropriately.

The issue we have now is that with the wide range of possible values for our new property, we’ll need to add dozens of egg-object-types to allow for all of them. Ideally, I’d like to skip the egg-object-type step and use Maya to tag a group in such a way that it is output containing the " key {value}" entry documented in the egg syntax manual. Unfortunately, I’m very new to .mel scripting; I’m afraid I have no idea how to make this happen.

Does anyone know what the code would look like to apply this kind of variable tag such that maya2egg will respect it and output a " key {value}" entry? Optionally, some information to get around my knowledge block could also work; if I better understood the ‘addAttr’ command in mel, I could probably cook up a script to do what we need.

Any help on this front would be greatly appreciated!

Thanks,
Mark

Sorry, we’ve never implemented that sort of thing in maya2egg. All you can output right now is keys, not values.

It wouldn’t be hard to do, though. Surely an industrious Maya user would be interested in designing the relevant mel script and possibly even adding the five lines of code to maya2egg to support it?

David

Does anyone who might be familiar with the construction of maya2egg know where we could start if we wanted to add a mel script to maya2egg? We don’t exactly have the resources to start sifting through all that code right now, and it would be great if anyone could point us in the right direction.

Thanks so much.

There are no mel scripts within maya2egg; it’s all written using the C++ OpenMaya API.

I meant that someone would have to write a new mel script, similar to eggObjectFlags.mel, that would save an attribute on a node that maya2egg could then identify and extract.

Presently, eggObjectFlags.mel is a simple mel script that adds an attribute called “eggObjectTypes” to a Maya node. As it happens, maya2egg is written to look for an attribute called “eggObjectTypes”; when it finds it, it outputs the corresponding { key } sequence to the egg file.

It would be possible to do this again with a different mel script that added an attribute for a key:value pair, and extending maya2egg to identify this attribute and output the appropriate tag sequence to the egg file.

David

How timely- I’m just hitting up against this topic as well.

One question, the maya2egg converter has a hard coded limit of 3 eggObjectTypes. I haven’t found anything indicating this limit is there for a particular reason- is it?

No particular reason, other than there had to be some limit. The maya2egg code looks for attributes named specifically “eggObjectTypes1”, “eggObjectTypes2”, and “eggObjectTypes3”.

If you really need more than three such tags, you’ll have to modify the maya2egg code to add enough additional cases. Or, consider using nested nodes. Or you can create special composite tags: one tag that outputs the same code as multiple different individual tags.

David

thanks! for now we’ve decided to work with the 3 tag limit but we’ve made a separate mel script for this special type of eggObjectType. The benefits we’ve found for making a separate script are:

  1. Ability to guarantee only 1 of a certain type of flag: ie, say you want a flag that indicates the type of animal something is and you only want each object to be flagged as one type of animal- you can’t be an elephant and a donkey at the same time. Having a separate script allows you to check in maya if that eggObjectType has already been assigned to that particular object.

  2. Also conveniently this breaks up our ever growing list of eggObjectType flags. This way our artist doesn’t have to look through the entire lists (possibly physics tags, hide, dcs, object type, or any number of other things you might want to tag for).

The only tricky parts to setting up this second script was getting it to deal well with the 3 ‘eggObjectType flags only’ limit and enforce the ‘only one flag of this type’ limit, as well as getting the flag field to have a specific name in the maya interface instead of appearing like just another eggObjectType field.

The way we did the latter was to take advantage of maya’s long name and short name flags when adding attributes:

addAttr -ln ($NameForInterface) -sn ($EggObjectTypeName) -k 1 -at enum" -en "customType1;customType2;custumType3;l"  $i;

(this is mel script based off the existing flag mel script for panda3D- refer to that script to see how this fits into the full script!)

Here -ln means ‘long name’ and -sn means ‘short name.’
Long name is how the attribute will be labeled in the maya interface.
Short name is how maya will store the attribute internally (and what will be used by Maya2Egg apparently.) This should always be ‘eggObjecType1’ or ‘eggObjectType2’ or ‘eggObjectType3.’

When you use the addAttr line above, the flag will appear in the Maya interface as
Name For Interface [ customType1 ]

Now that you’ve differentiated this special flag type’s long name from other eggObjectType flags, you can restrict your artists to only one use of this flag per object by searching for an existing attribute:

if( `attributeQuery -ex -n $i $NameForInterface` ) 

oh, and incidentally, we use a simple naming scheme to convert these tags to tag:value pairs… you know, your line in config.prc would be something like:

egg-object-type-doganimal      <Tag> animal { dog }

** Our actual flag in maya is dogAnimal for readability but the .prc entry should be all lowercase!

hope this helps other people!

if anybody is still interested in using the egg tags from within maya: i added some simple support for this to the maya2egg code.

in pandatool\src\mayaegg\mayaNodeTree.cxx at line 372 (after the add_object_type stuff) i added:

      MStatus status;
      string attrValue;
      MFnDependencyNode node_fn(dag_object, &status);
      if (!status) {
        maya_cat.error()
        << "Object is a " << dag_object.apiTypeStr() << ", not a DependencyNode.\n";
      }
      else {
        int cnt = node_fn.attributeCount ( &status );
        MObject attrObj;
        for (int i = 0; i < cnt; i++) {
           attrObj = node_fn.attribute(i, &status);
           if (!status) {
             maya_cat.error()
             << "cannot retrieve attribute object %i" << i << "\n";
             continue;
           }

           MFnAttribute attr(attrObj, &status);
           if (!status) {
             maya_cat.error()
             << "cannot convert attribute %i" << i << "\n";
             continue;
           }

           //only take attributes which begin with "tegg" and remove this part from their shortnames
           string attrName = attr.shortName(&status).asChar();
           if (attrName.substr(0, 4) == "tegg") {
              string keyName = attrName.substr(4);
             if (get_string_attribute(dag_object, attrName, attrValue)) {
               egg_group->set_tag(keyName, attrValue);
             }
           }
        }
      }

this searches for attributes whose short name begin with “tegg” and which are of type string, removes the “tegg” part from the attribute name and adds this stuff as a egg tag.

replace “tegg” with whatever you want, i just chose this to be sure that no attributes that are already in maya are chosen for egg-tagging, and as maya-noob i had no idea of how to get user defined “extra” attributes.