merge with trunk at r31523
[blender.git] / source / blender / editors / mesh / meshtools.c
index 00893f10165228504fb7216c9ad195bb3bd750c3..35e1a0975e51ce03d1e7662660322e2ba62c37f3 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * $Id
+ * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2004 by Blender Foundation
  * All rights reserved.
@@ -31,6 +31,7 @@
        meshtools.c: no editmode (violated already :), tools operating on meshes
 */
 
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
 
 #include "MEM_guardedalloc.h"
 
-#include "DNA_image_types.h"
 #include "DNA_key_types.h"
 #include "DNA_material_types.h"
 #include "DNA_meshdata_types.h"
-#include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_space_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_windowmanager_types.h"
-#include "DNA_world_types.h"
 
-#include "BLI_arithb.h"
+#include "BLI_math.h"
 #include "BLI_blenlib.h"
 #include "BLI_editVert.h"
 #include "BLI_ghash.h"
 #include "BLI_threads.h"
 
 
-#include "BKE_blender.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
-#include "BKE_customdata.h"
-#include "BKE_global.h"
-#include "BKE_image.h"
+#include "BKE_deform.h"
+#include "BKE_DerivedMesh.h"
 #include "BKE_key.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_material.h"
-#include "BKE_object.h"
-#include "BKE_utildefines.h"
 #include "BKE_report.h"
-
-#include "RE_pipeline.h"
-#include "RE_shader_ext.h"
-
-#include "PIL_time.h"
-
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-
-#include "GPU_draw.h"
+#include "BKE_tessmesh.h"
 
 #include "BLO_sys_types.h" // for intptr_t support
 
 /* own include */
 #include "mesh_intern.h"
 
-/* XXX */
-static void waitcursor(int val) {}
-static void error() {}
-static int pupmenu() {return 0;}
-/* XXX */
-
 
 /* * ********************** no editmode!!! *********** */
 
