merged from trunk 20741:20848
[blender.git] / source / blender / editors / mesh / editface.c
index 6c17dff34280bcbc7b5c4f9bc7ebc337ae4b0b40..a6c5e5beccf051fc0ba5d4cc5736c48487ecb63d 100644 (file)
@@ -144,16 +144,6 @@ MTFace *EM_get_active_mtface(EditMesh *em, EditFace **act_efa, MCol **mcol, int
        return NULL;
 }
 
-static void make_tfaces(Object *ob) 
-{
-       Mesh *me= ob->data;
-       
-       if(!me->mtface) {
-               me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT,
-                                                NULL, me->totface);
-       }
-}
-
 void reveal_tface(Scene *scene)
 {
        Mesh *me;
@@ -676,7 +666,7 @@ void face_borderselect(Scene *scene, ARegion *ar)
        rcti rect;
        struct ImBuf *ibuf;
        unsigned int *rt;
-       int a, sx, sy, index, val;
+       int a, sx, sy, index, val= 0;
        char *selar;
        
        me= get_mesh(OBACT);
@@ -734,155 +724,4 @@ void face_borderselect(Scene *scene, ARegion *ar)
 #endif
 }
 
-/* Texture Paint */
-
-void set_texturepaint(Scene *scene) /* toggle */
-{
-       Object *ob = OBACT;
-       Mesh *me = 0;
-       
-       if(ob==NULL) return;
-       
-       if (object_data_is_libdata(ob)) {
-// XXX         error_libdata();
-               return;
-       }
-
-       me= get_mesh(ob);
-       
-       if(me)
-               DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
-
-       if(G.f & G_TEXTUREPAINT) {
-               G.f &= ~G_TEXTUREPAINT;
-               GPU_paint_set_mipmap(1);
-       }
-       else if (me) {
-               G.f |= G_TEXTUREPAINT;
-
-               if(me->mtface==NULL)
-                       make_tfaces(ob);
-
-               brush_check_exists(&scene->toolsettings->imapaint.brush);
-               GPU_paint_set_mipmap(0);
-       }
-
-}
-
-static void texpaint_project(Object *ob, float *model, float *proj, float *co, float *pco)
-{
-       VECCOPY(pco, co);
-       pco[3]= 1.0f;
-
-       Mat4MulVecfl(ob->obmat, pco);
-       Mat4MulVecfl((float(*)[4])model, pco);
-       Mat4MulVec4fl((float(*)[4])proj, pco);
-}
 
