svn merge ^/trunk/blender -r42927:42931
authorCampbell Barton <ideasman42@gmail.com>
Wed, 28 Dec 2011 14:05:02 +0000 (14:05 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 28 Dec 2011 14:05:02 +0000 (14:05 +0000)
1  2 
source/blender/blenloader/intern/writefile.c
source/blender/makesdna/DNA_mesh_types.h
source/blender/windowmanager/intern/wm_operators.c

index 6f84d89c00a409a292791ffb738c89218a046bec,e9c14404057dcc361e17ab3f78133deb9dc460ff..c1759aa80fdf3851202143d7d23d277c3602a381
@@@ -152,7 -152,6 +152,7 @@@ Any case: direct data is ALWAYS after t
  #include "BKE_modifier.h"
  #include "BKE_fcurve.h"
  #include "BKE_pointcache.h"
 +#include "BKE_mesh.h"
  
  #include "BLO_writefile.h"
  #include "BLO_readfile.h"
@@@ -176,7 -175,7 +176,7 @@@ typedef struct 
        
        int tot, count, error, memsize;
  
- #ifdef USE_MESH_FORWARDS_COMAT
+ #ifdef USE_BMESH_SAVE_AS_COMPAT
        char use_mesh_compat; /* option to save with older mesh format */
  #endif
  } WriteData;