@@ -112,6 +87,7 @@ return 0 if no join is made (error) and 1 of the join is done */
 
 int join_mesh_exec(bContext *C, wmOperator *op)
 {
+       Main *bmain= CTX_data_main(C);
        Scene *scene= CTX_data_scene(C);
        Object *ob= CTX_data_active_object(C);
        Material **matar, *ma;
@@ -119,15 +95,17 @@ int join_mesh_exec(bContext *C, wmOperator *op)
        MVert *mvert, *mv, *mvertmain;
        MEdge *medge = NULL, *medgemain;
        MFace *mface = NULL, *mfacemain;
+       MPoly *mpoly = NULL, *mpolymain;
+       MLoop *mloop = NULL, *mloopmain;
        Key *key, *nkey=NULL;
        KeyBlock *kb, *okb, *kbn;
        float imat[4][4], cmat[4][4], *fp1, *fp2, curpos;
        int a, b, totcol, totmat=0, totedge=0, totvert=0, totface=0, ok=0;
-       int vertofs, *matmap;
-       int     i, j, index, haskey=0, edgeofs, faceofs;
+       int totloop=0, totpoly=0, vertofs, *matmap=NULL;
+       int i, j, index, haskey=0, edgeofs, faceofs, loopofs, polyofs;
        bDeformGroup *dg, *odg;
        MDeformVert *dvert;
-       CustomData vdata, edata, fdata;
+       CustomData vdata, edata, fdata, ldata, pdata;
 
        if(scene->obedit)
                return OPERATOR_CANCELLED;
@@ -144,6 +122,8 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                        totvert+= me->totvert;
                        totedge+= me->totedge;
                        totface+= me->totface;
+                       totloop+= me->totloop;
+                       totpoly+= me->totpoly;
                        totmat+= base->object->totcol;
                        
                        if(base->object == ob)
@@ -168,7 +148,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
        
        /* new material indices and material array */
        matar= MEM_callocN(sizeof(void*)*totmat, "join_mesh matar");
-       matmap= MEM_callocN(sizeof(int)*totmat, "join_mesh matmap");
+       if (totmat) matmap= MEM_callocN(sizeof(int)*totmat, "join_mesh matmap");
        totcol= ob->totcol;
        
        /* obact materials in new main array, is nicer start! */
@@ -210,12 +190,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                        /* Join this object's vertex groups to the base one's */
                        for(dg=base->object->defbase.first; dg; dg=dg->next) {
                                /* See if this group exists in the object (if it doesn't, add it to the end) */
-                               for(odg=ob->defbase.first; odg; odg=odg->next) {
-                                       if(!strcmp(odg->name, dg->name)) {
-                                               break;
-                                       }
-                               }
-                               if(!odg) {
+                               if(!defgroup_find_name(ob, dg->name)) {
                                        odg = MEM_callocN(sizeof(bDeformGroup), "join deformGroup");
                                        memcpy(odg, dg, sizeof(bDeformGroup));
                                        BLI_addtail(&ob->defbase, odg);
@@ -291,21 +266,29 @@ int join_mesh_exec(bContext *C, wmOperator *op)
        memset(&vdata, 0, sizeof(vdata));
        memset(&edata, 0, sizeof(edata));
        memset(&fdata, 0, sizeof(fdata));
+       memset(&ldata, 0, sizeof(ldata));
+       memset(&pdata, 0, sizeof(pdata));
        
        mvert= CustomData_add_layer(&vdata, CD_MVERT, CD_CALLOC, NULL, totvert);
        medge= CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge);
        mface= CustomData_add_layer(&fdata, CD_MFACE, CD_CALLOC, NULL, totface);
+       mloop= CustomData_add_layer(&ldata, CD_MLOOP, CD_CALLOC, NULL, totloop);
+       mpoly= CustomData_add_layer(&pdata, CD_MPOLY, CD_CALLOC, NULL, totpoly);
        
        mvertmain= mvert;
        medgemain= medge;
        mfacemain= mface;
+       mloopmain = mloop;
+       mpolymain = mpoly;
        
        vertofs= 0;
        edgeofs= 0;
        faceofs= 0;
+       loopofs= 0;
+       polyofs= 0;
        
        /* inverse transform for all selected meshes in this object */
-       Mat4Invert(imat, ob->obmat);
+       invert_m4_m4(imat, ob->obmat);
        
        CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
                /* only join if this is a mesh */
@@ -342,11 +325,11 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                                /* if this is the object we're merging into, no need to do anything */
                                if(base->object != ob) {
                                        /* watch this: switch matmul order really goes wrong */
-                                       Mat4MulMat4(cmat, base->object->obmat, imat);
+                                       mul_m4_m4m4(cmat, base->object->obmat, imat);
                                        
                                        /* transform vertex coordinates into new space */
                                        for(a=0, mv=mvert; a < me->totvert; a++, mv++) {
-                                               Mat4MulVecfl(cmat, mv->co);
+                                               mul_m4_v3(cmat, mv->co);
                                        }
                                        
                                        /* for each shapekey in destination mesh:
@@ -366,7 +349,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                                                                fp2= ((float *)(okb->data));
                                                                for(a=0; a < me->totvert; a++, fp1+=3, fp2+=3) {
                                                                        VECCOPY(fp1, fp2);
-                                                                       Mat4MulVecfl(cmat, fp1);
+                                                                       mul_m4_v3(cmat, fp1);
                                                                }
                                                        }
                                                        else {
@@ -435,7 +418,10 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                                        mface->v3+= vertofs;
                                        if(mface->v4) mface->v4+= vertofs;
                                        
-                                       mface->mat_nr= matmap[(int)mface->mat_nr];
+                                       if (matmap)
+                                               mface->mat_nr= matmap[(int)mface->mat_nr];
+                                       else 
+                                               mface->mat_nr= 0;
                                }
                                
                                faceofs += me->totface;
@@ -452,7 +438,43 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                                
                                edgeofs += me->totedge;
                        }
+
+                       if (me->totloop) {
+                               CustomData_merge(&me->ldata, &ldata, CD_MASK_MESH, CD_DEFAULT, totloop);
+                               CustomData_copy_data(&me->ldata, &ldata, 0, loopofs, me->totloop);
+                               
+                               for(a=0; a<me->totloop; a++, mloop++) {
+                                       mloop->v += vertofs;
+                                       mloop->e += edgeofs;
+                               }
+                               
+                               loopofs += me->totloop;
+                       }
                        
+                       if(me->totpoly) {
+                               /* make mapping for materials */
+                               for(a=1; a<=base->object->totcol; a++) {
+                                       ma= give_current_material(base->object, a);
+
+                                       for(b=0; b<totcol; b++) {
+                                               if(ma == matar[b]) {
+                                                       matmap[a-1]= b;
+                                                       break;
+                                               }
+                                       }
+                               }
+                               
+                               CustomData_merge(&me->pdata, &pdata, CD_MASK_MESH, CD_DEFAULT, totpoly);
+                               CustomData_copy_data(&me->pdata, &pdata, 0, polyofs, me->totpoly);
+                               
+                               for(a=0; a<me->totpoly; a++, mpoly++) {
+                                       mpoly->loopstart += loopofs;
+                                       mpoly->mat_nr= matmap[(int)mpoly->mat_nr];
+                               }
+                               
+                               polyofs += me->totface;
+                       }
+
                        /* vertofs is used to help newly added verts be reattached to their edge/face 
                         * (cannot be set earlier, or else reattaching goes wrong)
                         */
@@ -460,7 +482,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                        
                        /* free base, now that data is merged */
                        if(base->object != ob)
-                               ED_base_object_free_and_unlink(scene, base);
+                               ED_base_object_free_and_unlink(bmain, scene, base);
                }
        }
        CTX_DATA_END;
@@ -471,14 +493,20 @@ int join_mesh_exec(bContext *C, wmOperator *op)
        CustomData_free(&me->vdata, me->totvert);
        CustomData_free(&me->edata, me->totedge);
        CustomData_free(&me->fdata, me->totface);
+       CustomData_free(&me->ldata, me->totloop);
+       CustomData_free(&me->pdata, me->totpoly);
 
        me->totvert= totvert;
        me->totedge= totedge;
        me->totface= totface;
+       me->totloop= totloop;
+       me->totpoly= totpoly;
        
        me->vdata= vdata;
        me->edata= edata;
        me->fdata= fdata;
+       me->ldata= ldata;
+       me->pdata= pdata;
 
        mesh_update_customdata_pointers(me);
        
@@ -508,7 +536,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
        ob->totcol= me->totcol= totcol;
        ob->colbits= 0;
 
-       MEM_freeN(matmap);
+       if (matmap) MEM_freeN(matmap);
        
        /* other mesh users */
        test_object_materials((ID *)me);
@@ -520,180 +548,107 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                /* free it's ipo too - both are not actually freed from memory yet as ID-blocks */
                if(nkey->ipo) {
                        free_ipo(nkey->ipo);
-                       BLI_remlink(&G.main->ipo, nkey->ipo);
+                       BLI_remlink(&bmain->ipo, nkey->ipo);
                        MEM_freeN(nkey->ipo);
                }
 #endif
                
                free_key(nkey);
-               BLI_remlink(&G.main->key, nkey);
+               BLI_remlink(&bmain->key, nkey);
                MEM_freeN(nkey);
        }
        
-       DAG_scene_sort(scene);  // removed objects, need to rebuild dag before editmode call
+       DAG_scene_sort(bmain, scene);   // removed objects, need to rebuild dag before editmode call
        
        ED_object_enter_editmode(C, EM_WAITCURSOR);
-       ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR);
+       ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR|EM_DO_UNDO);
 
        WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
 
        return OPERATOR_FINISHED;
 }
 
-/* ********************** SORT FACES ******************* */
+/*********************** JOIN AS SHAPES ***************************/
 
