[Bf-committers] Select Same UV > Select Same Mat

Campbell Barton bf-committers@blender.org
Thu, 17 Jun 2004 10:02:36 +1000


Hi, Im modifying Goofsters *Sel Same UV *function into a select same 
Material func.

This function below works when the face has a UV image applied (has a 
TFace) or has had a TFace and then had it removed.

Is there a way to work out weather a face is active (in face select 
mode) without using TFace???

- Thanks
 Cam

 /* Selects all faces which have the same material as the active face
 * @author    Roel Spruit, adapted by Campbell Barton
 * @return    Void
 * Errors:    - Active object not in this layer
 *        - No active face or active face has no UV-texture           
 */
void get_same_mat(void)
{
    Object *ob;
    Mesh *me;
    TFace *tface;
    MFace *mface;
    short a, foundmat=0;
    unsigned char *mat;
    unsigned char *active_mat;
    ob = OBACT;
    if (!(ob->lay & G.vd->lay)) {
        error("The active object is not in this layer");
        return;
    }
    me = get_mesh(ob);
   
       
    /* Search for the active face with a UV-Texture */
    tface = me->tface;
    mface = me->mface;
    a = me->totface;
    while (a--) {       
        if(tface->flag & TF_ACTIVE){           
            mat=mface->mat_nr;
            if(mat){       
                a=0;
                foundmat=1;
                active_mat = mat;
            }
        }
        tface++;
        mface++;
    }       
   
    if(!foundmat) {
        error("No active face, or active face has no UV texture");
        return;
    }

    /* select everything with the same material */
    tface = me->tface;
    mface = me->mface;
    a = me->totface;
    while (a--) {       
        mat=mface->mat_nr;
        if(mat){
            if(mat == active_mat){
                tface->flag |= TF_SELECT;
            }
            else tface->flag &= ~TF_SELECT;
        }
        else tface->flag &= ~TF_SELECT;
        tface++;
        mface++;
    }
   

   
    /* image window redraw */
    allqueue(REDRAWIMAGE, 0);
    allqueue(REDRAWVIEW3D, 0);
}