Sometimes .blend files have compatibility issues between Blender versions, because .blend files depended on the specific order of geometry elements generated by some nodes/modifiers (#112746, #113018). While we make guarantees about the order in some places, that is relatively rare, because it makes future improvements much harder. The functionality in this patch makes it easier for users to notice when they depend on things that are not expected to be stable between Blender builds. This is achieved by adding a new global flag which indicates whether some algorithms should randomize their output. The functionality can be toggled on or off by searching for `Set Geometry Randomization`. If there are no differences (or acceptable minor ones) when the flag is on or off, one can be reasonably sure that one does not on unspecified behavior (can't be 100% sure though, because randomization might be missing in some places). If there are big differences, one should consider fixing the file before it comes to an actual breakage in the next Blender version. Currently, the setting is only available when `Developer Extras` is turned on, because the setting is in no menu. With this patch, if we get bug reports with compatibility issues caused by depending on indices, one of the following three cases should always apply: * We actually accidentally broke something, which requires a fix commit. * Turning on geometry randomization shows that the .blend file depends on things it shouldn't depend on. In this case the user has to fix the file. * We are missing geometry randomization somewhere, which requires a fix commit. Pull Request: https://projects.blender.org/blender/blender/pulls/113030
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "WM_api.hh"
|
|
|
|
#include "BKE_context.h"
|
|
#include "BKE_global.h"
|
|
#include "BKE_main.h"
|
|
|
|
#include "DEG_depsgraph.hh"
|
|
|
|
#include "RNA_access.hh"
|
|
#include "RNA_define.hh"
|
|
|
|
#include "geometry_intern.hh"
|
|
|
|
namespace blender::ed::geometry {
|
|
|
|
static int geometry_randomization_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|
{
|
|
RNA_boolean_set(op->ptr, "value", G.randomize_geometry_element_order);
|
|
return WM_operator_props_popup(C, op, event);
|
|
}
|
|
|
|
static int geometry_randomization_exec(bContext *C, wmOperator *op)
|
|
{
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
G.randomize_geometry_element_order = RNA_boolean_get(op->ptr, "value");
|
|
|
|
LISTBASE_FOREACH (Object *, object, &bmain->objects) {
|
|
DEG_id_tag_update(&object->id, ID_RECALC_GEOMETRY);
|
|
}
|
|
WM_event_add_notifier(C, NC_WINDOW, nullptr);
|
|
return OPERATOR_FINISHED;
|
|
}
|
|
|
|
void GEOMETRY_OT_geometry_randomization(wmOperatorType *ot)
|
|
{
|
|
ot->name = "Set Geometry Randomization";
|
|
ot->idname = "GEOMETRY_OT_geometry_randomization";
|
|
ot->description = "Toggle geometry randomization for debugging purposes";
|
|
|
|
ot->exec = geometry_randomization_exec;
|
|
ot->invoke = geometry_randomization_invoke;
|
|
ot->flag |= OPTYPE_UNDO | OPTYPE_REGISTER;
|
|
|
|
RNA_def_boolean(ot->srna,
|
|
"value",
|
|
false,
|
|
"Value",
|
|
"Randomize the order of geometry elements (e.g. vertices or edges) after some "
|
|
"operations where there are no guarantees about the order. This avoids "
|
|
"accidentally depending on something that may change in the future");
|
|
}
|
|
|
|
} // namespace blender::ed::geometry
|