diff options
Diffstat (limited to 'source/blender/blenloader/intern/writefile.c')
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 130 |
1 files changed, 122 insertions, 8 deletions
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index a7f6354583f..f1b76cb56bf 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -156,6 +156,7 @@ Any case: direct data is ALWAYS after the lib block #include "BKE_modifier.h" #include "BKE_fcurve.h" #include "BKE_pointcache.h" +#include "BKE_mesh.h" #include "BLO_writefile.h" #include "BLO_readfile.h" @@ -1686,22 +1687,135 @@ static void write_customdata(WriteData *wd, ID *id, int count, CustomData *data, static void write_meshs(WriteData *wd, ListBase *idbase) { Mesh *mesh; + int save_for_old_blender= 0; + +#ifdef USE_BMESH_SAVE_AS_COMPAT + 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) { + +#ifdef USE_BMESH_SAVE_WITHOUT_MFACE + Mesh backup_mesh = {{0}}; + /* cache only - dont write */ + backup_mesh.mface = mesh->mface; + mesh->mface = NULL; + /* -- */ + backup_mesh.totface = mesh->totface; + mesh->totface = 0; + /* -- */ +#endif /* USE_BMESH_SAVE_WITHOUT_MFACE */ + + 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); + /* fdata is really a dummy - written so slots align */ + 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); + +#ifdef USE_BMESH_SAVE_WITHOUT_MFACE + /* cache only - dont write */ + mesh->mface = backup_mesh.mface; + /* -- */ + mesh->totface = backup_mesh.totface; +#endif /* USE_BMESH_SAVE_WITHOUT_MFACE */ - /* direct data */ - if (mesh->id.properties) IDP_WriteProperty(mesh->id.properties, wd); - if (mesh->adt) write_animdata(wd, mesh->adt); + } + else { - writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat); +#ifdef USE_BMESH_SAVE_AS_COMPAT - 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); + 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->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->totface = backup_mesh.totface; + mesh->totpoly = backup_mesh.totpoly; + mesh->totloop = backup_mesh.totloop; + /* -- */ + mesh_update_customdata_pointers(mesh, FALSE); + /* --*/ + mesh->edit_btmesh = backup_mesh.edit_btmesh; /* keep this after updating custom pointers */ + /* restore */ + +#endif /* USE_BMESH_SAVE_AS_COMPAT */ + } } mesh= mesh->id.next; } |