@@@ -1683,113 -1682,22 +1683,113 @@@ static void write_customdata(WriteData 
  static void write_meshs(WriteData *wd, ListBase *idbase)
  {
        Mesh *mesh;
 +      int save_for_old_blender= 0;
 +
 +#ifdef USE_MESH_FORWARDS_COMAT
 +      save_for_old_blender = wd->use_mesh_compat; /* option to save with older mesh format */
 +#endif
  
        mesh= idbase->first;
        while(mesh) {
                if(mesh->id.us>0 || wd->current) {
                        /* write LibData */
 -                      writestruct(wd, ID_ME, "Mesh", 1, mesh);
 +                      if (!save_for_old_blender) {
 +                              writestruct(wd, ID_ME, "Mesh", 1, mesh);
  
 -                      /* direct data */
 -                      if (mesh->id.properties) IDP_WriteProperty(mesh->id.properties, wd);
 -                      if (mesh->adt) write_animdata(wd, mesh->adt);
 +                              /* direct data */
 +                              if (mesh->id.properties) IDP_WriteProperty(mesh->id.properties, wd);
 +                              if (mesh->adt) write_animdata(wd, mesh->adt);
  
 -                      writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat);
 +                              writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat);
  
 -                      write_customdata(wd, &mesh->id, mesh->totvert, &mesh->vdata, -1, 0);
 -                      write_customdata(wd, &mesh->id, mesh->totedge, &mesh->edata, -1, 0);
 -                      write_customdata(wd, &mesh->id, mesh->totface, &mesh->fdata, -1, 0);
 +                              write_customdata(wd, &mesh->id, mesh->totvert, &mesh->vdata, -1, 0);
 +                              write_customdata(wd, &mesh->id, mesh->totedge, &mesh->edata, -1, 0);
 +                              write_customdata(wd, &mesh->id, mesh->totface, &mesh->fdata, -1, 0);
 +                              write_customdata(wd, &mesh->id, mesh->totloop, &mesh->ldata, -1, 0);
 +                              write_customdata(wd, &mesh->id, mesh->totpoly, &mesh->pdata, -1, 0);
 +                      }
 +                      else {
 +
 +#ifdef USE_MESH_FORWARDS_COMAT
 +
 +                              Mesh backup_mesh = {{0}};
 +
 +                              /* backup */
 +                              backup_mesh.mpoly = mesh->mpoly;
 +                              mesh->mpoly = NULL;
 +                              /* -- */
 +                              backup_mesh.mface = mesh->mface;
 +                              mesh->mface = NULL;
 +                              /* -- */
 +                              backup_mesh.totface = mesh->totface;
 +                              mesh->totface = 0;
 +                              /* -- */
 +                              backup_mesh.totpoly = mesh->totpoly;
 +                              mesh->totpoly = 0;
 +                              /* -- */
 +                              backup_mesh.totloop = mesh->totloop;
 +                              mesh->totloop = 0;
 +                              /* -- */
 +                              backup_mesh.fdata = mesh->fdata;
 +                              memset(&mesh->fdata, 0, sizeof(CustomData));
 +                              /* -- */
 +                              backup_mesh.pdata = mesh->pdata;
 +                              memset(&mesh->pdata, 0, sizeof(CustomData));
 +                              /* -- */
 +                              backup_mesh.ldata = mesh->ldata;
 +                              memset(&mesh->ldata, 0, sizeof(CustomData));
 +                              /* -- */
 +                              backup_mesh.edit_btmesh = mesh->edit_btmesh;
 +                              mesh->edit_btmesh = NULL;
 +                              /* backup */
 +
 +
 +                              /* now fill in polys to mfaces*/
 +                              mesh->totface= mesh_mpoly_to_mface(&mesh->fdata, &backup_mesh.ldata, &backup_mesh.pdata,
 +                                                                 mesh->totface, backup_mesh.totloop, backup_mesh.totpoly);
 +
 +                              mesh_update_customdata_pointers(mesh, FALSE);
 +
 +                              writestruct(wd, ID_ME, "Mesh", 1, mesh);
 +
 +                              /* direct data */
 +                              if (mesh->id.properties) IDP_WriteProperty(mesh->id.properties, wd);
 +                              if (mesh->adt) write_animdata(wd, mesh->adt);
 +
 +                              writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat);
 +
 +                              write_customdata(wd, &mesh->id, mesh->totvert, &mesh->vdata, -1, 0);
 +                              write_customdata(wd, &mesh->id, mesh->totedge, &mesh->edata, -1, 0);
 +                              write_customdata(wd, &mesh->id, mesh->totface, &mesh->fdata, -1, 0);
 +                              /* harmless for older blender versioins but _not_ writing these keeps file size down */
 +                              /*
 +                              write_customdata(wd, &mesh->id, mesh->totloop, &mesh->ldata, -1, 0);
 +                              write_customdata(wd, &mesh->id, mesh->totpoly, &mesh->pdata, -1, 0);
 +                              */
 +
 +                              /* restore */
 +                              mesh->mpoly = backup_mesh.mpoly;
 +                              mesh->totface = backup_mesh.totface;
 +                              mesh->totpoly = backup_mesh.totpoly;
 +                              mesh->totloop = backup_mesh.totloop;
 +                              /* -- */
 +                              mesh->mface = backup_mesh.mface;
 +                              /* -- */
 +                              CustomData_free(&mesh->fdata, mesh->totface);
 +                              /* -- */
 +                              mesh->fdata= backup_mesh.fdata;
 +                              /* -- */
 +                              mesh->pdata= backup_mesh.pdata;
 +                              /* -- */
 +                              mesh->ldata= backup_mesh.ldata;
 +                              /* -- */
 +                              mesh_update_customdata_pointers(mesh, FALSE);
 +                              /* --*/
 +                              mesh->edit_btmesh = backup_mesh.edit_btmesh; /* keep this after updating custom pointers */
 +                              /* restore */
 +
 +#endif /* USE_MESH_FORWARDS_COMAT */
 +                      }
                }
                mesh= mesh->id.next;
        }
