Merging r41246 through r41535 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenkernel / intern / BME_conversions.c
index 2129042bdc251334af452c8bf7eada8f42bb8873..ce1da6132cdfcbfbbb801add91228cb39f9a8a9b 100644 (file)
@@ -1,9 +1,8 @@
-/**
+/*
  * BME_mesh.c    jan 2007
  *
  *     BMesh mesh level functions.
  *
- * $Id: BME_eulers.c,v 1.00 2007/01/17 17:42:01 Briggs Exp $
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -20,7 +19,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) 2007 Blender Foundation.
  * All rights reserved.
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/blenkernel/intern/BME_conversions.c
+ *  \ingroup bke
+ */
+
+
 #include "MEM_guardedalloc.h"
-#include "BKE_customdata.h" 
 
-#include "DNA_listBase.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
-#include "BKE_utildefines.h"
+#include "BLI_edgehash.h"
+#include "BLI_listbase.h"
+#include "BLI_utildefines.h"
+
 #include "BKE_mesh.h"
-#include "BKE_bmesh.h"
-#include "BKE_global.h"
-#include "BKE_DerivedMesh.h"
 #include "BKE_cdderivedmesh.h"
 
-#include "BLI_blenlib.h"
-#include "BLI_editVert.h"
-#include "BLI_edgehash.h"
 //XXX #include "BIF_editmesh.h"
 //XXX #include "editmesh.h"
 #include "bmesh_private.h"
 
 //XXX #include "BSE_edit.h"
 
