Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Friedrich <rbx775>2020-12-02 12:35:04 +0300
committerBastien Montagne <bastien@blender.org>2020-12-02 13:20:03 +0300
commite4204a3979c4ffba0f90dac1ba6a2cc72fde96c3 (patch)
tree4a49f91ddbab450fc48a3e9db78614531511a3c4
parent84451f89f5c1ca84a3647da6906f95f6fe9f6c1f (diff)
Add Custom Falloff Curve to the Vertex Weight Proximity Modifier.
The Vertex Weight Edit Modifier already got the Custom Curve, there was no real reason for the proximity not to have it as well. With some fixes by Bastien Montagne (@mont29). Reviewed By: mont29 Differential Revision: https://developer.blender.org/D9594
-rw-r--r--source/blender/blenloader/intern/versioning_290.c12
-rw-r--r--source/blender/makesdna/DNA_modifier_types.h4
-rw-r--r--source/blender/makesrna/intern/rna_modifier.c7
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgproximity.c62
4 files changed, 76 insertions, 9 deletions
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 41064b6b136..aca8d2f3439 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -1189,5 +1189,17 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
+
+ LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
+ LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
+ if (md->type == eModifierType_WeightVGProximity) {
+ WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *)md;
+ if (wmd->cmap_curve == NULL) {
+ wmd->cmap_curve = BKE_curvemapping_add(1, 0.0, 0.0, 1.0, 1.0);
+ BKE_curvemapping_init(wmd->cmap_curve);
+ }
+ }
+ }
+ }
}
}
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 232fca062fa..7b5bdac47f5 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1583,6 +1583,10 @@ typedef struct WeightVGProximityModifierData {
/** Name of vertex group to modify/weight. MAX_VGROUP_NAME. */
char defgrp_name[64];
+
+ /* Mapping stuff. */
+ /** The custom mapping curve!. */
+ struct CurveMapping *cmap_curve;
/* Proximity modes. */
int proximity_mode;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 2df42b87c07..c0f3197b2d1 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -5293,7 +5293,7 @@ static void rna_def_modifier_weightvgproximity(BlenderRNA *brna)
static const EnumPropertyItem weightvg_proximity_falloff_type_items[] = {
{MOD_WVG_MAPPING_NONE, "LINEAR", ICON_LINCURVE, "Linear", "Null action"},
- /* No curve mapping here! */
+ {MOD_WVG_MAPPING_CURVE, "CURVE", ICON_RNDCURVE, "Custom Curve", ""},
{MOD_WVG_MAPPING_SHARP, "SHARP", ICON_SHARPCURVE, "Sharp", ""},
{MOD_WVG_MAPPING_SMOOTH, "SMOOTH", ICON_SMOOTHCURVE, "Smooth", ""},
{MOD_WVG_MAPPING_ROOT, "ROOT", ICON_ROOTCURVE, "Root", ""},
@@ -5381,6 +5381,11 @@ static void rna_def_modifier_weightvgproximity(BlenderRNA *brna)
"Normalize the resulting weights (otherwise they are only clamped within [0.0, 1.0] range)");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
+ prop = RNA_def_property(srna, "map_curve", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "cmap_curve");
+ RNA_def_property_ui_text(prop, "Mapping Curve", "Custom mapping curve");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
RNA_define_lib_overridable(false);
/* Common masking properties. */
diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c
index 9b21c77268e..7232ffd3d9d 100644
--- a/source/blender/modifiers/intern/MOD_weightvgproximity.c
+++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c
@@ -31,6 +31,7 @@
#include "BLT_translation.h"
+#include "DNA_color_types.h" /* CurveMapping. */
#include "DNA_defaults.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -39,6 +40,7 @@
#include "DNA_screen_types.h"
#include "BKE_bvhutils.h"
+#include "BKE_colortools.h" /* CurveMapping. */
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_customdata.h"
@@ -54,6 +56,8 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "BLO_read_write.h"
+
#include "RNA_access.h"
#include "DEG_depsgraph_build.h"
@@ -258,7 +262,8 @@ static void do_map(Object *ob,
const float min_d,
const float max_d,
short mode,
- const bool do_invert_mapping)
+ const bool do_invert_mapping,
+ CurveMapping *cmap)
{
const float range_inv = 1.0f / (max_d - min_d); /* invert since multiplication is faster */
uint i = nidx;
@@ -294,7 +299,6 @@ static void do_map(Object *ob,
}
}
- BLI_assert(mode != MOD_WVG_MAPPING_CURVE);
if (do_invert_mapping || mode != MOD_WVG_MAPPING_NONE) {
RNG *rng = NULL;
@@ -302,7 +306,7 @@ static void do_map(Object *ob,
rng = BLI_rng_new_srandom(BLI_ghashutil_strhash(ob->id.name + 2));
}
- weightvg_do_map(nidx, weights, mode, do_invert_mapping, NULL, rng);
+ weightvg_do_map(nidx, weights, mode, do_invert_mapping, cmap, rng);
if (rng) {
BLI_rng_free(rng);
@@ -320,6 +324,25 @@ static void initData(ModifierData *md)
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(wmd, modifier));
MEMCPY_STRUCT_AFTER(wmd, DNA_struct_default_get(WeightVGProximityModifierData), modifier);
+
+ wmd->cmap_curve = BKE_curvemapping_add(1, 0.0, 0.0, 1.0, 1.0);
+ BKE_curvemapping_init(wmd->cmap_curve);
+}
+
+static void freeData(ModifierData *md)
+{
+ WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *)md;
+ BKE_curvemapping_free(wmd->cmap_curve);
+}
+
+static void copyData(const ModifierData *md, ModifierData *target, const int flag)
+{
+ const WeightVGProximityModifierData *wmd = (const WeightVGProximityModifierData *)md;
+ WeightVGProximityModifierData *twmd = (WeightVGProximityModifierData *)target;
+
+ BKE_modifier_copydata_generic(md, target, flag);
+
+ twmd->cmap_curve = BKE_curvemapping_copy(wmd->cmap_curve);
}
static void requiredDataMask(Object *UNUSED(ob),
@@ -587,7 +610,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
wmd->min_dist,
wmd->max_dist,
wmd->falloff_type,
- (wmd->proximity_flags & MOD_WVG_PROXIMITY_INVERT_FALLOFF) != 0);
+ (wmd->proximity_flags & MOD_WVG_PROXIMITY_INVERT_FALLOFF) != 0,
+ wmd->cmap_curve);
/* Do masking. */
struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
@@ -680,6 +704,9 @@ static void falloff_panel_draw(const bContext *UNUSED(C), Panel *panel)
sub = uiLayoutRow(row, true);
uiLayoutSetPropSep(sub, false);
uiItemR(row, ptr, "invert_falloff", 0, "", ICON_ARROW_LEFTRIGHT);
+ if (RNA_enum_get(ptr, "falloff_type") == MOD_WVG_MAPPING_CURVE) {
+ uiTemplateCurveMapping(layout, ptr, "map_curve", 0, false, false, false, false);
+ }
modifier_panel_end(layout, ptr);
}
@@ -703,6 +730,25 @@ static void panelRegister(ARegionType *region_type)
region_type, "influence", "Influence", NULL, influence_panel_draw, panel_type);
}
+static void blendWrite(BlendWriter *writer, const ModifierData *md)
+{
+ const WeightVGProximityModifierData *wmd = (const WeightVGProximityModifierData *)md;
+
+ if (wmd->cmap_curve) {
+ BKE_curvemapping_blend_write(writer, wmd->cmap_curve);
+ }
+}
+
+static void blendRead(BlendDataReader *reader, ModifierData *md)
+{
+ WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *)md;
+
+ BLO_read_data_address(reader, &wmd->cmap_curve);
+ if (wmd->cmap_curve) {
+ BKE_curvemapping_blend_read(reader, wmd->cmap_curve);
+ }
+}
+
ModifierTypeInfo modifierType_WeightVGProximity = {
/* name */ "VertexWeightProximity",
/* structName */ "WeightVGProximityModifierData",
@@ -713,7 +759,7 @@ ModifierTypeInfo modifierType_WeightVGProximity = {
eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_UsesPreview,
/* icon */ ICON_MOD_VERTEX_WEIGHT,
- /* copyData */ BKE_modifier_copydata_generic,
+ /* copyData */ copyData,
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
@@ -726,7 +772,7 @@ ModifierTypeInfo modifierType_WeightVGProximity = {
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
- /* freeData */ NULL,
+ /* freeData */ freeData,
/* isDisabled */ isDisabled,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
@@ -735,6 +781,6 @@ ModifierTypeInfo modifierType_WeightVGProximity = {
/* foreachTexLink */ foreachTexLink,
/* freeRuntimeData */ NULL,
/* panelRegister */ panelRegister,
- /* blendWrite */ NULL,
- /* blendRead */ NULL,
+ /* blendWrite */ blendWrite,
+ /* blendRead */ blendRead,
};