@@@ -2717,7 -2625,7 +2717,7 @@@ static int write_file_handle(Main *main
  
        wd= bgnwrite(handle, compare, current);
  
- #ifdef USE_MESH_FORWARDS_COMAT
+ #ifdef USE_BMESH_SAVE_AS_COMPAT
        wd->use_mesh_compat = (write_flags & G_FILE_MESH_COMPAT) != 0;
  #endif
  
index bedb3e7429bbb6ea502c88876e1ce78f0b6e0d93,ca471bbabcde8f3926f1bb716edfe2a678fc078e..26a67c0504c441109befed38536a93dfdfcadfad
@@@ -49,11 -49,6 +49,11 @@@ struct MCol
  struct MSticky;
  struct Mesh;
  struct OcInfo;
 +struct MPoly;
 +struct MTexPoly;
 +struct MLoop;
 +struct MLoopUV;
 +struct MLoopCol;
  struct Multires;
  struct EditMesh;
  struct AnimData;
@@@ -67,35 -62,23 +67,35 @@@ typedef struct Mesh 
        struct Ipo *ipo  DNA_DEPRECATED;  /* old animation system, deprecated for 2.5 */
        struct Key *key;
        struct Material **mat;
 -
 -      struct MFace *mface;    /* array of mesh object mode faces */
 -      struct MTFace *mtface;  /* store face UV's and texture here */
 +      
 +      /*new face structures*/
 +      struct MPoly *mpoly;
 +      struct MTexPoly *mtpoly;
 +      struct MLoop *mloop;
 +      struct MLoopUV *mloopuv;
 +      struct MLoopCol *mloopcol;
 +
 +      /*mface stores the tesselation (triangulation) of the mesh,
 +        real faces are now stored in nface.*/
 +      struct MFace *mface;    /* array of mesh object mode faces for tesselation */
 +      struct MTFace *mtface;  /* store tesselation face UV's and texture here */
        struct TFace *tface;    /* depecrated, use mtface */
        struct MVert *mvert;    /* array of verts */
        struct MEdge *medge;    /* array of edges */
        struct MDeformVert *dvert;      /* deformgroup vertices */
 -      struct MCol *mcol;              /* array of colors, this must be the number of faces * 4 */
 +      
 +      /* array of colors for the tesselated faces, must be number of tesselated
 +         faces * 4 in length */
 +      struct MCol *mcol;              
        struct MSticky *msticky;
        struct Mesh *texcomesh;
        struct MSelect *mselect;
        
 -      struct EditMesh *edit_mesh;     /* not saved in file! */
 +      struct BMEditMesh *edit_btmesh; /* not saved in file! */
  
 -      struct CustomData vdata, edata, fdata;
 +      struct CustomData vdata, edata, fdata, pdata, ldata;
  
 -      int totvert, totedge, totface, totselect;
 +      int totvert, totedge, totface, totpoly, totloop, totselect;
        
        /* the last selected vertex/edge/face are used for the active face however
         * this means the active face must always be selected, this is to keep track
@@@ -214,7 -197,9 +214,7 @@@ typedef struct TFace 
  /* this is so we can save bmesh files that load in trunk, ignoring NGons
   * will eventually be removed */
  
- #define USE_MESH_FORWARDS_COMAT
 -#if 0 /* enable in bmesh branch only for now */
+ #define USE_BMESH_SAVE_AS_COMPAT
 -#endif
  
  
  #endif
index 22b1bf1b5080dc909709de5c763f9c350c8ff805,29d2f9392b2898eb2ec151cda4aa29499f5bd385..e528bb52bc980e0283092fe58233dbd722a77883
@@@ -46,7 -46,7 +46,7 @@@
  #include "DNA_scene_types.h"
  #include "DNA_userdef_types.h"
  #include "DNA_windowmanager_types.h"
- #include "DNA_mesh_types.h" /* only for USE_MESH_FORWARDS_COMAT */
+ #include "DNA_mesh_types.h" /* only for USE_BMESH_SAVE_AS_COMPAT */
  
  #include "BLF_translation.h"
  
@@@ -1973,10 -1973,6 +1973,10 @@@ static int wm_save_as_mainfile_exec(bCo
        else                                                                                    fileflags &= ~G_FILE_COMPRESS;
        if(RNA_boolean_get(op->ptr, "relative_remap"))  fileflags |=  G_FILE_RELATIVE_REMAP;
        else                                                                                    fileflags &= ~G_FILE_RELATIVE_REMAP;
 +#ifdef USE_MESH_FORWARDS_COMAT
 +      if(RNA_boolean_get(op->ptr, "use_mesh_compat")) fileflags |=  G_FILE_MESH_COMPAT;
 +      else                                                                                    fileflags &= ~G_FILE_MESH_COMPAT;
 +#endif
  
        if ( WM_write_file(C, path, fileflags, op->reports, copy) != 0)
                return OPERATOR_CANCELLED;
@@@ -2016,7 -2012,7 +2016,7 @@@ static void WM_OT_save_as_mainfile(wmOp
        RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file");
        RNA_def_boolean(ot->srna, "relative_remap", 1, "Remap Relative", "Remap relative paths when saving in a different directory");
        RNA_def_boolean(ot->srna, "copy", 0, "Save Copy", "Save a copy of the actual working state but does not make saved file active");
- #ifdef USE_MESH_FORWARDS_COMAT
+ #ifdef USE_BMESH_SAVE_AS_COMPAT
        RNA_def_boolean(ot->srna, "use_mesh_compat", 0, "Legacy Mesh Format", "Save using legacy mesh format (no ngons)");
  #endif
  }