+/* XXX IMPORTANT: editmesh stuff doesn't belong in kernel! (ton) */
+
 /*merge these functions*/
 static void BME_DMcorners_to_loops(BME_Mesh *bm, CustomData *facedata, int index, BME_Poly *f, int numCol, int numTex){
        int i, j;
@@ -343,26 +344,22 @@ BME_Mesh *BME_editmesh_to_bmesh(EditMesh *em) {
        BME_model_end(bm);
        return bm;
 }
-/* adds the geometry in the bmesh to G.editMesh (does not free G.editMesh)
+/* adds the geometry in the bmesh to editMesh (does not free editMesh)
  * if td != NULL, the transdata will be mapped to the EditVert's co */
-EditMesh *BME_bmesh_to_editmesh(BME_Mesh *bm, BME_TransData_Head *td) {
+void BME_bmesh_to_editmesh(BME_Mesh *bm, BME_TransData_Head *td, EditMesh *em) {
        BME_Vert *v1;
        BME_Edge *e;
        BME_Poly *f;
        
        BME_TransData *vtd;
 
-       EditMesh *em;
-       EditVert *eve1, *eve2, *eve3, *eve4, **evlist;
+       EditVert *eve1, /* *eve2, *eve3, *eve4, */ /* UNUSED */ **evlist;
        EditEdge *eed;
        EditFace *efa;
 
        int totvert, len, i, numTex, numCol;
 
-       em = G.editMesh;
-
-       if (em == NULL) return NULL;
-
+       if (em == NULL) return;
 
        CustomData_copy(&bm->vdata, &em->vdata, CD_MASK_BMESH, CD_CALLOC, 0);
        CustomData_copy(&bm->edata, &em->edata, CD_MASK_BMESH, CD_CALLOC, 0);
@@ -401,9 +398,9 @@ EditMesh *BME_bmesh_to_editmesh(BME_Mesh *bm, BME_TransData_Head *td) {
                        if(e->flag & SELECT) eed->f |= SELECT;
                        //XXX if(e->flag & ME_FGON) eed->h= EM_FGON; // 2 different defines!
                        if(e->flag & ME_HIDE) eed->h |= 1;
-                       if(G.scene->selectmode==SCE_SELECT_EDGE) 
+                       if(em->selectmode==SCE_SELECT_EDGE) { 
                                ; //XXX EM_select_edge(eed, eed->f & SELECT);
-               
+                       }
                        CustomData_em_copy_data(&bm->edata, &em->edata, e->data, &eed->data);
                }
        }
@@ -413,14 +410,14 @@ EditMesh *BME_bmesh_to_editmesh(BME_Mesh *bm, BME_TransData_Head *td) {
                len = BME_cycle_length(f->loopbase);
                if (len==3 || len==4) {
                        eve1= evlist[f->loopbase->v->tflag1];
-                       eve2= evlist[f->loopbase->next->v->tflag1];
-                       eve3= evlist[f->loopbase->next->next->v->tflag1];
-                       if (len == 4) {
+                       /* eve2= evlist[f->loopbase->next->v->tflag1]; */ /* UNUSED */
+                       /* eve3= evlist[f->loopbase->next->next->v->tflag1]; */ /* UNUSED */
+                       /* if (len == 4) {
                                eve4= evlist[f->loopbase->prev->v->tflag1];
                        }
                        else {
                                eve4= NULL;
-                       }
+                       } */ /* UNUSED */
 
                        efa = NULL; //XXX addfacelist(eve1, eve2, eve3, eve4, NULL, NULL);
                        efa->mat_nr = (unsigned char)f->mat_nr;
@@ -429,8 +426,9 @@ EditMesh *BME_bmesh_to_editmesh(BME_Mesh *bm, BME_TransData_Head *td) {
                                efa->f |= SELECT;
                        }
                        if(f->flag & ME_HIDE) efa->h= 1;
-                       if((G.f & G_FACESELECT) && (efa->f & SELECT))
-                               ; //XXX EM_select_face(efa, 1); /* flush down */
+                       // XXX flag depricated
+                       // if((G.f & G_FACESELECT) && (efa->f & SELECT))
+                               //XXX EM_select_face(efa, 1); /* flush down */
                        CustomData_em_copy_data(&bm->pdata, &em->fdata, f->data, &efa->data);
                        BME_loops_to_corners(bm, &em->fdata, efa->data, f,numCol,numTex);
                }
@@ -438,9 +436,6 @@ EditMesh *BME_bmesh_to_editmesh(BME_Mesh *bm, BME_TransData_Head *td) {
 
        MEM_freeN(evlist);
 
-       //XXX countall();
-
-       return em;
 }
 
 /* Adds the geometry found in dm to bm
@@ -543,7 +538,8 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm)
        MFace *mface, *mf;
        MEdge *medge, *me;
        MVert *mvert, *mv;
-       int totface,totedge,totvert,i,bmeshok,len, numTex, numCol;
+       int *origindex;
+       int totface, totedge, totvert, i, /* bmeshok, */ /* UNUSED */ len, numTex, numCol;
 
        BME_Vert *v1=NULL;
        BME_Edge *e=NULL, *oe=NULL;
@@ -571,7 +567,7 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm)
        
        /*count quads and tris*/
        totface = 0;
-       bmeshok = 1;
+       /* bmeshok = 1; */ /* UNUSED */
        for(f=bm->polys.first;f;f=f->next){
                len = BME_cycle_length(f->loopbase);
                if(len == 3 || len == 4) totface++;
@@ -589,13 +585,16 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm)
 
        /*Make Verts*/
        mvert = CDDM_get_verts(result);
+       origindex = result->getVertDataArray(result, CD_ORIGINDEX);
        for(i=0,v1=bm->verts.first,mv=mvert;v1;v1=v1->next,i++,mv++){
                VECCOPY(mv->co,v1->co);
                mv->flag = (unsigned char)v1->flag;
                mv->bweight = (char)(255.0*v1->bweight);
                CustomData_from_bmesh_block(&bm->vdata, &result->vertData, &v1->data, i);
+               origindex[i] = ORIGINDEX_NONE;
        }
        medge = CDDM_get_edges(result);
+       origindex = result->getEdgeDataArray(result, CD_ORIGINDEX);
        i=0;
        for(e=bm->edges.first,me=medge;e;e=e->next){
                if(e->tflag2){
@@ -612,12 +611,14 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm)
                        me->bweight = (char)(255.0*e->bweight);
                        me->flag = e->flag;
                        CustomData_from_bmesh_block(&bm->edata, &result->edgeData, &e->data, i);
+                       origindex[i] = ORIGINDEX_NONE;
                        me++;
                        i++;
                }
        }
        if(totface){
                mface = CDDM_get_faces(result);
+               origindex = result->getFaceDataArray(result, CD_ORIGINDEX);
                /*make faces*/
                for(i=0,f=bm->polys.first;f;f=f->next){
                        mf = &mface[i];
@@ -637,6 +638,7 @@ DerivedMesh *BME_bmesh_to_derivedmesh(BME_Mesh *bm, DerivedMesh *dm)
                                mf->flag = (unsigned char)f->flag;
                                CustomData_from_bmesh_block(&bm->pdata, &result->faceData, &f->data, i);
                                BME_DMloops_to_corners(bm, &result->faceData, i, f,numCol,numTex);
+                               origindex[i] = ORIGINDEX_NONE;
                                i++;
                        }
                }