-static void permutate(void *list, int num, int size, int *index)
-{
-       void *buf;
-       int len;
-       int i;
-
-       len = num * size;
+/* Append selected meshes vertex locations as shapes of the active mesh, 
+  return 0 if no join is made (error) and 1 of the join is done */
 
-       buf = MEM_mallocN(len, "permutate");
-       memcpy(buf, list, len);
+int join_mesh_shapes_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+       Mesh *me= (Mesh *)ob->data;
+       Mesh *selme=NULL;
+       DerivedMesh *dm=NULL;
+       Key *key=me->key;
+       KeyBlock *kb;
+       int ok=0, nonequal_verts=0;
        
-       for (i = 0; i < num; i++) {
-               memcpy((char *)list + (i * size), (char *)buf + (index[i] * size), size);
+       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
+               if (base->object == ob) continue;
+               
+               if (base->object->type==OB_MESH) {
+                       selme = (Mesh *)base->object->data;
+                       
+                       if (selme->totvert==me->totvert)
+                               ok++;
+                       else
+                               nonequal_verts=1;
+               }
        }
-       MEM_freeN(buf);
-}
-
-/* sort faces on view axis */
-static float *face_sort_floats;
-static int float_sort(const void *v1, const void *v2)
-{
-       float x1, x2;
+       CTX_DATA_END;
        
-       x1 = face_sort_floats[((int *) v1)[0]];
-       x2 = face_sort_floats[((int *) v2)[0]];
+       if (!ok) {
+               if (nonequal_verts)
+                       BKE_report(op->reports, RPT_ERROR, "Selected meshes must have equal numbers of vertices.");
+               else
+                       BKE_report(op->reports, RPT_ERROR, "No additional selected meshes with equal vertex count to join.");
+               return OPERATOR_CANCELLED;
+       }
        
-       if( x1 > x2 ) return 1;
-       else if( x1 < x2 ) return -1;
-       return 0;
-}
-
+       if(key == NULL) {
+               key= me->key= add_key((ID *)me);
+               key->type= KEY_RELATIVE;
 
-void sort_faces(Scene *scene, View3D *v3d)
-{
-       RegionView3D *rv3d= NULL; // get from context 
-       Object *ob= OBACT;
-       Mesh *me;
-       CustomDataLayer *layer;
-       int i, *index;
-       short event;
-       float reverse = 1;
-       int ctrl= 0;    // XXX
-       
-       if(!ob) return;
-       if(scene->obedit) return;
-       if(ob->type!=OB_MESH) return;
-       if (!v3d) return;
-       
-       me= ob->data;
-       if(me->totface==0) return;
-       
-       event = pupmenu(
-       "Sort Faces (Ctrl to reverse)%t|"
-       "View Axis%x1|"
-       "Cursor Distance%x2|"
-       "Material%x3|"
-       "Selection%x4|"
-       "Randomize%x5");
-       
-       if (event==-1) return;
-       
-       if(ctrl)
-               reverse = -1;
-       
-/*     create index list */
-       index = (int *) MEM_mallocN(sizeof(int) * me->totface, "sort faces");
-       for (i = 0; i < me->totface; i++) {
-               index[i] = i;
+               /* first key added, so it was the basis. initialise it with the existing mesh */
+               kb= add_keyblock(key, NULL);
+               mesh_to_key(me, kb);
        }
        
-       face_sort_floats = (float *) MEM_mallocN(sizeof(float) * me->totface, "sort faces float");
-       
-/* sort index list instead of faces itself 
-   and apply this permutation to all face layers */
-   
-       if (event == 5) {
-               /* Random */
-               for(i=0; i<me->totface; i++) {
-                       face_sort_floats[i] = BLI_frand();
-               }
-               qsort(index, me->totface, sizeof(int), float_sort);             
-       } else {
-               MFace *mf;
-               float vec[3];
-               float mat[4][4];
-               float cur[3];
-               
-               if (event == 1)
-                       Mat4MulMat4(mat, OBACT->obmat, rv3d->viewmat); /* apply the view matrix to the object matrix */
-               else if (event == 2) { /* sort from cursor */
-                       if( v3d && v3d->localvd ) {
-                               VECCOPY(cur, v3d->cursor);
-                       } else {
-                               VECCOPY(cur, scene->cursor);
-                       }
-                       Mat4Invert(mat, OBACT->obmat);
-                       Mat4MulVecfl(mat, cur);
-               }
+       /* now ready to add new keys from selected meshes */
+       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
+               if (base->object == ob) continue;
                
-               mf= me->mface;
-               for(i=0; i<me->totface; i++, mf++) {
+               if(base->object->type==OB_MESH) {
+                       selme = (Mesh *)base->object->data;
                        
-                       if (event==3) {
-                               face_sort_floats[i] = ((float)mf->mat_nr)*reverse;
-                       } else if (event==4) {
-                               /*selected first*/
-                               if (mf->flag & ME_FACE_SEL)     face_sort_floats[i] = 0.0;
-                               else                                            face_sort_floats[i] = reverse;
-                       } else {
-                               /* find the faces center */
-                               VecAddf(vec, (me->mvert+mf->v1)->co, (me->mvert+mf->v2)->co);
-                               if (mf->v4) {
-                                       VecAddf(vec, vec, (me->mvert+mf->v3)->co);
-                                       VecAddf(vec, vec, (me->mvert+mf->v4)->co);
-                                       VecMulf(vec, 0.25f);
-                               } else {
-                                       VecAddf(vec, vec, (me->mvert+mf->v3)->co);
-                                       VecMulf(vec, 1.0f/3.0f);
-                               } /* done */
+                       if (selme->totvert==me->totvert) {
+                               dm = mesh_get_derived_deform(scene, base->object, CD_MASK_BAREMESH);
                                
-                               if (event == 1) { /* sort on view axis */
-                                       Mat4MulVecfl(mat, vec);
-                                       face_sort_floats[i] = vec[2] * reverse;
-                               } else { /* distance from cursor*/
-                                       face_sort_floats[i] = VecLenf(cur, vec) * reverse; /* back to front */
-                               }
+                               if (!dm) continue;
+                                       
+                               kb= add_keyblock(key, base->object->id.name+2);
+                               
+                               DM_to_meshkey(dm, me, kb);
+                               
+                               dm->release(dm);
                        }
                }
-               qsort(index, me->totface, sizeof(int), float_sort);
        }
+       CTX_DATA_END;
        
-       MEM_freeN(face_sort_floats);
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
        
-       for(i = 0; i < me->fdata.totlayer; i++) {
-               layer = &me->fdata.layers[i];
-               permutate(layer->data, me->totface, CustomData_sizeof(layer->type), index);
-       }
-
-       MEM_freeN(index);
-
-       DAG_id_flush_update(ob->data, OB_RECALC_DATA);
+       return OPERATOR_FINISHED;
 }
 
-
-
 /* ********************* MESH VERTEX OCTREE LOOKUP ************* */
 
 /* important note; this is unfinished, needs better API for editmode, and custom threshold */
 
 #define MOC_RES                        8
 #define MOC_NODE_RES   8
-#define MOC_THRESH             0.0002f
+#define MOC_THRESH             0.00002f
 
 typedef struct MocNode {
        struct MocNode *next;
@@ -795,7 +750,7 @@ static void mesh_octree_add_nodes(MocNode **basetable, float *co, float *offs, f
        
 }
 
-static intptr_t mesh_octree_find_index(MocNode **bt, float (*orco)[3], MVert *mvert, float *co)
+static intptr_t mesh_octree_find_index(MocNode **bt, MVert *mvert, float *co)
 {
        float *vec;
        int a;
@@ -806,26 +761,21 @@ static intptr_t mesh_octree_find_index(MocNode **bt, float (*orco)[3], MVert *mv
        for(a=0; a<MOC_NODE_RES; a++) {
                if((*bt)->index[a]) {
                        /* does mesh verts and editmode, code looks potential dangerous, octree should really be filled OK! */
-                       if(orco) {
-                               vec= orco[(*bt)->index[a]-1];
-                               if(FloatCompare(vec, co, MOC_THRESH))
-                                       return (*bt)->index[a]-1;
-                       }
-                       else if(mvert) {
+                       if(mvert) {
                                vec= (mvert+(*bt)->index[a]-1)->co;
-                               if(FloatCompare(vec, co, MOC_THRESH))
+                               if(compare_v3v3(vec, co, MOC_THRESH))
                                        return (*bt)->index[a]-1;
                        }
                        else {
                                EditVert *eve= (EditVert *)((*bt)->index[a]);
-                               if(FloatCompare(eve->co, co, MOC_THRESH))
+                               if(compare_v3v3(eve->co, co, MOC_THRESH))
                                        return (*bt)->index[a];
                        }
                }
                else return -1;
        }
        if( (*bt)->next)
-               return mesh_octree_find_index(&(*bt)->next, orco, mvert, co);
+               return mesh_octree_find_index(&(*bt)->next, mvert, co);
        
        return -1;
 }
@@ -833,13 +783,11 @@ static intptr_t mesh_octree_find_index(MocNode **bt, float (*orco)[3], MVert *mv
 static struct {
        MocNode **table;
        float offs[3], div[3];
-       float (*orco)[3];
-       float orcoloc[3];
-} MeshOctree = {NULL, {0, 0, 0}, {0, 0, 0}, NULL};
+} MeshOctree = {NULL, {0, 0, 0}, {0, 0, 0}};
 
 /* mode is 's' start, or 'e' end, or 'u' use */
 /* if end, ob can be NULL */
-intptr_t mesh_octree_table(Object *ob, EditMesh *em, float *co, char mode)
+intptr_t mesh_octree_table(Object *ob, BMEditMesh *em, float *co, char mode)
 {
        MocNode **bt;
        
@@ -851,9 +799,9 @@ intptr_t mesh_octree_table(Object *ob, EditMesh *em, float *co, char mode)
                        Mesh *me= ob->data;
                        bt= MeshOctree.table + mesh_octree_get_base_offs(co, MeshOctree.offs, MeshOctree.div);
                        if(em)
-                               return mesh_octree_find_index(bt, NULL, NULL, co);
+                               return mesh_octree_find_index(bt, NULL, co);
                        else
-                               return mesh_octree_find_index(bt, MeshOctree.orco, me->mvert, co);
+                               return mesh_octree_find_index(bt, me->mvert, co);
                }
                return -1;
        }
@@ -865,24 +813,20 @@ intptr_t mesh_octree_table(Object *ob, EditMesh *em, float *co, char mode)
                 * we are using the undeformed coordinates*/
                INIT_MINMAX(min, max);
 
-               if(em && me->edit_mesh==em) {
-                       EditVert *eve;
+               if(em && me->edit_btmesh==em) {
+                       BMIter iter;
+                       BMVert *eve;
                        
-                       for(eve= em->verts.first; eve; eve= eve->next)
+                       eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL);
+                       for (; eve; eve=BMIter_Step(&iter))
                                DO_MINMAX(eve->co, min, max)
                }
                else {          
                        MVert *mvert;
-                       float *vco;
-                       int a, totvert;
-                       
-                       MeshOctree.orco= mesh_getRefKeyCos(me, &totvert);
-                       mesh_get_texspace(me, MeshOctree.orcoloc, NULL, NULL);
+                       int a;
                        
-                       for(a=0, mvert= me->mvert; a<me->totvert; a++, mvert++) {
-                               vco= (MeshOctree.orco)? MeshOctree.orco[a]: mvert->co;
-                               DO_MINMAX(vco, min, max);
-                       }
+                       for(a=0, mvert= me->mvert; a<me->totvert; a++, mvert++)
+                               DO_MINMAX(mvert->co, min, max);
                }
                
                /* for quick unit coordinate calculus */
@@ -891,12 +835,12 @@ intptr_t mesh_octree_table(Object *ob, EditMesh *em, float *co, char mode)
                MeshOctree.offs[1]-= MOC_THRESH;
                MeshOctree.offs[2]-= MOC_THRESH;
                
-               VecSubf(MeshOctree.div, max, min);
+               sub_v3_v3v3(MeshOctree.div, max, min);
                MeshOctree.div[0]+= 2*MOC_THRESH;       /* and divide with 2 threshold unit more extra (try 8x8 unit grid on paint) */
                MeshOctree.div[1]+= 2*MOC_THRESH;
                MeshOctree.div[2]+= 2*MOC_THRESH;
                
-               VecMulf(MeshOctree.div, 1.0f/MOC_RES);
+               mul_v3_fl(MeshOctree.div, 1.0f/MOC_RES);
                if(MeshOctree.div[0]==0.0f) MeshOctree.div[0]= 1.0f;
                if(MeshOctree.div[1]==0.0f) MeshOctree.div[1]= 1.0f;
                if(MeshOctree.div[2]==0.0f) MeshOctree.div[2]= 1.0f;
@@ -906,22 +850,21 @@ intptr_t mesh_octree_table(Object *ob, EditMesh *em, float *co, char mode)
                
                MeshOctree.table= MEM_callocN(MOC_RES*MOC_RES*MOC_RES*sizeof(void *), "sym table");
                
-               if(em && me->edit_mesh==em) {
-                       EditVert *eve;
+               if(em && me->edit_btmesh==em) {
+                       BMVert *eve;
+                       BMIter iter;
 
-                       for(eve= em->verts.first; eve; eve= eve->next) {
+                       eve = BMIter_New(&iter, em->bm, BM_VERTS_OF_MESH, NULL);
+                       for (; eve; eve=BMIter_Step(&iter)) {
                                mesh_octree_add_nodes(MeshOctree.table, eve->co, MeshOctree.offs, MeshOctree.div, (intptr_t)(eve));
                        }
                }
                else {          
                        MVert *mvert;
-                       float *vco;
                        int a;
                        
-                       for(a=0, mvert= me->mvert; a<me->totvert; a++, mvert++) {
-                               vco= (MeshOctree.orco)? MeshOctree.orco[a]: mvert->co;
-                               mesh_octree_add_nodes(MeshOctree.table, vco, MeshOctree.offs, MeshOctree.div, a+1);
-                       }
+                       for(a=0, mvert= me->mvert; a<me->totvert; a++, mvert++)
+                               mesh_octree_add_nodes(MeshOctree.table, mvert->co, MeshOctree.offs, MeshOctree.div, a+1);
                }
        }
        else if(mode=='e') { /* end table */
@@ -934,38 +877,248 @@ intptr_t mesh_octree_table(Object *ob, EditMesh *em, float *co, char mode)
                        MEM_freeN(MeshOctree.table);
                        MeshOctree.table= NULL;
                }
-               if(MeshOctree.orco) {
-                       MEM_freeN(MeshOctree.orco);
-                       MeshOctree.orco= NULL;
+       }
+       return 0;
+}
+
+
+/* ********************* MESH VERTEX MIRR TOPO LOOKUP *************** */
+
+#define MIRRHASH_TYPE int
+
+typedef struct MirrTopoPair {
+       long hash;
+       int vIndex;
+} MirrTopoPair;
+
+static int MirrTopo_long_sort(const void *l1, const void *l2)
+{
+       if(                     (MIRRHASH_TYPE)(intptr_t)l1 > (MIRRHASH_TYPE)(intptr_t)l2 ) return  1;
+       else if(        (MIRRHASH_TYPE)(intptr_t)l1 < (MIRRHASH_TYPE)(intptr_t)l2 ) return -1;
+       return 0;
+}
+
+static int MirrTopo_item_sort(const void *v1, const void *v2)
+{
+       if(                     ((MirrTopoPair *)v1)->hash > ((MirrTopoPair *)v2)->hash ) return  1;
+       else if(        ((MirrTopoPair *)v1)->hash < ((MirrTopoPair *)v2)->hash ) return -1;
+       return 0;
+}
+
+static long *mesh_topo_lookup = NULL;
+static int  mesh_topo_lookup_tot = -1;
+static int  mesh_topo_lookup_mode = -1;
+
+/* mode is 's' start, or 'e' end, or 'u' use */
+/* if end, ob can be NULL */
+long mesh_mirrtopo_table(Object *ob, char mode)
+{
+#if 0
+       if(mode=='u') {         /* use table */
+               Mesh *me= ob->data;
+               if(     (mesh_topo_lookup==NULL) ||
+                       (mesh_topo_lookup_mode != ob->mode) ||
+                       (me->edit_mesh && me->edit_mesh->totvert != mesh_topo_lookup_tot) ||
+                       (me->edit_mesh==NULL && me->totvert != mesh_topo_lookup_tot)
+               ) {
+                       mesh_mirrtopo_table(ob, 's');
                }
+       } else if(mode=='s') { /* start table */
+               Mesh *me= ob->data;
+               MEdge *medge;
+               EditMesh *em= me->edit_mesh;
+
+
+               /* editmode*/
+               EditEdge *eed;
+
+               int a, last, totvert;
+               int totUnique= -1, totUniqueOld= -1;
+
+               MIRRHASH_TYPE *MirrTopoHash = NULL;
+               MIRRHASH_TYPE *MirrTopoHash_Prev = NULL;
+               MirrTopoPair *MirrTopoPairs;
+               mesh_topo_lookup_mode= ob->mode;
+
+               /* reallocate if needed */
+               if (mesh_topo_lookup) {
+                       MEM_freeN(mesh_topo_lookup);
+                       mesh_topo_lookup = NULL;
+               }
+
+               if(em) {
+                       EditVert *eve;
+                       totvert= 0;
+                       for(eve= em->verts.first; eve; eve= eve->next) {
+                               eve->hash = totvert++;
+                       }
+               } else {
+                       totvert = me->totvert;
+               }
+
+               MirrTopoHash = MEM_callocN( totvert * sizeof(MIRRHASH_TYPE), "TopoMirr" );
+
+               /* Initialize the vert-edge-user counts used to detect unique topology */
+               if(em) {
+                       for(eed=em->edges.first; eed; eed= eed->next) {
+                               MirrTopoHash[eed->v1->hash]++;
+                               MirrTopoHash[eed->v2->hash]++;
+                       }
+               } else {
+                       for(a=0, medge=me->medge; a<me->totedge; a++, medge++) {
+                               MirrTopoHash[medge->v1]++;
+                               MirrTopoHash[medge->v2]++;
+                       }
+               }
+
+               MirrTopoHash_Prev = MEM_dupallocN( MirrTopoHash );
+
+               totUniqueOld = -1;
+               while(1) {
+                       /* use the number of edges per vert to give verts unique topology IDs */
+
+                       if(em) {
+                               for(eed=em->edges.first; eed; eed= eed->next) {
+                                       MirrTopoHash[eed->v1->hash] += MirrTopoHash_Prev[eed->v2->hash];
+                                       MirrTopoHash[eed->v2->hash] += MirrTopoHash_Prev[eed->v1->hash];
+                               }
+                       } else {
+                               for(a=0, medge=me->medge; a<me->totedge; a++, medge++) {
+                                       /* This can make realy big numbers, wrapping around here is fine */
+                                       MirrTopoHash[medge->v1] += MirrTopoHash_Prev[medge->v2];
+                                       MirrTopoHash[medge->v2] += MirrTopoHash_Prev[medge->v1];
+                               }
+                       }
+                       memcpy(MirrTopoHash_Prev, MirrTopoHash, sizeof(MIRRHASH_TYPE) * totvert);
+
+                       /* sort so we can count unique values */
+                       qsort(MirrTopoHash_Prev, totvert, sizeof(MIRRHASH_TYPE), MirrTopo_long_sort);
+
+                       totUnique = 1; /* account for skiping the first value */
+                       for(a=1; a<totvert; a++) {
+                               if (MirrTopoHash_Prev[a-1] != MirrTopoHash_Prev[a]) {
+                                       totUnique++;
+                               }
+                       }
+
+                       if (totUnique <= totUniqueOld) {
+                               /* Finish searching for unique valus when 1 loop dosnt give a
+                                * higher number of unique values compared to the previous loop */
+                               break;
+                       } else {
+                               totUniqueOld = totUnique;
+                       }
+                       /* Copy the hash calculated this iter, so we can use them next time */
+                       memcpy(MirrTopoHash_Prev, MirrTopoHash, sizeof(MIRRHASH_TYPE) * totvert);
+               }
+
+               /* Hash/Index pairs are needed for sorting to find index pairs */
+               MirrTopoPairs= MEM_callocN( sizeof(MirrTopoPair) * totvert, "MirrTopoPairs");
+
+               /* since we are looping through verts, initialize these values here too */
+               mesh_topo_lookup = MEM_mallocN( totvert * sizeof(long), "mesh_topo_lookup" );
+
+               if(em) {
+                       EM_init_index_arrays(em,1,0,0);
+               }
+
+
+               for(a=0; a<totvert; a++) {
+                       MirrTopoPairs[a].hash= MirrTopoHash[a];
+                       MirrTopoPairs[a].vIndex = a;
+
+                       /* initialize lookup */
+                       mesh_topo_lookup[a] = -1;
+               }
+
+               qsort(MirrTopoPairs, totvert, sizeof(MirrTopoPair), MirrTopo_item_sort);
+
+               /* Since the loop starts at 2, we must define the last index where the hash's differ */
+               last = ((totvert >= 2) && (MirrTopoPairs[0].hash == MirrTopoPairs[1].hash)) ? 0 : 1;
+
+               /* Get the pairs out of the sorted hashes, note, totvert+1 means we can use the previous 2,
+                * but you cant ever access the last 'a' index of MirrTopoPairs */
+               for(a=2; a < totvert+1; a++) {
+                       /* printf("I %d %ld %d\n", (a-last), MirrTopoPairs[a  ].hash, MirrTopoPairs[a  ].vIndex ); */
+                       if ((a==totvert) || (MirrTopoPairs[a-1].hash != MirrTopoPairs[a].hash)) {
+                               if (a-last==2) {
+                                       if(em) {
+                                               mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] =   (long)EM_get_vert_for_index(MirrTopoPairs[a-2].vIndex);
+                                               mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] =   (long)EM_get_vert_for_index(MirrTopoPairs[a-1].vIndex);
+                                       } else {
+                                               mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] =   MirrTopoPairs[a-2].vIndex;
+                                               mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] =   MirrTopoPairs[a-1].vIndex;
+                                       }
+                               }
+                               last= a;
+                       }
+               }
+               if(em) {
+                       EM_free_index_arrays();
+               }
+
+               MEM_freeN( MirrTopoPairs );
+               MirrTopoPairs = NULL;
+
+               MEM_freeN( MirrTopoHash );
+               MEM_freeN( MirrTopoHash_Prev );
+
+               mesh_topo_lookup_tot = totvert;
+
+       } else if(mode=='e') { /* end table */
+               if (mesh_topo_lookup) {
+                       MEM_freeN(mesh_topo_lookup);
+               }
+               mesh_topo_lookup = NULL;
+               mesh_topo_lookup_tot= -1;
        }
+       return 0;
+#endif
+
        return 0;
 }
 
-int mesh_get_x_mirror_vert(Object *ob, int index)
+int mesh_get_x_mirror_vert_spacial(Object *ob, int index)
 {
        Mesh *me= ob->data;
        MVert *mvert;
        float vec[3];
        
-       if(MeshOctree.orco) {
-               float *loc= MeshOctree.orcoloc;
-
-               vec[0]= -(MeshOctree.orco[index][0] + loc[0]) - loc[0];
-               vec[1]= MeshOctree.orco[index][1];
-               vec[2]= MeshOctree.orco[index][2];
-       }
-       else {
-               mvert= me->mvert+index;
-               vec[0]= -mvert->co[0];
-               vec[1]= mvert->co[1];
-               vec[2]= mvert->co[2];
-       }
+       mvert= me->mvert+index;
+       vec[0]= -mvert->co[0];
+       vec[1]= mvert->co[1];
+       vec[2]= mvert->co[2];
        
        return mesh_octree_table(ob, NULL, vec, 'u');
 }
 
-EditVert *editmesh_get_x_mirror_vert(Object *ob, EditMesh *em, float *co)
+/*BMESH_TODO: hook into editbmesh_bvh.h code, though that'll require caching the
+              bvh structure most likely, not too difficult*/
+BMVert *editmesh_get_x_mirror_vert(Object *ob, BMEditMesh *em, float *co)
+{
+#if 0
+       if (mesh_mirrtopo_table(ob, 'u')==-1)
+               return -1;
+
+       return mesh_topo_lookup[index];
+#endif
+       return NULL;
+
+}
+
+int mesh_get_x_mirror_vert(Object *ob, int index)
+{
+#if 0 //BMESH_TODO
+       if (((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_TOPO) {
+               return mesh_get_x_mirror_vert_topo(ob, index);
+       } else {
+               return mesh_get_x_mirror_vert_spacial(ob, index);
+       }
+#endif
+       return 0;
+}
+
+static EditVert *editmesh_get_x_mirror_vert_spacial(Object *ob, EditMesh *em, float *co)
 {
        float vec[3];
        intptr_t poinval;
@@ -982,11 +1135,94 @@ EditVert *editmesh_get_x_mirror_vert(Object *ob, EditMesh *em, float *co)
        vec[2]= co[2];
        
        poinval= mesh_octree_table(ob, em, vec, 'u');
+       if(poinval != -1)
+               return (BMVert *)(poinval);
+       return NULL;
+}
+
+static EditVert *editmesh_get_x_mirror_vert_topo(Object *ob, struct EditMesh *em, EditVert *eve, int index)
+{
+       long poinval;
+       if (mesh_mirrtopo_table(ob, 'u')==-1)
+               return NULL;
+
+       if (index!=-1) {
+               index = BLI_findindex(&em->verts, eve);
+       }
+
+       if (index==-1)
+               return NULL;
+
+       poinval= mesh_topo_lookup[ index ];
+
        if(poinval != -1)
                return (EditVert *)(poinval);
        return NULL;
 }
 
+#if 0
+EditVert *editmesh_get_x_mirror_vert(Object *ob, struct EditMesh *em, EditVert *eve, float *co, int index)
+{
+       //BMESH_TODO use this flag, ME_EDIT_MIRROR_TOPO, at appropriate places
+       if (((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_TOPO) {
+               return editmesh_get_x_mirror_vert_topo(ob, em, eve, index);
+       } else {
+               return editmesh_get_x_mirror_vert_spacial(ob, em, eve->co);
+       }
+}
+#endif
+
+
+#if 0
+float *editmesh_get_mirror_uv(int axis, float *uv, float *mirrCent, float *face_cent)
+{
+       float vec[2];
+       float cent_vec[2];
+       float cent[2];
+
+       /* ignore nan verts */
+       if (isnan(uv[0]) || !finite(uv[0]) ||
+               isnan(uv[1]) || !finite(uv[1])
+          )
+               return NULL;
+
+       if (axis) {
+               vec[0]= uv[0];
+               vec[1]= -((uv[1])-mirrCent[1]) + mirrCent[1];
+
+               cent_vec[0] = face_cent[0];
+               cent_vec[1]= -((face_cent[1])-mirrCent[1]) + mirrCent[1];
+       } else {
+               vec[0]= -((uv[0])-mirrCent[0]) + mirrCent[0];
+               vec[1]= uv[1];
+
+               cent_vec[0]= -((face_cent[0])-mirrCent[0]) + mirrCent[0];
+               cent_vec[1] = face_cent[1];
+       }
+
+       /* TODO - Optimize */
+       {
+               EditFace *efa;
+               int i, len;
+               for(efa=em->faces.first; efa; efa=efa->next) {
+                       MTFace *tf= (MTFace *)CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+                       uv_center(tf->uv, cent, (void *)efa->v4);
+
+                       if ( (fabs(cent[0] - cent_vec[0]) < 0.001) && (fabs(cent[1] - cent_vec[1]) < 0.001) ) {
+                               len = efa->v4 ? 4 : 3;
+                               for (i=0; i<len; i++) {
+                                       if ( (fabs(tf->uv[i][0] - vec[0]) < 0.001) && (fabs(tf->uv[i][1] - vec[1]) < 0.001) ) {
+                                               return tf->uv[i];
+                                       }
+                               }
+                       }
+               }
+       }
+
+       return NULL;
+}
+#endif
+
 static unsigned int mirror_facehash(void *ptr)
 {
        MFace *mf= ptr;
@@ -1033,7 +1269,7 @@ static int mirror_facecmp(void *a, void *b)
        return (mirror_facerotation((MFace*)a, (MFace*)b) == -1);
 }
 
-int *mesh_get_x_mirror_faces(Object *ob, EditMesh *em)
+int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em)
 {
        Mesh *me= ob->data;
        MVert *mv, *mvert= me->mvert;
@@ -1052,7 +1288,7 @@ int *mesh_get_x_mirror_faces(Object *ob, EditMesh *em)
 
        mesh_octree_table(ob, em, NULL, 'e');
 
-       fhash= BLI_ghash_new(mirror_facehash, mirror_facecmp);
+       fhash= BLI_ghash_new(mirror_facehash, mirror_facecmp, "mirror_facehash gh");
        for(a=0, mf=mface; a<me->totface; a++, mf++)
                BLI_ghash_insert(fhash, mf, mf);
 
@@ -1082,191 +1318,3 @@ int *mesh_get_x_mirror_faces(Object *ob, EditMesh *em)
        
        return mirrorfaces;
 }
-
-/* ****************** render BAKING ********************** */
-
-/* threaded break test */
-static int thread_break(void *unused)
-{
-       return G.afbreek;
-}
-
-static ScrArea *biggest_image_area(bScreen *screen)
-{
-       ScrArea *sa, *big= NULL;
-       int size, maxsize= 0;
-       
-       for(sa= screen->areabase.first; sa; sa= sa->next) {
-               if(sa->spacetype==SPACE_IMAGE) {
-                       size= sa->winx*sa->winy;
-                       if(sa->winx > 10 && sa->winy > 10 && size > maxsize) {
-                               maxsize= size;
-                               big= sa;
-                       }
-               }
-       }
-       return big;
-}
-
-
-typedef struct BakeRender {
-       Render *re;
-       struct Object *actob;
-       int event, tot, ready;
-} BakeRender;
-
-static void *do_bake_render(void *bake_v)
-{
-       BakeRender *bkr= bake_v;
-       
-       bkr->tot= RE_bake_shade_all_selected(bkr->re, bkr->event, bkr->actob);
-       bkr->ready= 1;
-       
-       return NULL;
-}
-
-
-void objects_bake_render(Scene *scene, short event, char **error_msg)
-{
-       Object *actob= OBACT;
-       int active= scene->r.bake_flag & R_BAKE_TO_ACTIVE;
-       short prev_r_raytrace= 0, prev_wo_amb_occ= 0;
-       
-       if(event==0) event= scene->r.bake_mode;
-       
-       if(scene->r.renderer!=R_INTERN) {        
-               *error_msg = "Bake only supported for Internal Renderer";
-               return;
-       }        
-       
-       if(active && !actob) {
-               *error_msg = "No active object";
-               return;
-       }
-       
-       if(event>0) {
-               bScreen *screen= NULL; // XXX CTX
-               Render *re= RE_NewRender("_Bake View_");
-               ScrArea *area= biggest_image_area(screen);
-               ListBase threads;
-               BakeRender bkr;
-               int timer=0, tot; // XXX, sculptmode= G.f & G_SCULPTMODE;
-
-// XXX         if(sculptmode) set_sculptmode();
-               
-               if(event==1) event= RE_BAKE_ALL;
-               else if(event==2) event= RE_BAKE_AO;
-               else if(event==3) event= RE_BAKE_NORMALS;
-               else if(event==4) event= RE_BAKE_TEXTURE;
-               else if(event==5) event= RE_BAKE_DISPLACEMENT;
-               else event= RE_BAKE_SHADOW;
-
-               if(event==RE_BAKE_AO) {
-                       if(scene->world==NULL) {
-                               *error_msg = "No world set up";
-                               return;
-                       }
-
-                       /* If raytracing or AO is disabled, switch it on temporarily for baking. */
-                       prev_wo_amb_occ = (scene->world->mode & WO_AMB_OCC) != 0;
-                       scene->world->mode |= WO_AMB_OCC;
-               }
-               if(event==RE_BAKE_AO || active) {
-                       prev_r_raytrace = (scene->r.mode & R_RAYTRACE) != 0;
-                       scene->r.mode |= R_RAYTRACE;
-               }
-               
-               waitcursor(1);
-               RE_test_break_cb(re, NULL, thread_break);
-               G.afbreek= 0;   /* blender_test_break uses this global */
-               
-               RE_Database_Baking(re, scene, event, (active)? actob: NULL);
-               
-               /* baking itself is threaded, cannot use test_break in threads. we also update optional imagewindow */
-       
-               BLI_init_threads(&threads, do_bake_render, 1);
-               bkr.re= re;
-               bkr.event= event;
-               bkr.ready= 0;
-               bkr.actob= (active)? actob: NULL;
-               BLI_insert_thread(&threads, &bkr);
-               
-               while(bkr.ready==0) {
-                       PIL_sleep_ms(50);
-                       if(bkr.ready)
-                               break;
-                       
-                       if (!G.background) {
-                               blender_test_break();
-                               
-                               timer++;
-                               if(area && timer==20) {
-                                       Image *ima= RE_bake_shade_get_image();
-                                       if(ima) ((SpaceImage *)area->spacedata.first)->image= ima;
-// XX                                  scrarea_do_windraw(area);
-//                                     myswapbuffers();        
-                                       timer= 0;
-                               }
-                       }
-               }
-               BLI_end_threads(&threads);
-               tot= bkr.tot;
-               
-               RE_Database_Free(re);
-               waitcursor(0);
-               
-               if(tot==0) *error_msg = "No Images found to bake to";
-               else {
-                       Image *ima;
-                       /* force OpenGL reload and mipmap recalc */
-                       for(ima= G.main->image.first; ima; ima= ima->id.next) {
-                               if(ima->ok==IMA_OK_LOADED) {
-                                       ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
-                                       if(ibuf && (ibuf->userflags & IB_BITMAPDIRTY)) {
-                                               GPU_free_image(ima); 
-                                               imb_freemipmapImBuf(ibuf);
-                                       }
-                               }
-                       }
-               }
-               
-               /* restore raytrace and AO */
-               if(event==RE_BAKE_AO)
-                       if(prev_wo_amb_occ == 0)
-                               scene->world->mode &= ~WO_AMB_OCC;
-
-               if(event==RE_BAKE_AO || active)
-                       if(prev_r_raytrace == 0)
-                               scene->r.mode &= ~R_RAYTRACE;
-               
-// XXX         if(sculptmode) set_sculptmode();
-               
-       }
-}
-
-/* all selected meshes with UV maps are rendered for current scene visibility */
-static void objects_bake_render_ui(Scene *scene, short event)
-{
-       char *error_msg = NULL;
-//     int is_editmode = (obedit!=NULL);
-       
-       /* Deal with editmode, this is a bit clunky but since UV's are in editmode, users are likely to bake from their */
-// XXX if (is_editmode) exit_editmode(0);
-       
-       objects_bake_render(scene, event, &error_msg);
-       
-// XXX if (is_editmode) enter_editmode(0);
-       
-       if (error_msg)
-               error(error_msg);
-}
-
-void objects_bake_render_menu(Scene *scene)
-{
-       short event;
-       
-       event= pupmenu("Bake Selected Meshes %t|Full Render %x1|Ambient Occlusion %x2|Normals %x3|Texture Only %x4|Displacement %x5|Shadow %x6");
-       if (event < 1) return;
-       objects_bake_render_ui(scene, event);
-}
-