-static void texpaint_tri_weights(Object *ob, float *v1, float *v2, float *v3, float *co, float *w)
-{
-       float pv1[4], pv2[4], pv3[4], h[3], divw;
-       float model[16], proj[16], wmat[3][3], invwmat[3][3];
-       GLint view[4];
-
-       /* compute barycentric coordinates */
-
-       /* get the needed opengl matrices */
-       glGetIntegerv(GL_VIEWPORT, view);
-       glGetFloatv(GL_MODELVIEW_MATRIX, model);
-       glGetFloatv(GL_PROJECTION_MATRIX, proj);
-       view[0] = view[1] = 0;
-
-       /* project the verts */
-       texpaint_project(ob, model, proj, v1, pv1);
-       texpaint_project(ob, model, proj, v2, pv2);
-       texpaint_project(ob, model, proj, v3, pv3);
-
-       /* do inverse view mapping, see gluProject man page */
-       h[0]= (co[0] - view[0])*2.0f/view[2] - 1;
-       h[1]= (co[1] - view[1])*2.0f/view[3] - 1;
-       h[2]= 1.0f;
-
-       /* solve for (w1,w2,w3)/perspdiv in:
-          h*perspdiv = Project*Model*(w1*v1 + w2*v2 + w3*v3) */
-
-       wmat[0][0]= pv1[0];  wmat[1][0]= pv2[0];  wmat[2][0]= pv3[0];
-       wmat[0][1]= pv1[1];  wmat[1][1]= pv2[1];  wmat[2][1]= pv3[1];
-       wmat[0][2]= pv1[3];  wmat[1][2]= pv2[3];  wmat[2][2]= pv3[3];
-
-       Mat3Inv(invwmat, wmat);
-       Mat3MulVecfl(invwmat, h);
-
-       VECCOPY(w, h);
-
-       /* w is still divided by perspdiv, make it sum to one */
-       divw= w[0] + w[1] + w[2];
-       if(divw != 0.0f)
-               VecMulf(w, 1.0f/divw);
-}
-
-/* compute uv coordinates of mouse in face */
-void texpaint_pick_uv(Scene *scene, Object *ob, Mesh *mesh, unsigned int faceindex, short *xy, float *uv)
-{
-       DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
-       int *index = dm->getFaceDataArray(dm, CD_ORIGINDEX);
-       MTFace *tface = dm->getFaceDataArray(dm, CD_MTFACE), *tf;
-       int numfaces = dm->getNumFaces(dm), a;
-       float p[2], w[3], absw, minabsw;
-       MFace mf;
-       MVert mv[4];
-
-       minabsw = 1e10;
-       uv[0] = uv[1] = 0.0;
-
-// XXX persp(PERSP_VIEW);
-
-       /* test all faces in the derivedmesh with the original index of the picked face */
-       for (a = 0; a < numfaces; a++) {
-               if (index[a] == faceindex) {
-                       dm->getFace(dm, a, &mf);
-
-                       dm->getVert(dm, mf.v1, &mv[0]);
-                       dm->getVert(dm, mf.v2, &mv[1]);
-                       dm->getVert(dm, mf.v3, &mv[2]);
-                       if (mf.v4)
-                               dm->getVert(dm, mf.v4, &mv[3]);
-
-                       tf= &tface[a];
-
-                       p[0]= xy[0];
-                       p[1]= xy[1];
-
-                       if (mf.v4) {
-                               /* the triangle with the largest absolute values is the one
-                                  with the most negative weights */
-                               texpaint_tri_weights(ob, mv[0].co, mv[1].co, mv[3].co, p, w);
-                               absw= fabs(w[0]) + fabs(w[1]) + fabs(w[2]);
-                               if(absw < minabsw) {
-                                       uv[0]= tf->uv[0][0]*w[0] + tf->uv[1][0]*w[1] + tf->uv[3][0]*w[2];
-                                       uv[1]= tf->uv[0][1]*w[0] + tf->uv[1][1]*w[1] + tf->uv[3][1]*w[2];
-                                       minabsw = absw;
-                               }
-
-                               texpaint_tri_weights(ob, mv[1].co, mv[2].co, mv[3].co, p, w);
-                               absw= fabs(w[0]) + fabs(w[1]) + fabs(w[2]);
-                               if (absw < minabsw) {
-                                       uv[0]= tf->uv[1][0]*w[0] + tf->uv[2][0]*w[1] + tf->uv[3][0]*w[2];
-                                       uv[1]= tf->uv[1][1]*w[0] + tf->uv[2][1]*w[1] + tf->uv[3][1]*w[2];
-                                       minabsw = absw;
-                               }
-                       }
-                       else {
-                               texpaint_tri_weights(ob, mv[0].co, mv[1].co, mv[2].co, p, w);
-                               absw= fabs(w[0]) + fabs(w[1]) + fabs(w[2]);
-                               if (absw < minabsw) {
-                                       uv[0]= tf->uv[0][0]*w[0] + tf->uv[1][0]*w[1] + tf->uv[2][0]*w[2];
-                                       uv[1]= tf->uv[0][1]*w[0] + tf->uv[1][1]*w[1] + tf->uv[2][1]*w[2];
-                                       minabsw = absw;
-                               }
-                       }
-               }
-       }
-
-       dm->release(dm);
-}