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:
authorBastien Montagne <montagne29@wanadoo.fr>2011-09-05 20:16:00 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2011-09-05 20:16:00 +0400
commit4393df93202198b5eaaff438e18060c66b98928d (patch)
treee6f045ff5c0e5a6e676cf93cf8bc6c4c41431b50 /source/blender/modifiers/intern
parentcc906e0e2a1de9b19c6cefa1167332f348bb9e0f (diff)
VGroup Modifiers: added mapping options to proximity and edit.
*Added Smooth/Sharp/Root/etc. mappings to WeightVGEdit modifier, in addition to custom curve one. *Added Smooth/Sharp/Root/etc. mappings to WeightVGProximity modifier, without the custom curve one! *Factorized the common mapping code into MOD_weightvg_util.
Diffstat (limited to 'source/blender/modifiers/intern')
-rw-r--r--source/blender/modifiers/intern/MOD_weightvg_util.c66
-rw-r--r--source/blender/modifiers/intern/MOD_weightvg_util.h17
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgedit.c11
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgproximity.c27
4 files changed, 92 insertions, 29 deletions
diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c
index 93e1899ad60..675f0d76a48 100644
--- a/source/blender/modifiers/intern/MOD_weightvg_util.c
+++ b/source/blender/modifiers/intern/MOD_weightvg_util.c
@@ -33,16 +33,19 @@
* Or the WeightPaint mode code itself?
*/
-#include "BLI_utildefines.h"
#include "BLI_math.h"
+#include "BLI_rand.h"
#include "BLI_string.h"
+#include "BLI_utildefines.h"
+#include "DNA_color_types.h" /* CurveMapping. */
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "BKE_cdderivedmesh.h"
+#include "BKE_colortools.h" /* CurveMapping. */
#include "BKE_deform.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
@@ -54,16 +57,69 @@
#include "MOD_weightvg_util.h"
#include "RE_shader_ext.h" /* Texture masking. */
+/* Maps new_w weights in place, using either one of the predifined functions, or a custom curve.
+ * Return values are in new_w.
+ * If indices is not NULL, it must be a table of same length as org_w and new_w, mapping to the real
+ * vertex index (in case the weight tables do not cover the whole vertices...).
+ * cmap might be NULL, in which case curve mapping mode will return unmodified data.
+ */
+void weightvg_do_map(int num, float *new_w, short mode, CurveMapping *cmap)
+{
+ int i;
+
+ /* Return immediately, if we have nothing to do! */
+ /* Also security checks... */
+ if(((mode == MOD_WVG_MAPPING_CURVE) && (cmap == NULL))
+ || !ELEM7(mode, MOD_WVG_MAPPING_CURVE, MOD_WVG_MAPPING_SHARP, MOD_WVG_MAPPING_SMOOTH,
+ MOD_WVG_MAPPING_ROOT, MOD_WVG_MAPPING_SPHERE, MOD_WVG_MAPPING_RANDOM,
+ MOD_WVG_MAPPING_STEP))
+ return;
+
+ /* Map each weight (vertex) to its new value, accordingly to the chosen mode. */
+ for(i = 0; i < num; ++i) {
+ float fac = new_w[i];
+
+ /* Code borrowed from the warp modifier. */
+ /* Closely matches PROP_SMOOTH and similar. */
+ switch(mode) {
+ case MOD_WVG_MAPPING_CURVE:
+ fac = curvemapping_evaluateF(cmap, 0, fac);
+ break;
+ case MOD_WVG_MAPPING_SHARP:
+ fac = fac*fac;
+ break;
+ case MOD_WVG_MAPPING_SMOOTH:
+ fac = 3.0f*fac*fac - 2.0f*fac*fac*fac;
+ break;
+ case MOD_WVG_MAPPING_ROOT:
+ fac = (float)sqrt(fac);
+ break;
+ case MOD_WVG_MAPPING_SPHERE:
+ fac = (float)sqrt(2*fac - fac * fac);
+ break;
+ case MOD_WVG_MAPPING_RANDOM:
+ BLI_srand(BLI_rand()); /* random seed */
+ fac = BLI_frand()*fac;
+ break;
+ case MOD_WVG_MAPPING_STEP:
+ fac = (fac >= 0.5f)?1.0f:0.0f;
+ break;
+ }
+
+ new_w[i] = fac;
+ }
+}
+
/* Applies new_w weights to org_w ones, using either a texture, vgroup or constant value as factor.
* Return values are in org_w.
* If indices is not NULL, it must be a table of same length as org_w and new_w, mapping to the real
* vertex index (in case the weight tables do not cover the whole vertices...).
* XXX The standard “factor” value is assumed in [0.0, 1.0] range. Else, weird results might appear.
*/
-void weightvg_do_mask(int num, int *indices, float *org_w, float *new_w, Object *ob,
- DerivedMesh *dm, float fact, const char defgrp_name[32], Tex *texture,
- int tex_use_channel, int tex_mapping, Object *tex_map_object,
- const char *tex_uvlayer_name)
+void weightvg_do_mask(int num, const int *indices, float *org_w, const float *new_w,
+ Object *ob, DerivedMesh *dm, float fact, const char defgrp_name[32],
+ Tex *texture, int tex_use_channel, int tex_mapping,
+ Object *tex_map_object, const char *tex_uvlayer_name)
{
int ref_didx;
int i;
diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.h b/source/blender/modifiers/intern/MOD_weightvg_util.h
index b42e9c20035..3afff391943 100644
--- a/source/blender/modifiers/intern/MOD_weightvg_util.h
+++ b/source/blender/modifiers/intern/MOD_weightvg_util.h
@@ -37,11 +37,10 @@
/* so modifier types match their defines */
#include "MOD_modifiertypes.h"
-struct Tex;
+struct CurveMapping;
struct DerivedMesh;
struct Object;
-/*struct ModifierData;
-struct MappingInfoModifierData;*/
+struct Tex;
/*
* XXX I'd like to make modified weights visible in WeightPaint mode,
@@ -61,14 +60,22 @@ struct MappingInfoModifierData;*/
*/
#define MOD_WVG_ZEROFLOOR 1.0e-32f
+/* Maps new_w weights in place, using either one of the predifined functions, or a custom curve.
+ * Return values are in new_w.
+ * If indices is not NULL, it must be a table of same length as org_w and new_w, mapping to the real
+ * vertex index (in case the weight tables do not cover the whole vertices...).
+ * cmap might be NULL, in which case curve mapping mode will return unmodified data.
+ */
+void weightvg_do_map(int num, float *new_w, short mode, struct CurveMapping *cmap);
+
/* Applies new_w weights to org_w ones, using either a texture, vgroup or constant value as factor.
* Return values are in org_w.
* If indices is not NULL, it must be a table of same length as org_w and new_w, mapping to the real
* vertex index (in case the weight tables do not cover the whole vertices...).
* XXX The standard “factor” value is assumed in [0.0, 1.0] range. Else, weird results might appear.
*/
-void weightvg_do_mask(int num, int *indices, float *org_w, float *new_w, Object *ob,
- struct DerivedMesh *dm, float fact, const char defgrp_name[32], Tex *texture,
+void weightvg_do_mask(int num, const int *indices, float *org_w, const float *new_w, Object *ob,
+ DerivedMesh *dm, float fact, const char defgrp_name[32], Tex *texture,
int tex_use_channel, int tex_mapping, Object *tex_map_object,
const char *tex_uvlayer_name);
diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c
index 87747f255fd..763a063567b 100644
--- a/source/blender/modifiers/intern/MOD_weightvgedit.c
+++ b/source/blender/modifiers/intern/MOD_weightvgedit.c
@@ -62,6 +62,7 @@ static void initData(ModifierData *md)
{
WeightVGEditModifierData *wmd = (WeightVGEditModifierData*) md;
wmd->edit_flags = 0;
+ wmd->mapping_mode = MOD_WVG_MAPPING_NONE;
wmd->default_weight = 0.0f;
wmd->cmap_curve = curvemapping_add(1, 0.0, 0.0, 1.0, 1.0);
@@ -89,6 +90,7 @@ static void copyData(ModifierData *md, ModifierData *target)
BLI_strncpy(twmd->defgrp_name, wmd->defgrp_name, sizeof(twmd->defgrp_name));
twmd->edit_flags = wmd->edit_flags;
+ twmd->mapping_mode = wmd->mapping_mode;
twmd->default_weight = wmd->default_weight;
twmd->cmap_curve = curvemapping_copy(wmd->cmap_curve);
@@ -192,7 +194,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
int i;
char rel_ret = 0; /* Boolean, whether we have to release ret dm or not, when not using it! */
/* Flags. */
- int do_map = (wmd->edit_flags & MOD_WVG_EDIT_CMAP) != 0;
int do_add = (wmd->edit_flags & MOD_WVG_EDIT_ADD2VG) != 0;
int do_rem = (wmd->edit_flags & MOD_WVG_EDIT_REMFVG) != 0;
@@ -264,11 +265,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
if(dw) {
org_w[i] = new_w[i] = dw->weight;
}
+ }
- /* Do mapping. */
- if (do_map) {
- new_w[i] = curvemapping_evaluateF(wmd->cmap_curve, 0, new_w[i]);
- }
+ /* Do mapping. */
+ if (wmd->mapping_mode != MOD_WVG_MAPPING_NONE) {
+ weightvg_do_map(numVerts, new_w, wmd->mapping_mode, wmd->cmap_curve);
}
/* Do masking. */
diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c
index 513ba9c815f..35f993e24b6 100644
--- a/source/blender/modifiers/intern/MOD_weightvgproximity.c
+++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c
@@ -33,10 +33,10 @@
* Or the WeightPaint mode code itself?
*/
-#include "BLI_utildefines.h"
+#include "BLI_editVert.h"
#include "BLI_math.h"
#include "BLI_string.h"
-#include "BLI_editVert.h"
+#include "BLI_utildefines.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -193,9 +193,9 @@ static float get_ob2ob_distance(const Object* ob, const Object* obr)
}
/**
- * Maps distances to weights.
+ * Maps distances to weights, with an optionnal “smoothing” mapping.
*/
-void do_map(float *weights, const int nidx, const float min_d, const float max_d)
+void do_map(float *weights, const int nidx, const float min_d, const float max_d, short mode)
{
const float range_inv= 1.0f / (max_d - min_d); /* invert since multiplication is faster */
unsigned int i= nidx;
@@ -204,17 +204,12 @@ void do_map(float *weights, const int nidx, const float min_d, const float max_d
else if(weights[i] <= min_d) weights[i]= 0.0f;
else weights[i]= (weights[i] - min_d) * range_inv;
}
-}
-/*a min_d + b = 0.0*/
-/*a max_d + b = 1.0*/
-/*a min_d = -b*/
-/*a = -b / min_d*/
+ if(!ELEM(mode, MOD_WVG_MAPPING_NONE, MOD_WVG_MAPPING_CURVE)) {
+ weightvg_do_map(nidx, weights, mode, NULL);
+ }
+}
-/*max_d(-b/min_d) + b = 1.0*/
-/*b((-max_d/min_d)+1.0) = 1.0*/
-/*b = 1.0 / ((min_d-max_d)/min_d)*/
-/*b = min_d/(min_d-max_d)*/
/**************************************
* Modifiers functions. *
**************************************/
@@ -225,6 +220,8 @@ static void initData(ModifierData *md)
wmd->proximity_mode = MOD_WVG_PROXIMITY_OBJECT;
wmd->proximity_flags = MOD_WVG_PROXIMITY_GEOM_VERTS;
+ wmd->mapping_mode = MOD_WVG_MAPPING_NONE;
+
wmd->mask_constant = 1.0f;
wmd->mask_tex_use_channel = MOD_WVG_MASK_TEX_USE_INT; /* Use intensity by default. */
wmd->mask_tex_mapping = MOD_DISP_MAP_LOCAL;
@@ -241,6 +238,8 @@ static void copyData(ModifierData *md, ModifierData *target)
twmd->proximity_flags = wmd->proximity_flags;
twmd->proximity_ob_target = wmd->proximity_ob_target;
+ twmd->mapping_mode = wmd->mapping_mode;
+
twmd->mask_constant = wmd->mask_constant;
BLI_strncpy(twmd->mask_defgrp_name, wmd->mask_defgrp_name, sizeof(twmd->mask_defgrp_name));
twmd->mask_texture = wmd->mask_texture;
@@ -499,7 +498,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
wmd->mask_tex_mapping, wmd->mask_tex_map_obj, wmd->mask_tex_uvlayer_name);
/* Map distances to weights. */
- do_map(org_w, numIdx, wmd->min_dist, wmd->max_dist);
+ do_map(org_w, numIdx, wmd->min_dist, wmd->max_dist, wmd->mapping_mode);
/* Update vgroup. Note we never add nor remove vertices from vgroup here. */
weightvg_update_vg(dvert, defgrp_idx, numIdx, indices, org_w, 0, 0.0f, 0, 0.0f);