Jump to content

Querying attributes from one geo to another


bandini

Recommended Posts

I am trying to do this in an attribute wrangle. I want the user to be able to input a list of attributes to copy and then the wrangle does all the work, grabbing each attribute from the list and performing some function on it. The problem I have is that I need to run a bunch a queries about the attribute (size, type, etc.) and then create big blocks of comparison statements to fill out the appropriate function definitions for the addattrib() function, as they are type specific. I am wondering if there is an easy generic way of doing this that I am missing.

Link to comment
Share on other sites

Guest mantragora

Do I understand this right...

 

1. You want to have only list of attributes and then AttributeWrangleSOP should go thru each and figure out their type, size etc., on its own?

2. Or will there be specified type and size and you just want to have universal (one, not many for each type, size) addAttribute() version that will add any type/size specified by user?

3. None of this.

 

...?

Edited by fântastîque Mântragorîè
Link to comment
Share on other sites

#1 is pretty close. (Should only be point attributes)

 

Maybe posting the code will show a little bit of what I am doing and where it gets a bit ugly... I am copying attributes from a parametric uv surface onto some geo that is deformed onto that surface, using a custom deformer. I don't know what attributes the user will assign to the parametric surface, and I want to give the user the most flexibility possible. Seems like string values don't make much sense, but I can make a case for most other values.

 

 

string attributes[] = split(chs("curve_attributes"));
 
foreach (string attribute; attributes)
{
    int attribsize = attribsize(@OpInput2, "point", attribute);
    
    if(attribsize == 1)
    {
        if(pointattribtype(@OpInput2, attribute) == 0)
        {
            int puv = primuv(1, attribute, 0, v@curveuv);
            addattrib(0, "point", attribute, puv);
            setpointattrib(geoself(), attribute, @ptnum, puv, "set");
        }
        if(pointattribtype(@OpInput2, attribute) == 1)
        {
            float puv = primuv(1, attribute, 0, v@curveuv);
            addattrib(0, "point", attribute, puv);
            setpointattrib(geoself(), attribute, @ptnum, puv, "set");
        }
    }
    if(attribsize >= 1 && attribsize < 5)
    {
        vector puv = primuv(1, attribute, 0, v@curveuv);
        addattrib(0, "point", attribute, puv);
        setpointattrib(geoself(), attribute, @ptnum, puv, "set");
    }
    if(attribsize == 9)
    {
        matrix3 puv = primuv(1, attribute, 0, v@curveuv);
        addattrib(0, "point", attribute, puv);
        setpointattrib(geoself(), attribute, @ptnum, puv, "set");
    }
    if(attribsize == 16)
    {
        matrix puv = primuv(1, attribute, 0, v@curveuv);
        addattrib(0, "point", attribute, puv);
        setpointattrib(geoself(), attribute, @ptnum, puv, "set");
    }
}
Edited by bandini
Link to comment
Share on other sites

Guest mantragora

That's my 5 AM logic :)

string names = chs("names");
string attributes[] = split(names);
 
foreach (string attrib; attributes)
{
    // possible types
    int puvI = 0;
    float puvF = 0.0;  
    vector2 puvV2; 
    vector puvV3; 
    vector4 puvV4; 
    matrix3 puvM3;
    matrix puvM4;   
    
    // test variables
    int type = pointattribtype(@OpInput1, attrib);    
    int size = attribsize(@OpInput1, "point", attrib);
      
    // manage int and float
    if (size == 1)
    {        
        if (type) { puvF = primuv(1, attrib, 0, v@curveuv); printf("float\n");}
        else { puvI = primuv(1, attrib, 0, v@curveuv); printf("int\n");}
        
        addattrib(0, "point", attrib, (type? puvF: puvI));
        setpointattrib(geoself(), attrib, @ptnum, (type? puvF: puvI), "set");          
    }
        
    // manage vector2, vector3, vector4
    else if (size > 1 && size < 5)
    {   
        if (size == 2) { puvV2 = primuv(1, attrib, 0, v@curveuv); printf("vector2\n");}
        else if (size == 3) { puvV3 = primuv(1, attrib, 0, v@curveuv); printf("vector3\n");}
        else if (size == 4) { puvV4 = primuv(1, attrib, 0, v@curveuv); printf("vector4\n");}
        
        addattrib(0, "point", attrib, (size == 4? puvV4: size == 2? puvV2: puvV3));
        setpointattrib(geoself(), attrib, @ptnum, (size == 4? puvV4: size == 2? puvV2: puvV3), "set");  
    }
    
    else if (size > 8)
    {
        // manage matrix3, matrix4
        if (size < 16) { puvM3 = primuv(1, attrib, 0, v@curveuv); printf("matrix3\n");}
        else { puvM4 = primuv(1, attrib, 0, v@curveuv); printf("matrix4\n");}
 
        addattrib(0, "point", attrib, (size < 16? puvM3: puvM4));
        setpointattrib(geoself(), attrib, @ptnum, (size < 16? puvM3: puvM4), "set");      
    }
}
Edited by fântastîque Mântragorîè
Link to comment
Share on other sites

Guest mantragora

I don't think it works...

 

It detects attribute correctly, name it correctly, but it always creates wrong type, despite that it gets correct type into addAttribute() send.

 

... or maybe I should finally go sleep?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...