MPxNode derived plugin that add faces + MultiUV + MultiMaterial = fail

MPxNode derived plugin that add faces + MultiUV + MultiMaterial = fail

olarn
Advocate Advocate
1,616 Views
8 Replies
Message 1 of 9

MPxNode derived plugin that add faces + MultiUV + MultiMaterial = fail

olarn
Advocate
Advocate

image.pngimage.png

 

Reproduction step

  1. Create a customized plugin
    1. Grab meshOpCmd or splitUV from devkit sample
    2. Pull every extra argument, plugs and mesh operation out and
    3. Replace fty's doIt method with:
      1. using mfn mesh addPolygon, add 1 new triangle to the mesh
  2. In Maya,
    1. Create some mesh that have at more than 1 faces. (do not delete history)
    2. Copy uv to new uv set.
    3. Make some modification to either uv set (this step may be optional)
    4. Assign at lease some faces to different shaders
    5. Apply customized plugin to mesh
    6. Apply any shaders to the new face
    7. New face's shader will look fine at this point, but will turn green when switching to another UV set.
      1. New face might look fine again when reassigned, but will turn back to green on UV set switch.

*On some large test mesh, cannot assign material to new face at all.

*only appears to happen to mesh with history

 

I think it might be an issue with component part id but can't find any documentation on a proper way to manage this manually. Any pointers will be great. (I have tried assigning group manually using MFnMeshData too, with no improvement)

0 Likes
1,617 Views
8 Replies
Replies (8)
Message 2 of 9

olarn
Advocate
Advocate

Bump

0 Likes
Message 3 of 9

olarn
Advocate
Advocate

bump

0 Likes
Message 4 of 9

olarn
Advocate
Advocate

bam

0 Likes
Message 5 of 9

BurkhardRammner
Collaborator
Collaborator

@olarn 

 

I didn`t understand exactly what you wanted to tell and whats happens where : (

...but...

- it looks like your data are overwritten by Maya. So, did you check that your face is part of the .inputComponents attribute?

If not, make sure that your node includes just every face and not a specific selection. You could use this mel-script:

//
//
// sciSetToAllInputComponents( {} );
//
//_____________________________________________________________
//
//
global proc sciSetToAllInputComponents( string $sel[] )
{
    string $sn = " // sciloop message :"+
                " mel: 'sciSetToAllInputComponents' :";

    if( !size($sel) )
    {$sel = ls( "-l", "-selection" );}

    if( !size($sel) )
    {
        print( $sn+" select at least one node, please.\n" );
        return;
    }

    int $hasInputComponents = false;

    for( $node in $sel )
    {
        string $attr = "";
        if( attributeExists("inputComponents", $node) )
        {
            $attr = ".inputComponents";
            $hasInputComponents = true;
        }
        else if( attributeExists("inputComponent", $node) )
        {
            $attr = ".inputComponent";
            $hasInputComponents = true;
        }

        if( $attr=="" )
        {continue;}        

        string $val[] = getAttr( $node+$attr );
        if( !size($val) )
        {continue;}

        string $buffer0[] = {};
        int $numTokens0 = tokenize( $val[0], "[", $buffer0 );
        string $type = $buffer0[0];

        if( $type=="vtx" || $type=="e" || $type=="f" )
        {
           $type = "\""+$type+"[*]\"";

           eval setAttr ($node+$attr)
                        -type "componentList"
                        1 $type;

            print( $sn+" set 'inputComponents' for "+
                    $type+" at node : '"+$node+"'\n" );
        }
    }

    if( !$hasInputComponents )
    {
        print( $sn+" no input node has a"+
                " '.inputComponents' attribute.\n" );
    }
    else
    { print( $sn+" done!\n" );}
}

//_____________________________________________________________
//
//

Does that help?

0 Likes
Message 6 of 9

olarn
Advocate
Advocate

Thank you for the response.

 

I have script to print out mesh component group data completely for every point up the node history but I don't have it right now.

 

Did you meant that when history is active newly added face should ideally  be given new groupid + groupnode on creation?

In that case how do one handle face/component deletion?
(Edit: theres attribute called inputRemoveComponent. Will try it out later..)

 

In case of no history this group info appeared to be saved in mesh node (inherited) attributed called compInstObjGroups

http://help.autodesk.com/cloudhelp/2018/ENU/Maya-Tech-Docs/Nodes/geometryShape.html

Setting these manually have no effect and got overwritten by upstream groupid nodes.

I have also tried messing with objectGroup/objectGroupComponent of

http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=__cpp_ref_class_m_fn_mesh_data_html

to add newly created faces with no results.

 

Also I've tried to come up with a simpler example but ended up as convoluted as the current one.

0 Likes
Message 7 of 9

BurkhardRammner
Collaborator
Collaborator

@olarn 

 

(in case you didn`t know or I misread your former posts):

If you want to have correct shading:

- every separately shaded face component group needs its own groupId, which has to be given to the mesh node via a groupId node. It doesn`t matter if the mesh node has input mesh data or not.

- also, you have to add to the mesh data via the use of 'MFnSingleIndexedComponent', 'MFn::kMeshPolygonComponent', 'MFnComponentListData' the face group data to it.

- the shadingEngine nodes need the groupId data from the groupId nodes you created

 

 

..mmmh...does this help?

0 Likes
Message 8 of 9

olarn
Advocate
Advocate
- every separately shaded face component group needs its own groupId, which has to be given to the mesh node via a groupId node. It doesn`t matter if the mesh node has input mesh data or not.

I get it but it's a bit more complicated when there's history. new modification have to play nice with upstream info.

I will give it another try.

also, you have to add to the mesh data via the use of 'MFnSingleIndexedComponent', 'MFn::kMeshPolygonComponent', 'MFnComponentListData' the face group data to it.

From last few week experiment, when there is history, this information got lost the next time node got dirtied. Instead inserting groupid node upstream might work.

0 Likes
Message 9 of 9

BurkhardRammner
Collaborator
Collaborator

Yes, with history, you would have to account for changes in face count by creating new groupId node(s)/group data inside your node...

0 Likes