Compare commits

...

12 Commits

4 changed files with 28 additions and 3 deletions

View File

@@ -181,6 +181,8 @@ void BLO_write_string(BlendWriter *writer, const char *data_ptr);
*/ */
bool BLO_write_is_undo(BlendWriter *writer); bool BLO_write_is_undo(BlendWriter *writer);
bool BLO_write_use_legacy_mesh_format(const BlendWriter *writer);
/** \} */ /** \} */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */

View File

@@ -44,6 +44,7 @@ struct BlendFileWriteParams {
uint use_save_versions : 1; uint use_save_versions : 1;
/** On write, restore paths after editing them (see #BLO_WRITE_PATH_REMAP_RELATIVE). */ /** On write, restore paths after editing them (see #BLO_WRITE_PATH_REMAP_RELATIVE). */
uint use_save_as_copy : 1; uint use_save_as_copy : 1;
uint use_legacy_mesh_format : 1;
uint use_userdef : 1; uint use_userdef : 1;
const struct BlendThumbnail *thumb; const struct BlendThumbnail *thumb;
}; };

View File

@@ -422,6 +422,8 @@ typedef struct {
/** When true, write to #WriteData.current, could also call 'is_undo'. */ /** When true, write to #WriteData.current, could also call 'is_undo'. */
bool use_memfile; bool use_memfile;
bool use_legacy_mesh_format;
/** /**
* Wrap writing, so we can use zstd or * Wrap writing, so we can use zstd or
* other compression types later, see: G_FILE_COMPRESS * other compression types later, see: G_FILE_COMPRESS
@@ -1083,6 +1085,7 @@ static bool write_file_handle(Main *mainvar,
MemFile *current, MemFile *current,
int write_flags, int write_flags,
bool use_userdef, bool use_userdef,
const bool use_legacy_mesh_format,
const BlendThumbnail *thumb) const BlendThumbnail *thumb)
{ {
BHead bhead; BHead bhead;
@@ -1093,6 +1096,7 @@ static bool write_file_handle(Main *mainvar,
blo_split_main(&mainlist, mainvar); blo_split_main(&mainlist, mainvar);
wd = mywrite_begin(ww, compare, current); wd = mywrite_begin(ww, compare, current);
wd->use_legacy_mesh_format = use_legacy_mesh_format;
BlendWriter writer = {wd}; BlendWriter writer = {wd};
sprintf(buf, sprintf(buf,
@@ -1432,7 +1436,8 @@ bool BLO_write_file(Main *mainvar,
} }
/* actual file writing */ /* 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); ww.close(&ww);
@@ -1476,7 +1481,7 @@ bool BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int w
bool use_userdef = false; bool use_userdef = false;
const bool err = write_file_handle( 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); return (err == 0);
} }
@@ -1605,4 +1610,9 @@ bool BLO_write_is_undo(BlendWriter *writer)
return writer->wd->use_memfile; return writer->wd->use_memfile;
} }
bool BLO_write_use_legacy_mesh_format(const BlendWriter *writer)
{
return writer->wd->use_legacy_mesh_format;
}
/** \} */ /** \} */

View File

@@ -1719,6 +1719,7 @@ static bool wm_file_write(bContext *C,
int fileflags, int fileflags,
eBLO_WritePathRemap remap_mode, eBLO_WritePathRemap remap_mode,
bool use_save_as_copy, bool use_save_as_copy,
const bool use_legacy_mesh_format,
ReportList *reports) ReportList *reports)
{ {
Main *bmain = CTX_data_main(C); Main *bmain = CTX_data_main(C);
@@ -1830,6 +1831,7 @@ static bool wm_file_write(bContext *C,
.remap_mode = remap_mode, .remap_mode = remap_mode,
.use_save_versions = true, .use_save_versions = true,
.use_save_as_copy = use_save_as_copy, .use_save_as_copy = use_save_as_copy,
.use_legacy_mesh_format = use_legacy_mesh_format,
.thumb = thumb, .thumb = thumb,
}, },
reports)) { reports)) {
@@ -3064,6 +3066,8 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
char path[FILE_MAX]; char path[FILE_MAX];
const bool is_save_as = (op->type->invoke == wm_save_as_mainfile_invoke); const bool is_save_as = (op->type->invoke == wm_save_as_mainfile_invoke);
const bool use_save_as_copy = is_save_as && RNA_boolean_get(op->ptr, "copy"); const bool use_save_as_copy = is_save_as && RNA_boolean_get(op->ptr, "copy");
const bool use_legacy_mesh_format = is_save_as &&
RNA_boolean_get(op->ptr, "use_legacy_mesh_format");
/* We could expose all options to the users however in most cases remapping /* We could expose all options to the users however in most cases remapping
* existing relative paths is a good default. * existing relative paths is a good default.
@@ -3107,7 +3111,8 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
/* set compression flag */ /* set compression flag */
SET_FLAG_FROM_TEST(fileflags, RNA_boolean_get(op->ptr, "compress"), G_FILE_COMPRESS); 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) { if ((op->flag & OP_IS_INVOKE) == 0) {
/* OP_IS_INVOKE is set when the operator is called from the GUI. /* OP_IS_INVOKE is set when the operator is called from the GUI.
@@ -3198,6 +3203,13 @@ void WM_OT_save_as_mainfile(wmOperatorType *ot)
"Save Copy", "Save Copy",
"Save a copy of the actual working state but does not make saved file active"); "Save a copy of the actual working state but does not make saved file active");
RNA_def_property_flag(prop, PROP_SKIP_SAVE); 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)) static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))