[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43541] branches/vgroup_modifiers: Heavily refactored the "weight preview" code:
Bastien Montagne
montagne29 at wanadoo.fr
Thu Jan 19 22:02:19 CET 2012
Revision: 43541
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43541
Author: mont29
Date: 2012-01-19 21:02:17 +0000 (Thu, 19 Jan 2012)
Log Message:
-----------
Heavily refactored the "weight preview" code:
* Removed "preview modes" from 3DView in WPaint mode.
* Made preview even more "generic code". Note however current solution to control whether a given modifier is authorized to compute preview or not is most probably wrong currently, will need another solution (prob. affecting all modifiers' code).
-----
Here is a new version of the patch.
I addressed most of your advices, with one exception: imho, setting CD_WEIGHT_MCOL from the main modifier evaluation code (in DerivedMesh.c) is not a good idea, and is not even doable, at least for DPaint VCol preview. There would also be the problem of determining which vgroup?\226?\128?\153s weights to preview (modifier one might be different from current active one). Not to mention that a modifier might want to output something else than just a single group?\226?\128?\153s weights (I already have on my hdd a new weight modifier that uses a more complex preview option?\226?\128?\166).
So, I think the modifier should keep the responsibility of preview compute, and hence be aware whether it is authorized to compute a given type of preview (in WPaint mode, we want weight preview, but not VCol preview!). In current code, I added two more temporary flags to md->mode, but I?\226?\128?\153m quite aware this is not a good solution.
Which leads me to that proposition: I?\226?\128?\153d like to replace the useRenderParam, useCache, useDeform, etc. params passed to the exec modifier functions by a single flag one, which would allow much more flexibility to main code to control each modifier?\226?\128?\153s behavior.
Obviously, this would be a huge change in modifiers code, to be done on its own (and before applying that patch!). Not sure whether we want to do that kind of things with bmesh narrowing to merge point?
As a side note, as suggested by miikha, we should also rename CD_WEIGHT_MCOL to something like CD_PREVIEW_MCOL... another big patch, but that can wait later.
Modified Paths:
--------------
branches/vgroup_modifiers/release/scripts/startup/bl_ui/properties_data_modifier.py
branches/vgroup_modifiers/source/blender/blenkernel/BKE_DerivedMesh.h
branches/vgroup_modifiers/source/blender/blenkernel/BKE_modifier.h
branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c
branches/vgroup_modifiers/source/blender/blenkernel/intern/dynamicpaint.c
branches/vgroup_modifiers/source/blender/blenkernel/intern/modifier.c
branches/vgroup_modifiers/source/blender/editors/interface/interface_templates.c
branches/vgroup_modifiers/source/blender/editors/space_view3d/drawmesh.c
branches/vgroup_modifiers/source/blender/editors/space_view3d/drawobject.c
branches/vgroup_modifiers/source/blender/editors/space_view3d/view3d_header.c
branches/vgroup_modifiers/source/blender/editors/space_view3d/view3d_intern.h
branches/vgroup_modifiers/source/blender/makesdna/DNA_modifier_types.h
branches/vgroup_modifiers/source/blender/makesdna/DNA_scene_types.h
branches/vgroup_modifiers/source/blender/makesrna/intern/rna_modifier.c
branches/vgroup_modifiers/source/blender/makesrna/intern/rna_scene.c
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_dynamicpaint.c
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvg_util.c
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvg_util.h
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgedit.c
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgmix.c
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c
Modified: branches/vgroup_modifiers/release/scripts/startup/bl_ui/properties_data_modifier.py
===================================================================
--- branches/vgroup_modifiers/release/scripts/startup/bl_ui/properties_data_modifier.py 2012-01-19 20:52:51 UTC (rev 43540)
+++ branches/vgroup_modifiers/release/scripts/startup/bl_ui/properties_data_modifier.py 2012-01-19 21:02:17 UTC (rev 43541)
@@ -828,8 +828,6 @@
@staticmethod
def vertex_weight_common(layout, ob, md):
- layout.prop(md, "use_weight_preview")
-
layout.label(text="Influence/Mask Options:")
split = layout.split(percentage=0.4)
Modified: branches/vgroup_modifiers/source/blender/blenkernel/BKE_DerivedMesh.h
===================================================================
--- branches/vgroup_modifiers/source/blender/blenkernel/BKE_DerivedMesh.h 2012-01-19 20:52:51 UTC (rev 43540)
+++ branches/vgroup_modifiers/source/blender/blenkernel/BKE_DerivedMesh.h 2012-01-19 21:02:17 UTC (rev 43541)
@@ -68,9 +68,6 @@
#define SUB_ELEMS_EDGE 2
#define SUB_ELEMS_FACE 4
-/* DM flags. */
-#define DM_MOD_DO_WMCOL (1 << 0)
-
typedef struct DMGridData {
float co[3];
float no[3];
@@ -98,7 +95,6 @@
struct GPUDrawObject *drawObject;
DerivedMeshType type;
float auto_bump_scale;
- int flags; /* Various flags, currently only DM_MOD_DO_WMCOL. */
/* Misc. Queries */
@@ -376,11 +372,6 @@
*/
int DM_release(DerivedMesh *dm);
-/* Utility functions to set, clear, and get a DM flag. */
-void DM_set_flag(DerivedMesh *dm, const int flag);
-void DM_clear_flag(DerivedMesh *dm, const int flag);
-int DM_get_flag(DerivedMesh *dm, const int flag);
-
/* utility function to convert a DerivedMesh to a Mesh
*/
void DM_to_mesh(DerivedMesh *dm, struct Mesh *me);
@@ -547,7 +538,15 @@
float (**deformmats)[3][3], float (**deformcos)[3]);
void weight_to_rgb(float r_rgb[3], const float weight);
-void weightpaint_color(unsigned char r_col[4], struct ColorBand *coba, const float input, const int use_stored_cb);
+/* Update the weight MCOL preview layer.
+ * If weights are NULL, use object's active vgroup(s).
+ * Else, weights must be an array of weight float values.
+ * If indices is NULL, it must be of numVerts length.
+ * Else, it must be of num length, as indices, which contains vertices' idx to apply weights to.
+ * (other vertices are assumed zero weight).
+ */
+void DM_update_weight_mcol(struct Object *ob, struct DerivedMesh *dm, int const draw_flag,
+ float *weights, int num, const int *indices);
/* convert layers requested by a GLSL material to actually available layers in
* the DerivedMesh, with both a pointer for arrays and an offset for editmesh */
Modified: branches/vgroup_modifiers/source/blender/blenkernel/BKE_modifier.h
===================================================================
--- branches/vgroup_modifiers/source/blender/blenkernel/BKE_modifier.h 2012-01-19 20:52:51 UTC (rev 43540)
+++ branches/vgroup_modifiers/source/blender/blenkernel/BKE_modifier.h 2012-01-19 21:02:17 UTC (rev 43541)
@@ -102,7 +102,7 @@
eModifierTypeFlag_NoUserAdd = (1<<8),
/* For modifiers that use CD_WEIGHT_MCOL for preview. */
- eModifierTypeFlag_UsesWMColPreview = (1<<9)
+ eModifierTypeFlag_UsesPreview = (1<<9)
} ModifierTypeFlag;
typedef void (*ObjectWalkFunc)(void *userData, struct Object *ob, struct Object **obpoin);
@@ -311,14 +311,14 @@
struct ModifierData *modifier_new(int type);
void modifier_free(struct ModifierData *md);
-void modifier_unique_name(struct ListBase *modifiers, struct ModifierData *md);
+void modifier_unique_name(struct ListBase *modifiers, struct ModifierData *md);
void modifier_copyData(struct ModifierData *md, struct ModifierData *target);
int modifier_dependsOnTime(struct ModifierData *md);
int modifier_supportsMapping(struct ModifierData *md);
int modifier_couldBeCage(struct Scene *scene, struct ModifierData *md);
int modifier_isCorrectableDeformed(struct ModifierData *md);
-int modifier_sameTopology(ModifierData *md);
+int modifier_sameTopology(ModifierData *md);
int modifier_nonGeometrical(ModifierData *md);
int modifier_isEnabled(struct Scene *scene, struct ModifierData *md, int required_mode);
void modifier_setError(struct ModifierData *md, const char *format, ...)
@@ -326,7 +326,7 @@
__attribute__ ((format (printf, 2, 3)))
#endif
;
-int modifier_usesWMColPreview(struct ModifierData *md);
+int modifier_usesPreview(struct ModifierData *md);
void modifiers_foreachObjectLink(struct Object *ob,
ObjectWalkFunc walk,
@@ -353,7 +353,7 @@
int modifiers_usesArmature(struct Object *ob, struct bArmature *arm);
int modifiers_isCorrectableDeformed(struct Object *ob);
void modifier_freeTemporaryData(struct ModifierData *md);
-int modifiers_isWMColPreview(struct Object *ob);
+int modifiers_isPreview(struct Object *ob);
int modifiers_indexInObject(struct Object *ob, struct ModifierData *md);
@@ -367,6 +367,9 @@
struct ModifierData *md,
CustomDataMask dataMask,
int required_mode);
+struct ModifierData *modifiers_getLastPreview(struct Scene *scene,
+ struct ModifierData *md,
+ int required_mode);
struct ModifierData *modifiers_getVirtualModifierList(struct Object *ob);
/* ensure modifier correctness when changing ob->data */
Modified: branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c 2012-01-19 20:52:51 UTC (rev 43540)
+++ branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c 2012-01-19 21:02:17 UTC (rev 43541)
@@ -185,7 +185,6 @@
dm->needsFree = 1;
dm->auto_bump_scale = -1.0f;
- dm->flags = 0;
}
void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type,
@@ -206,7 +205,6 @@
DM_init_funcs(dm);
dm->needsFree = 1;
- dm->flags = source->flags;
}
int DM_release(DerivedMesh *dm)
@@ -229,21 +227,6 @@
}
}
-void DM_set_flag(DerivedMesh *dm, const int flag)
-{
- dm->flags |= flag;
-}
-
-void DM_clear_flag(DerivedMesh *dm, const int flag)
-{
- dm->flags &= ~flag;
-}
-
-int DM_get_flag(DerivedMesh *dm, const int flag)
-{
- return (dm->flags & flag);
-}
-
void DM_to_mesh(DerivedMesh *dm, Mesh *me)
{
/* dm might depend on me, so we need to do everything with a local copy */
@@ -655,32 +638,20 @@
/* draw_flag's for calc_weightpaint_vert_color */
enum {
- CALC_WP_MULTIPAINT = (1 << 0),
- CALC_WP_AUTO_NORMALIZE = (1 << 1),
+ CALC_WP_MULTIPAINT= (1<<0),
+ CALC_WP_AUTO_NORMALIZE= (1<<1)
};
-static ColorBand *stored_cb= NULL;
-
-void vDM_ColorBand_store(ColorBand *coba)
+static void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const float input)
{
- stored_cb= coba;
-}
-
-void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const float input, const int use_stored_cb)
-{
float colf[4];
- if(coba)
- do_colorband(coba, input, colf);
- else if(use_stored_cb && stored_cb) /* Warning, stored_cb is not a local var. */
- do_colorband(stored_cb, input, colf);
- else
- weight_to_rgb(colf, input);
+ if(coba) do_colorband(coba, input, colf);
+ else weight_to_rgb(colf, input);
- /* XXX We cannot use F3TOCHAR4, as order must be reversed... */
- r_col[3] = FTOCHAR(colf[0]);
- r_col[2] = FTOCHAR(colf[1]);
- r_col[1] = FTOCHAR(colf[2]);
+ r_col[3] = (unsigned char)(colf[0] * 255.0f);
+ r_col[2] = (unsigned char)(colf[1] * 255.0f);
+ r_col[1] = (unsigned char)(colf[2] * 255.0f);
r_col[0] = 255;
}
@@ -735,10 +706,17 @@
}
else {
CLAMP(input, 0.0f, 1.0f);
- weightpaint_color(r_col, coba, input, FALSE);
+ weightpaint_color(r_col, coba, input);
}
}
+static ColorBand *stored_cb= NULL;
+
+void vDM_ColorBand_store(ColorBand *coba)
+{
+ stored_cb= coba;
+}
+
/* return an array of vertex weight colors, caller must free.
*
* note that we could save some memory and allocate RGB only but then we'd need to
@@ -768,21 +746,40 @@
}
else {
int col_i;
- weightpaint_color((unsigned char *)&col_i, coba, 0.0f, FALSE);
+ weightpaint_color((unsigned char *)&col_i, coba, 0.0f);
fill_vn_i((int *)wtcol_v, numVerts, col_i);
}
return wtcol_v;
}
-static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag)
+/* return an array of vertex weight colors from given weights, caller must free.
+ *
+ * note that we could save some memory and allocate RGB only but then we'd need to
+ * re-arrange the colors when copying to the face since MCol has odd ordering,
+ * so leave this as is - campbell */
+static unsigned char *calc_colors_from_weights_array(const int num, float *weights)
{
+ unsigned char *wtcol_v = MEM_mallocN(sizeof(unsigned char) * num * 4, "weightmap_v");
+ unsigned char *wc = wtcol_v;
+ int i;
+
+ for (i = 0; i < num; i++, wc += 4, weights++)
+ weightpaint_color((unsigned char *) wc, NULL, *weights);
+
+ return wtcol_v;
+}
+
+void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
+ float *weights, int num, const int *indices)
+{
ColorBand *coba= stored_cb; /* warning, not a local var */
MFace *mf = dm->getFaceArray(dm);
int numFaces = dm->getNumFaces(dm);
+ int numVerts = dm->getNumVerts(dm);
unsigned char *wtcol_v;
- unsigned char *wtcol_f = DM_get_face_data_layer(dm, CD_WEIGHT_MCOL);
+ unsigned char *wtcol_f = dm->getFaceDataArray(dm, CD_WEIGHT_MCOL);
int i;
/* If no CD_WEIGHT_MCOL existed yet, add a new one! */
@@ -791,7 +788,31 @@
if (wtcol_f) {
unsigned char *wtcol_f_step = wtcol_f;
- wtcol_v = calc_weightpaint_vert_array(ob, dm, draw_flag, coba);
+
+ /* Weights are given by caller. */
+ if (weights) {
+ float *w = weights;
+ /* If indices is not NULL, it means we do not have weights for all vertices,
+ * so we must create them (and set them to zero)... */
+ if(indices) {
+ w = MEM_callocN(sizeof(float)*numVerts, "Temp weight array DM_update_weight_mcol");
+ i = num;
+ while(i--)
+ w[indices[i]] = weights[i];
+ }
+
+ /* Convert float weights to colors. */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list