Animation: Make Vertex Weight Edit modifier inclusive #108286

Merged
Nate Rupsis merged 20 commits from nrupsis/blender:vertext-weights-inclusive into main 2023-07-12 17:52:58 +02:00
3 changed files with 30 additions and 6 deletions

View File

@ -8,6 +8,8 @@
#define DNA_DEPRECATED_ALLOW
#include <cmath>
#include "CLG_log.h"
#include "DNA_brush_types.h"
@ -134,6 +136,24 @@ static void version_geometry_nodes_add_realize_instance_nodes(bNodeTree *ntree)
}
}
/* Version VertexWeightEdit modifier to make existing weights exclusive of the threshold. */
static void version_vertex_weight_edit_preserve_threshold_exclusivity(Main *bmain)

Maybe add a comment that explains what these numbers are. They are just the min/max values ±1, but that might not be obvious to everybody.

Maybe add a comment that explains what these numbers are. They are just the min/max values ±1, but that might not be obvious to everybody.
{
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
if (ob->type != OB_MESH) {
continue;
}
LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
if (md->type == eModifierType_WeightVGEdit) {
WeightVGEditModifierData *wmd = reinterpret_cast<WeightVGEditModifierData *>(md);
wmd->add_threshold = nexttoward(wmd->add_threshold, 2.0);
wmd->rem_threshold = nexttoward(wmd->rem_threshold, -1.0);
}
}
}
}
static void version_mesh_crease_generic(Main &bmain)
{

Formatting

Formatting
LISTBASE_FOREACH (Mesh *, mesh, &bmain.meshes) {
@ -337,6 +357,10 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
if (!MAIN_VERSION_ATLEAST(bmain, 400, 11)) {
version_vertex_weight_edit_preserve_threshold_exclusivity(bmain);
}
/**
* Versioning code until next subversion bump goes here.
*

View File

@ -5218,21 +5218,21 @@ static void rna_def_modifier_weightvgedit(BlenderRNA *brna)
prop = RNA_def_property(srna, "add_threshold", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, nullptr, "add_threshold");
nrupsis marked this conversation as resolved Outdated

My bet is that this PR started before the code was converted to C++. Be sure to use nullptr instead of NULL in C++ code.

My bet is that this PR started before the code was converted to C++. Be sure to use `nullptr` instead of `NULL` in C++ code.

My bet is that this PR started before the code was converted to C++. Be sure to use nullptr instead of NULL in C++ code.

My bet is that this PR started before the code was converted to C++. Be sure to use `nullptr` instead of `NULL` in C++ code.
RNA_def_property_range(prop, 0.0, 1.0);
RNA_def_property_range(prop, -1000.0, 1000.0);
dr.sybren marked this conversation as resolved

The PR description says nothing about expanding the allowed ranges for these thresholds. Is this a necessity for the change from exclusive to inclusive? If not, it'll be better to put into a separate commit.

The PR description says nothing about expanding the allowed ranges for these thresholds. Is this a necessity for the change from exclusive to inclusive? If not, it'll be better to put into a separate commit.
Review

This change doesn't impact the exclusive to inclusive, however it is required for the versioning code to work.
Should the whole versioning bit be moved into a new PR/commit?

This change doesn't impact the exclusive to inclusive, however it is required for the versioning code to work. Should the whole versioning bit be moved into a new PR/commit?

No it's better to have the change + the versioning in one commit. I just didn't realise that this was necessary for the versioning.

No it's better to have the change + the versioning in one commit. I just didn't realise that this was necessary for the versioning.
RNA_def_property_ui_range(prop, 0.0, 1.0, 1, -1);
RNA_def_property_ui_text(prop,
"Add Threshold",
"Lower bound for a vertex's weight "
"Lower (inclusive) bound for a vertex's weight "
"to be added to the vgroup");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
prop = RNA_def_property(srna, "remove_threshold", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, nullptr, "rem_threshold");
RNA_def_property_range(prop, 0.0, 1.0);
RNA_def_property_range(prop, -1000.0, 1000.0);
RNA_def_property_ui_range(prop, 0.0, 1.0, 1, -1);
RNA_def_property_ui_text(prop,
"Remove Threshold",
"Upper bound for a vertex's weight "
"Upper (inclusive) bound for a vertex's weight "
"to be removed from the vgroup");
RNA_def_property_update(prop, 0, "rna_Modifier_update");

View File

@ -296,7 +296,7 @@ void weightvg_update_vg(MDeformVert *dvert,
/* If the vertex is in this vgroup, remove it if needed, or just update it. */
if (dw != nullptr) {
if (do_rem && w < rem_thresh) {
if (do_rem && w <= rem_thresh) {
BKE_defvert_remove_group(dv, dw);
}
else {
@ -304,7 +304,7 @@ void weightvg_update_vg(MDeformVert *dvert,
}
}
/* Else, add it if needed! */
else if (do_add && w > add_thresh) {
else if (do_add && w >= add_thresh) {
BKE_defvert_add_index_notest(dv, defgrp_idx, w);
}
}