[Bf-blender-cvs] [11ab64cf8d6] temp-legacy-mesh-format-option: Blend Write: Add option for legacy mesh format

Hans Goudey noreply at git.blender.org
Sun May 29 14:18:10 CEST 2022


Commit: 11ab64cf8d6bf6ad6c6f5c2c02ce7813d801f170
Author: Hans Goudey
Date:   Sun May 29 14:17:21 2022 +0200
Branches: temp-legacy-mesh-format-option
https://developer.blender.org/rB11ab64cf8d6bf6ad6c6f5c2c02ce7813d801f170

Blend Write: Add option for legacy mesh format

===================================================================

M	source/blender/blenloader/BLO_read_write.h
M	source/blender/blenloader/BLO_writefile.h
M	source/blender/blenloader/intern/writefile.c
M	source/blender/windowmanager/intern/wm_files.c

===================================================================

diff --git a/source/blender/blenloader/BLO_read_write.h b/source/blender/blenloader/BLO_read_write.h
index 536c3989aff..5d0bb8231d1 100644
--- a/source/blender/blenloader/BLO_read_write.h
+++ b/source/blender/blenloader/BLO_read_write.h
@@ -181,6 +181,8 @@ void BLO_write_string(BlendWriter *writer, const char *data_ptr);
  */
 bool BLO_write_is_undo(BlendWriter *writer);
 
+bool BLO_write_use_legacy_mesh_format(const BlendWriter *writer);
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/blenloader/BLO_writefile.h b/source/blender/blenloader/BLO_writefile.h
index 93f1ea5090f..a2c2c036f5a 100644
--- a/source/blender/blenloader/BLO_writefile.h
+++ b/source/blender/blenloader/BLO_writefile.h
@@ -44,6 +44,7 @@ struct BlendFileWriteParams {
   uint use_save_versions : 1;
   /** On write, restore paths after editing them (see #BLO_WRITE_PATH_REMAP_RELATIVE). */
   uint use_save_as_copy : 1;
+  uint use_legacy_mesh_format : 1;
   uint use_userdef : 1;
   const struct BlendThumbnail *thumb;
 };
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 65c42545a77..35698c94c4f 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -422,6 +422,8 @@ typedef struct {
   /** When true, write to #WriteData.current, could also call 'is_undo'. */
   bool use_memfile;
 
+  bool use_legacy_mesh_format;
+
   /**
    * Wrap writing, so we can use zstd or
    * other compression types later, see: G_FILE_COMPRESS
@@ -1083,6 +1085,7 @@ static bool write_file_handle(Main *mainvar,
                               MemFile *current,
                               int write_flags,
                               bool use_userdef,
+                              const bool use_legacy_mesh_format,
                               const BlendThumbnail *thumb)
 {
   BHead bhead;
@@ -1093,6 +1096,7 @@ static bool write_file_handle(Main *mainvar,
   blo_split_main(&mainlist, mainvar);
 
   wd = mywrite_begin(ww, compare, current);
+  wd->use_legacy_mesh_format = use_legacy_mesh_format;
   BlendWriter writer = {wd};
 
   sprintf(buf,
@@ -1432,7 +1436,8 @@ bool BLO_write_file(Main *mainvar,
   }
 
   /* actual file writing */
-  const bool err = write_file_handle(mainvar, &ww, NULL, NULL, write_flags, use_userdef, thumb);
+  const bool err = write_file_handle(
+      mainvar, &ww, NULL, NULL, write_flags, use_userdef, params->use_legacy_mesh_format, thumb);
 
   ww.close(&ww);
 
@@ -1476,7 +1481,7 @@ bool BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int w
   bool use_userdef = false;
 
   const bool err = write_file_handle(
-      mainvar, NULL, compare, current, write_flags, use_userdef, NULL);
+      mainvar, NULL, compare, current, write_flags, use_userdef, false, NULL);
 
   return (err == 0);
 }
@@ -1605,4 +1610,9 @@ bool BLO_write_is_undo(BlendWriter *writer)
   return writer->wd->use_memfile;
 }
 
+bool BLO_write_use_legacy_mesh_format(const BlendWriter *writer)
+{
+  return writer->wd->use_legacy_mesh_format;
+}
+
 /** \} */
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index bee7e71df54..0747e65406e 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -1714,6 +1714,7 @@ static bool wm_file_write(bContext *C,
                           int fileflags,
                           eBLO_WritePathRemap remap_mode,
                           bool use_save_as_copy,
+                          const bool use_legacy_mesh_format,
                           ReportList *reports)
 {
   Main *bmain = CTX_data_main(C);
@@ -1825,6 +1826,7 @@ static bool wm_file_write(bContext *C,
                          .remap_mode = remap_mode,
                          .use_save_versions = true,
                          .use_save_as_copy = use_save_as_copy,
+                         .use_legacy_mesh_format = use_legacy_mesh_format,
                          .thumb = thumb,
                      },
                      reports)) {
@@ -3060,6 +3062,9 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
   const bool is_save_as = (op->type->invoke == wm_save_as_mainfile_invoke);
   const bool use_save_as_copy = (RNA_struct_property_is_set(op->ptr, "copy") &&
                                  RNA_boolean_get(op->ptr, "copy"));
+  const bool use_legacy_mesh_format = (RNA_struct_property_is_set(op->ptr,
+                                                                  "use_legacy_mesh_format") &&
+                                       RNA_boolean_get(op->ptr, "use_legacy_mesh_format"));
 
   /* We could expose all options to the users however in most cases remapping
    * existing relative paths is a good default.
@@ -3103,7 +3108,8 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
   /* set compression flag */
   SET_FLAG_FROM_TEST(fileflags, RNA_boolean_get(op->ptr, "compress"), G_FILE_COMPRESS);
 
-  const bool ok = wm_file_write(C, path, fileflags, remap_mode, use_save_as_copy, op->reports);
+  const bool ok = wm_file_write(
+      C, path, fileflags, remap_mode, use_save_as_copy, use_legacy_mesh_format, op->reports);
 
   if ((op->flag & OP_IS_INVOKE) == 0) {
     /* OP_IS_INVOKE is set when the operator is called from the GUI.
@@ -3194,6 +3200,13 @@ void WM_OT_save_as_mainfile(wmOperatorType *ot)
       "Save Copy",
       "Save a copy of the actual working state but does not make saved file active");
   RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+  prop = RNA_def_boolean(
+      ot->srna,
+      "use_legacy_mesh_format",
+      false,
+      "Legacy Mesh Format",
+      "Save mesh data with a legacy format that can be read by earlier versions");
+  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
 static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))



More information about the Bf-blender-cvs mailing list