WIP loading bmesh in trunk, some conversion functions for this purpose.
[blender.git] / source / blender / blenloader / intern / writefile.c
index 11a80d0d41a6b4763ae8c80899e4c72368a30546..e9c14404057dcc361e17ab3f78133deb9dc460ff 100644 (file)
@@ -174,6 +174,10 @@ typedef struct {
        MemFile *compare, *current;
        
        int tot, count, error, memsize;
+
+#ifdef USE_BMESH_SAVE_AS_COMPAT
+       char use_mesh_compat; /* option to save with older mesh format */
+#endif
 } WriteData;
 
 static WriteData *writedata_new(int file)
@@ -1666,7 +1670,8 @@ static void write_customdata(WriteData *wd, ID *id, int count, CustomData *data,
                                writestruct(wd, DATA, structname, datasize, layer->data);
                        }
                        else
-                               printf("error: this CustomDataLayer must not be written to file\n");
+                               printf("%s error: layer '%s':%d - can't be written to file\n",
+                                      __func__, structname, layer->type);
                }
        }
 
@@ -1690,27 +1695,9 @@ static void write_meshs(WriteData *wd, ListBase *idbase)
 
                        writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat);
 
-                       if(mesh->pv) {
-                               write_customdata(wd, &mesh->id, mesh->pv->totvert, &mesh->vdata, -1, 0);
-                               write_customdata(wd, &mesh->id, mesh->pv->totedge, &mesh->edata,
-                                       CD_MEDGE, mesh->totedge);
-                               write_customdata(wd, &mesh->id, mesh->pv->totface, &mesh->fdata,
-                                       CD_MFACE, mesh->totface);
-                       }
-                       else {
-                               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);
-                       }
-
-                       /* PMV data */
-                       if(mesh->pv) {
-                               writestruct(wd, DATA, "PartialVisibility", 1, mesh->pv);
-                               writedata(wd, DATA, sizeof(unsigned int)*mesh->pv->totvert, mesh->pv->vert_map);
-                               writedata(wd, DATA, sizeof(int)*mesh->pv->totedge, mesh->pv->edge_map);
-                               writestruct(wd, DATA, "MFace", mesh->pv->totface, mesh->pv->old_faces);
-                               writestruct(wd, DATA, "MEdge", mesh->pv->totedge, mesh->pv->old_edges);
-                       }
+                       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= mesh->id.next;
        }
@@ -1815,6 +1802,7 @@ static void write_textures(WriteData *wd, ListBase *idbase)
                                if(tex->pd->falloff_curve) write_curvemapping(wd, tex->pd->falloff_curve);
                        }
                        if(tex->type == TEX_VOXELDATA) writestruct(wd, DATA, "VoxelData", 1, tex->vd);
+                       if(tex->type == TEX_OCEAN && tex->ot) writestruct(wd, DATA, "OceanTex", 1, tex->ot);
                        
                        /* nodetree is integral part of texture, no libdata */
                        if(tex->nodetree) {
@@ -2590,7 +2578,10 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar)
        fg.curscene= screen->scene;
        fg.displaymode= G.displaymode;
        fg.winpos= G.winpos;
-       fg.fileflags= (fileflags & ~(G_FILE_NO_UI|G_FILE_RELATIVE_REMAP));      // prevent to save this, is not good convention, and feature with concerns...
+
+       /* prevent to save this, is not good convention, and feature with concerns... */
+       fg.fileflags= (fileflags & ~(G_FILE_NO_UI|G_FILE_RELATIVE_REMAP|G_FILE_MESH_COMPAT));
+
        fg.globalf= G.f;
        BLI_strncpy(fg.filename, mainvar->name, sizeof(fg.filename));
 
@@ -2633,7 +2624,11 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
        blo_split_main(&mainlist, mainvar);
 
        wd= bgnwrite(handle, compare, current);
-       
+
+#ifdef USE_BMESH_SAVE_AS_COMPAT
+       wd->use_mesh_compat = (write_flags & G_FILE_MESH_COMPAT) != 0;
+#endif
+
        sprintf(buf, "BLENDER%c%c%.3d", (sizeof(void*)==8)?'-':'_', (ENDIAN_ORDER==B_ENDIAN)?'V':'v', BLENDER_VERSION);
        mywrite(wd, buf, 12);
 
@@ -2695,7 +2690,7 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
 /* return: success(0), failure(1) */
 static int do_history(const char *name, ReportList *reports)
 {
-       char tempname1[FILE_MAXDIR+FILE_MAXFILE], tempname2[FILE_MAXDIR+FILE_MAXFILE];
+       char tempname1[FILE_MAX], tempname2[FILE_MAX];
        int hisnr= U.versions;
        
        if(U.versions==0) return 0;
@@ -2729,8 +2724,8 @@ static int do_history(const char *name, ReportList *reports)
 /* return: success (1) */
 int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportList *reports, int *thumb)
 {
-       char userfilename[FILE_MAXDIR+FILE_MAXFILE];
-       char tempname[FILE_MAXDIR+FILE_MAXFILE+1];
+       char userfilename[FILE_MAX];
+       char tempname[FILE_MAX+1];
        int file, err, write_user_block;
 
        /* open temporary file, so we preserve the original in case we crash */
@@ -2744,8 +2739,8 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
 
        /* remapping of relative paths to new file location */
        if(write_flags & G_FILE_RELATIVE_REMAP) {
-               char dir1[FILE_MAXDIR+FILE_MAXFILE];
-               char dir2[FILE_MAXDIR+FILE_MAXFILE];
+               char dir1[FILE_MAX];
+               char dir2[FILE_MAX];
                BLI_split_dir_part(filepath, dir1, sizeof(dir1));
                BLI_split_dir_part(mainvar->name, dir2, sizeof(dir2));
 
@@ -2796,7 +2791,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
 
        if(write_flags & G_FILE_COMPRESS) {
                /* compressed files have the same ending as regular files... only from 2.4!!! */
-               char gzname[FILE_MAXDIR+FILE_MAXFILE+4];
+               char gzname[FILE_MAX+4];
                int ret;
 
                /* first write compressed to separate @.gz */