diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-09-20 16:01:16 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-09-20 16:01:16 +0400 |
commit | 7172316b945c62797e6beba953ff203766614531 (patch) | |
tree | 640ac56fadded9c7686399b5a1f1c64f1a135700 /source/blender/editors | |
parent | 2015eefef70350382931881dd65ed2da09f8f2cd (diff) | |
parent | 78d4260144dbf01166fac8bc9303e6d5aa022f71 (diff) |
Merging r40366 through r40392 from trunk into soc-2011-garlicsoc-2011-garlic
Diffstat (limited to 'source/blender/editors')
44 files changed, 2008 insertions, 277 deletions
diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 53e0fd92eeb..566ff09c366 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4290,10 +4290,15 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor /* if the bone cannot be affected, don't do anything */ if ((nearBone) && !(nearBone->flag & BONE_UNSELECTABLE)) { + Object *ob_act= OBACT; bArmature *arm= ob->data; - /* since we do unified select, we don't shift+select a bone if the armature object was not active yet */ - if (!(extend) || (base != scene->basact)) { + /* since we do unified select, we don't shift+select a bone if the + * armature object was not active yet. + * note, special exception for armature mode so we can do multi-select + * we could check for multi-select explicitly but think its fine to + * always give pradictable behavior in weight paint mode - campbell */ + if (!(extend) || ((ob_act && ob_act->mode & OB_MODE_WEIGHT_PAINT) == 0)) { ED_pose_deselectall(ob, 0); nearBone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); arm->act_bone= nearBone; @@ -4324,7 +4329,7 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor } /* in weightpaint we select the associated vertex group too */ - if (OBACT && OBACT->mode & OB_MODE_WEIGHT_PAINT) { + if (ob_act && ob_act->mode & OB_MODE_WEIGHT_PAINT) { if (nearBone == arm->act_bone) { ED_vgroup_select_by_name(OBACT, nearBone->name); DAG_id_tag_update(&OBACT->id, OB_RECALC_DATA); @@ -5061,6 +5066,10 @@ void POSE_OT_select_inverse(wmOperatorType *ot) static int pose_de_select_all_exec(bContext *C, wmOperator *op) { int action = RNA_enum_get(op->ptr, "action"); + + Object *ob = NULL; + Scene *scene= CTX_data_scene(C); + int multipaint = scene->toolsettings->multipaint; if (action == SEL_TOGGLE) { action= CTX_DATA_COUNT(C, selected_pose_bones) ? SEL_DESELECT : SEL_SELECT; @@ -5091,6 +5100,11 @@ static int pose_de_select_all_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, NULL); + if(multipaint) { + ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + } + return OPERATOR_FINISHED; } diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c index 806e288798f..6c721660e9c 100644 --- a/source/blender/editors/armature/meshlaplacian.c +++ b/source/blender/editors/armature/meshlaplacian.c @@ -657,22 +657,41 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource, int *vertsflipped = NULL, *mask= NULL; int a, totface, j, bbone, firstsegment, lastsegment; + MVert *mvert = me->mvert; + int use_vert_sel= FALSE; + int use_face_sel= FALSE; + *err_str= NULL; /* count triangles and create mask */ - if(me->editflag & ME_EDIT_PAINT_MASK) + if( (use_face_sel= (me->editflag & ME_EDIT_PAINT_MASK) != 0) || + (use_vert_sel= ((me->editflag & ME_EDIT_VERT_SEL) != 0))) + { mask= MEM_callocN(sizeof(int)*me->totvert, "heat_bone_weighting mask"); + } for(totface=0, a=0, mface=me->mface; a<me->totface; a++, mface++) { totface++; if(mface->v4) totface++; - if(mask && (mface->flag & ME_FACE_SEL)) { - mask[mface->v1]= 1; - mask[mface->v2]= 1; - mask[mface->v3]= 1; - if(mface->v4) - mask[mface->v4]= 1; + /* (added selectedVerts content for vertex mask, they used to just equal 1) */ + if(use_vert_sel) { + mask[mface->v1]= (mvert[mface->v1].flag & SELECT) != 0; + mask[mface->v2]= (mvert[mface->v2].flag & SELECT) != 0; + mask[mface->v3]= (mvert[mface->v3].flag & SELECT) != 0; + if(mface->v4) { + mask[mface->v4]= (mvert[mface->v4].flag & SELECT) != 0; + } + } + else { + if(use_face_sel) { + mask[mface->v1]= 1; + mask[mface->v2]= 1; + mask[mface->v3]= 1; + if(mface->v4) { + mask[mface->v4]= 1; + } + } } } diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index 8bb77ad43a0..9709979ff6a 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -123,6 +123,8 @@ int EM_vertColorCheck(struct EditMesh *em); void undo_push_mesh(struct bContext *C, const char *name); +void paintvert_flush_flags(struct Object *ob); +void paintvert_deselect_all_visible(struct Object *ob, int action, short flush_flags); /* editmesh_lib.c */ diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index f8682d3935b..d574ddd3030 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -53,6 +53,7 @@ struct Scene; struct View3D; struct ViewContext; struct wmWindow; +struct MVert; /* for derivedmesh drawing callbacks, for view3d_select, .... */ diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 095c90797f1..af515bf8061 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2138,6 +2138,18 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe //uiItemR(row, itemptr, "mute", 0, "", ICON_MUTE_IPO_OFF); uiBlockSetEmboss(block, UI_EMBOSS); } + else if(itemptr->type == &RNA_VertexGroup) { + bDeformGroup *dg= (bDeformGroup *)itemptr->data; + uiItemL(sub, name, icon); + /* RNA does not allow nice lock icons, use lower level buttons */ +#if 0 + uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "lock_weight", 0, 0, 0, 0, 0, NULL); +#else + uiBlockSetEmboss(block, UI_EMBOSSN); + uiDefIconButBitC(block, TOG, DG_LOCK_WEIGHT, 0, (dg->flag & DG_LOCK_WEIGHT) ? ICON_LOCKED : ICON_UNLOCKED, 0, 0, UI_UNIT_X, UI_UNIT_Y, &dg->flag, 0, 0, 0, 0, "Maintain relative weights while painting"); + uiBlockSetEmboss(block, UI_EMBOSS); +#endif + } else if(itemptr->type == &RNA_KeyingSetPath) { KS_Path *ksp = (KS_Path*)itemptr->data; diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 3f5bc21814d..18db1c8c894 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -420,8 +420,8 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) /* check if we should restore aspect ratio (if view size changed) */ if (v2d->keepzoom & V2D_KEEPASPECT) { - short do_x=0, do_y=0, do_cur, do_win; - float curRatio, winRatio; + short do_x=0, do_y=0, do_cur /* , do_win */ /* UNUSED */; + float /* curRatio, */ /* UNUSED */ winRatio; /* when a window edge changes, the aspect ratio can't be used to * find which is the best new 'cur' rect. thats why it stores 'old' @@ -429,7 +429,7 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) if (winx != v2d->oldwinx) do_x= 1; if (winy != v2d->oldwiny) do_y= 1; - curRatio= height / width; + /* curRatio= height / width; */ /* UNUSED */ winRatio= winy / winx; /* both sizes change (area/region maximised) */ @@ -443,7 +443,7 @@ void UI_view2d_curRect_validate_resize(View2D *v2d, int resize) else do_x= 1; } do_cur= do_x; - do_win= do_y; + /* do_win= do_y; */ /* UNUSED */ if (do_cur) { if ((v2d->keeptot == V2D_KEEPTOT_STRICT) && (winx != v2d->oldwinx)) { diff --git a/source/blender/editors/mesh/editmesh.c b/source/blender/editors/mesh/editmesh.c index c56a4238239..6a263fca915 100644 --- a/source/blender/editors/mesh/editmesh.c +++ b/source/blender/editors/mesh/editmesh.c @@ -1958,3 +1958,101 @@ void em_setup_viewcontext(bContext *C, ViewContext *vc) vc->em= me->edit_mesh; } } + + +/* (similar to void paintface_flush_flags(Object *ob)) + * copy the vertex flags, most importantly selection from the mesh to the final derived mesh, + * use in object mode when selecting vertices (while painting) */ +void paintvert_flush_flags(Object *ob) +{ + Mesh *me= get_mesh(ob); + DerivedMesh *dm= ob->derivedFinal; + MVert *dm_mvert, *dm_mv; + int *index_array = NULL; + int totvert; + int i; + + if(me==NULL || dm==NULL) + return; + + index_array = dm->getVertDataArray(dm, CD_ORIGINDEX); + + dm_mvert = dm->getVertArray(dm); + totvert = dm->getNumVerts(dm); + + dm_mv= dm_mvert; + + if(index_array) { + int orig_index; + for (i= 0; i<totvert; i++, dm_mv++) { + orig_index= index_array[i]; + if(orig_index != ORIGINDEX_NONE) { + dm_mv->flag= me->mvert[index_array[i]].flag; + } + } + } + else { + for (i= 0; i<totvert; i++, dm_mv++) { + dm_mv->flag= me->mvert[i].flag; + } + } +} +/* note: if the caller passes FALSE to flush_flags, then they will need to run paintvert_flush_flags(ob) themselves */ +void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags) +{ + Mesh *me; + MVert *mvert; + int a; + + me= get_mesh(ob); + if(me==NULL) return; + + if(action == SEL_INVERT) { + mvert= me->mvert; + a= me->totvert; + while(a--) { + if((mvert->flag & ME_HIDE) == 0) { + mvert->flag ^= SELECT; + } + mvert++; + } + } + else { + if (action == SEL_TOGGLE) { + action = SEL_SELECT; + + mvert= me->mvert; + a= me->totvert; + while(a--) { + if((mvert->flag & ME_HIDE) == 0 && mvert->flag & SELECT) { + action = SEL_DESELECT; + break; + } + mvert++; + } + } + + mvert= me->mvert; + a= me->totvert; + while(a--) { + if((mvert->flag & ME_HIDE) == 0) { + switch (action) { + case SEL_SELECT: + mvert->flag |= SELECT; + break; + case SEL_DESELECT: + mvert->flag &= ~SELECT; + break; + case SEL_INVERT: + mvert->flag ^= SELECT; + break; + } + } + mvert++; + } + } + + if(flush_flags) { + paintvert_flush_flags(ob); + } +} diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index 9783f25466e..8c035ca46fd 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -266,6 +266,7 @@ int EM_mask_init_backbuf_border(ViewContext *vc, int mcords[][2], short tot, sho /* method in use for face selecting too */ if(vc->obedit==NULL) { if(paint_facesel_test(vc->obact)); + else if(paint_vertsel_test(vc->obact)); else return 0; } else if(vc->v3d->drawtype<OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT)==0) return 0; @@ -328,6 +329,7 @@ int EM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads) /* method in use for face selecting too */ if(vc->obedit==NULL) { if(paint_facesel_test(vc->obact)); + else if (paint_vertsel_test(vc->obact)); else return 0; } else if(vc->v3d->drawtype<OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT)==0) return 0; @@ -1471,10 +1473,8 @@ static void EM_mesh_copy_face(EditMesh *em, wmOperator *op, short type) tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); if (tf_act->tpage) { tf->tpage = tf_act->tpage; - tf->mode |= TF_TEX; } else { tf->tpage = NULL; - tf->mode &= ~TF_TEX; } tf->tile= tf_act->tile; change = 1; @@ -1654,10 +1654,8 @@ void EM_mesh_copy_face_layer(EditMesh *em, wmOperator *op, short type) tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); if (tf_from->tpage) { tf->tpage = tf_from->tpage; - tf->mode |= TF_TEX; } else { tf->tpage = NULL; - tf->mode &= ~TF_TEX; } tf->tile= tf_from->tile; change = 1; diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 5411f01bee4..ef52d9be0c3 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -238,7 +238,6 @@ int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me) int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mesh *me, const char *name, int active_set) { EditMesh *em; - MCol *mcol; int layernum; if(me->edit_mesh) { @@ -261,8 +260,6 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes if(layernum >= MAX_MCOL) return 0; - mcol= me->mcol; - if(me->mcol) CustomData_add_layer_named(&me->fdata, CD_MCOL, CD_DUPLICATE, me->mcol, me->totface, name); else diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 32e52916b77..526bf177ab7 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -217,7 +217,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) if(me->totvert) { /* Add this object's materials to the base one's if they don't exist already (but only if limits not exceeded yet) */ - if(totcol < MAXMAT-1) { + if(totcol < MAXMAT) { for(a=1; a<=base->object->totcol; a++) { ma= give_current_material(base->object, a); @@ -231,7 +231,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) } totcol++; } - if(totcol>=MAXMAT-1) + if(totcol >= MAXMAT) break; } } diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 3da0723ec18..434111c1227 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -200,6 +200,8 @@ void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_normalize_all(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_levels(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_lock(struct wmOperatorType *ot); +void OBJECT_OT_vertex_group_fix(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_invert(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_blend(struct wmOperatorType *ot); void OBJECT_OT_vertex_group_clean(struct wmOperatorType *ot); diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 57efc8c7dc9..452d1aded51 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -174,6 +174,8 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_vertex_group_copy); WM_operatortype_append(OBJECT_OT_vertex_group_normalize); WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all); + WM_operatortype_append(OBJECT_OT_vertex_group_lock); + WM_operatortype_append(OBJECT_OT_vertex_group_fix); WM_operatortype_append(OBJECT_OT_vertex_group_invert); WM_operatortype_append(OBJECT_OT_vertex_group_levels); WM_operatortype_append(OBJECT_OT_vertex_group_blend); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 592205d2a31..797cf428969 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -49,6 +49,7 @@ #include "DNA_scene_types.h" #include "DNA_particle_types.h" +#include "BLI_math.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BLI_utildefines.h" @@ -60,6 +61,7 @@ #include "BKE_global.h" #include "BKE_mesh.h" #include "BKE_report.h" +#include "BKE_DerivedMesh.h" #include "RNA_access.h" #include "RNA_define.h" @@ -701,6 +703,10 @@ static void vgroup_normalize(Object *ob) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; + + Mesh *me = ob->data; + MVert *mvert = me->mvert; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -712,6 +718,11 @@ static void vgroup_normalize(Object *ob) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { + + if(use_vert_sel && !(mvert[i].flag & SELECT)) { + continue; + } + dvert = dvert_array[i]; dw = defvert_find_index(dvert, def_nr); if(dw) { @@ -721,6 +732,11 @@ static void vgroup_normalize(Object *ob) if(weight_max > 0.0f) { for(i = 0; i < dvert_tot; i++) { + + if(use_vert_sel && !(mvert[i].flag & SELECT)) { + continue; + } + dvert = dvert_array[i]; dw = defvert_find_index(dvert, def_nr); if(dw) { @@ -736,6 +752,401 @@ static void vgroup_normalize(Object *ob) if (dvert_array) MEM_freeN(dvert_array); } +/* This adds the indices of vertices to a list if they are not already present +It returns the number that it added (0-2) +It relies on verts having -1 for unassigned indices +*/ +static int tryToAddVerts(int *verts, int length, int a, int b) { + char containsA = FALSE; + char containsB = FALSE; + int added = 0; + int i; + for(i = 0; i < length && (!containsA || !containsB); i++) { + if(verts[i] == a) { + containsA = TRUE; + } else if(verts[i] == b) { + containsB = TRUE; + } else if(verts[i] == -1) { + if(!containsA) { + verts[i] = a; + containsA = TRUE; + added++; + } else if(!containsB){ + verts[i] = b; + containsB = TRUE; + added++; + } + } + } + return added; +} + +/* This finds all of the vertices connected to vert by an edge +and returns an array of indices of size count + +count is an int passed by reference so it can be assigned the value of the length here. +*/ +static int* getSurroundingVerts(Mesh *me, int vert, int *count) { + int length = 0; + int *tverts; + int *verts = NULL; + MFace *mf = me->mface; + int totface = me->totface; + int found = 0; + int i; + for(i = 0; i < totface; i++, mf++) { + if(vert == mf->v1 || vert == mf->v2 || vert == mf->v3 || (mf->v4 &&vert == mf->v4)) { + length+=2; + } + } + if(!length) { + return 0; + } + tverts = MEM_mallocN(sizeof(int)*length, "tempSurroundingVerts"); + mf = me->mface; + for(i = 0; i < length; i++) { + tverts[i] = -1; + } + for(i = 0; i < totface; i++, mf++) { + int a=-1, b=-1; + if(mf->v1 == vert) { + a = mf->v2; + if(mf->v4) { + b = mf->v4; + } else { + b = mf->v3; + } + } else if(mf->v2 == vert) { + a = mf->v1; + b = mf->v3; + } else if(mf->v3 == vert) { + a = mf->v2; + if(mf->v4) { + b = mf->v4; + } else { + b = mf->v1; + } + } else if (mf->v4 && mf->v4 == vert){ + a = mf->v1; + b = mf->v3; + } else { + continue; + } + found += tryToAddVerts(tverts, length, a, b); + } + if(found) { + verts = MEM_mallocN(sizeof(int)* found, "surroundingVerts"); + for(i = 0; i < found; i++) { + verts[i] = tverts[i]; + } + *count = found; + } + MEM_freeN(tverts); + return verts; +} + +/* get a single point in space by averaging a point cloud (vectors of size 3) +coord is the place the average is stored, points is the point cloud, count is the number of points in the cloud +*/ +static void getSingleCoordinate(MVert *points, int count, float coord[3]) { + int i; + zero_v3(coord); + for(i = 0; i < count; i++) { + add_v3_v3(coord, points[i].co); + } + mul_v3_fl(coord, 1.0f/count); +} + +/* find the closest point on a plane to another point and store it in dst */ +/* coord is a point on the plane */ +/* point is the point that you want the nearest of */ +/* norm is the plane's normal, and d is the last number in the plane equation 0 = ax + by + cz + d */ +static void getNearestPointOnPlane(const float norm[3], const float coord[3], const float point[3], float dst_r[3]) +{ + float temp[3]; + float dotprod; + + sub_v3_v3v3(temp, point, coord); + dotprod= dot_v3v3(temp, norm); + + dst_r[0] = point[0] - (norm[0] * dotprod); + dst_r[1] = point[1] - (norm[1] * dotprod); + dst_r[2] = point[2] - (norm[2] * dotprod); +} + +/* distance of two vectors a and b of size length */ +static float distance(float* a, float *b, int length) { + int i; + float sum = 0; + for(i = 0; i < length; i++) { + sum += (b[i]-a[i])*(b[i]-a[i]); + } + return sqrt(sum); +} + +/* given a plane and a start and end position, +compute the amount of vertical distance relative to the plane and store it in dists, +then get the horizontal and vertical change and store them in changes +*/ +static void getVerticalAndHorizontalChange(float *norm, float d, float *coord, float *start, float distToStart, float *end, float (*changes)[2], float *dists, int index) { + // A=Q-((Q-P).N)N + // D = (a*x0 + b*y0 +c*z0 +d) + float projA[3] = {0}, projB[3] = {0}; + + getNearestPointOnPlane(norm, coord, start, projA); + getNearestPointOnPlane(norm, coord, end, projB); + // (vertical and horizontal refer to the plane's y and xz respectively) + // vertical distance + dists[index] = norm[0]*end[0] + norm[1]*end[1] + norm[2]*end[2] + d; + // vertical change + changes[index][0] = dists[index] - distToStart; + //printf("vc %f %f\n", distance(end, projB, 3)-distance(start, projA, 3), changes[index][0]); + // horizontal change + changes[index][1] = distance(projA, projB, 3); +} + +// I need the derived mesh to be forgotten so the positions are recalculated with weight changes (see dm_deform_recalc) +static void dm_deform_clear(DerivedMesh *dm, Object *ob) { + if(ob->derivedDeform && (ob->derivedDeform)==dm) { + ob->derivedDeform->needsFree = 1; + ob->derivedDeform->release(ob->derivedDeform); + ob->derivedDeform = NULL; + } + else if(dm) { + dm->needsFree = 1; + dm->release(dm); + } +} + +// recalculate the deformation +static DerivedMesh* dm_deform_recalc(Scene *scene, Object *ob) { + return mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); +} + +/* by changing nonzero weights, try to move a vertex in me->mverts with index 'index' to distToBe distance away from the provided plane +strength can change distToBe so that it moves towards distToBe by that percentage +cp changes how much the weights are adjusted to check the distance + +index is the index of the vertex being moved +norm and d are the plane's properties for the equation: ax + by + cz + d = 0 +coord is a point on the plane +*/ +static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, int index, float norm[3], float coord[3], float d, float distToBe, float strength, float cp) { + DerivedMesh *dm; + MDeformWeight *dw; + MVert m; + MDeformVert *dvert = me->dvert+index; + int totweight = dvert->totweight; + float oldw = 0; + float oldPos[3] = {0}; + float vc, hc, dist; + int i, k; + float (*changes)[2] = MEM_mallocN(sizeof(float *)*totweight*2, "vertHorzChange"); + float *dists = MEM_mallocN(sizeof(float)*totweight, "distance"); + int *upDown = MEM_callocN(sizeof(int)*totweight, "upDownTracker");// track if up or down moved it closer for each bone + int *dwIndices = MEM_callocN(sizeof(int)*totweight, "dwIndexTracker"); + float distToStart; + int bestIndex = 0; + char wasChange; + char wasUp; + int lastIndex = -1; + float originalDistToBe = distToBe; + do { + wasChange = FALSE; + dm = dm_deform_recalc(scene, ob); + dm->getVert(dm, index, &m); + oldPos[0] = m.co[0]; + oldPos[1] = m.co[1]; + oldPos[2] = m.co[2]; + distToStart = norm[0]*oldPos[0] + norm[1]*oldPos[1] + norm[2]*oldPos[2] + d; + + if(distToBe == originalDistToBe) { + distToBe += distToStart - distToStart*strength; + } + for(i = 0; i < totweight; i++) { + dwIndices[i] = i; + dw = (dvert->dw+i); + vc = hc = 0; + if(!dw->weight) { + changes[i][0] = 0; + changes[i][1] = 0; + dists[i] = distToStart; + continue; + } + for(k = 0; k < 2; k++) { + if(dm) { + dm_deform_clear(dm, ob); dm = NULL; + } + oldw = dw->weight; + if(k) { + dw->weight *= 1+cp; + } else { + dw->weight /= 1+cp; + } + if(dw->weight == oldw) { + changes[i][0] = 0; + changes[i][1] = 0; + dists[i] = distToStart; + break; + } + if(dw->weight > 1) { + dw->weight = 1; + } + dm = dm_deform_recalc(scene, ob); + dm->getVert(dm, index, &m); + getVerticalAndHorizontalChange(norm, d, coord, oldPos, distToStart, m.co, changes, dists, i); + dw->weight = oldw; + if(!k) { + vc = changes[i][0]; + hc = changes[i][1]; + dist = dists[i]; + } else { + if(fabs(dist - distToBe) < fabs(dists[i] - distToBe)) { + upDown[i] = 0; + changes[i][0] = vc; + changes[i][1] = hc; + dists[i] = dist; + } else { + upDown[i] = 1; + } + if(fabs(dists[i] - distToBe) > fabs(distToStart - distToBe)) { + changes[i][0] = 0; + changes[i][1] = 0; + dists[i] = distToStart; + } + } + } + } + // sort the changes by the vertical change + for(k = 0; k < totweight; k++) { + float tf; + int ti; + bestIndex = k; + for(i = k+1; i < totweight; i++) { + dist = dists[i]; + + if(fabs(dist) > fabs(dists[i])) { + bestIndex = i; + } + } + // switch with k + if(bestIndex != k) { + ti = upDown[k]; + upDown[k] = upDown[bestIndex]; + upDown[bestIndex] = ti; + + ti = dwIndices[k]; + dwIndices[k] = dwIndices[bestIndex]; + dwIndices[bestIndex] = ti; + + tf = changes[k][0]; + changes[k][0] = changes[bestIndex][0]; + changes[bestIndex][0] = tf; + + tf = changes[k][1]; + changes[k][1] = changes[bestIndex][1]; + changes[bestIndex][1] = tf; + + tf = dists[k]; + dists[k] = dists[bestIndex]; + dists[bestIndex] = tf; + } + } + bestIndex = -1; + // find the best change with an acceptable horizontal change + for(i = 0; i < totweight; i++) { + if(fabs(changes[i][0]) > fabs(changes[i][1]*2.0f)) { + bestIndex = i; + break; + } + } + if(bestIndex != -1) { + wasChange = TRUE; + // it is a good place to stop if it tries to move the opposite direction + // (relative to the plane) of last time + if(lastIndex != -1) { + if(wasUp != upDown[bestIndex]) { + wasChange = FALSE; + } + } + lastIndex = bestIndex; + wasUp = upDown[bestIndex]; + dw = (dvert->dw+dwIndices[bestIndex]); + oldw = dw->weight; + if(upDown[bestIndex]) { + dw->weight *= 1+cp; + } else { + dw->weight /= 1+cp; + } + if(dw->weight > 1) { + dw->weight = 1; + } + if(oldw == dw->weight) { + wasChange = FALSE; + } + if(dm) { + dm_deform_clear(dm, ob); dm = NULL; + } + } + }while(wasChange && (distToStart-distToBe)/fabs(distToStart-distToBe) == (dists[bestIndex]-distToBe)/fabs(dists[bestIndex]-distToBe)); + MEM_freeN(upDown); + MEM_freeN(changes); + MEM_freeN(dists); + MEM_freeN(dwIndices); +} + +/* this is used to try to smooth a surface by only adjusting the nonzero weights of a vertex +but it could be used to raise or lower an existing 'bump.' */ +static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, float cp) +{ + int i; + + Mesh *me = ob->data; + MVert *mvert = me->mvert; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; + int *verts = NULL; + for(i = 0; i < me->totvert && mvert; i++, mvert++) { + + if(use_vert_sel && (mvert->flag & SELECT)) { + + int count=0; + if((verts = getSurroundingVerts(me, i, &count))) { + MVert m; + MVert *p = MEM_callocN(sizeof(MVert)*(count), "deformedPoints"); + int k; + + DerivedMesh *dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); + for(k = 0; k < count; k++) { + dm->getVert(dm, verts[k], &m); + p[k] = m; + } + + if(count >= 3) { + float d /*, dist */ /* UNUSED */, mag; + float coord[3] = {0}; + float norm[3] = {0}; + getSingleCoordinate(p, count, coord); + dm->getVert(dm, i, &m); + norm[0] = m.co[0]-coord[0]; + norm[1] = m.co[1]-coord[1]; + norm[2] = m.co[2]-coord[2]; + mag = sqrt(norm[0]*norm[0] + norm[1]*norm[1] + norm[2]*norm[2]); + if(mag) {// zeros fix + mul_v3_fl(norm, 1.0f/mag); + + d = -norm[0]*coord[0] -norm[1]*coord[1] -norm[2]*coord[2]; + /* dist = (norm[0]*m.co[0] + norm[1]*m.co[1] + norm[2]*m.co[2] + d); */ /* UNUSED */ + moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, distToBe, strength, cp); + } + } + + MEM_freeN(verts); + MEM_freeN(p); + } + } + } +} + static void vgroup_levels(Object *ob, float offset, float gain) { bDeformGroup *dg; @@ -743,6 +1154,10 @@ static void vgroup_levels(Object *ob, float offset, float gain) MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; + Mesh *me = ob->data; + MVert *mvert = me->mvert; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; + ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); dg = BLI_findlink(&ob->defbase, (ob->actdef-1)); @@ -751,6 +1166,11 @@ static void vgroup_levels(Object *ob, float offset, float gain) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { + + if(use_vert_sel && !(mvert[i].flag & SELECT)) { + continue; + } + dvert = dvert_array[i]; dw = defvert_find_index(dvert, def_nr); if(dw) { @@ -772,6 +1192,11 @@ static void vgroup_normalize_all(Object *ob, int lock_active) int i, dvert_tot=0; float tot_weight; + + Mesh *me = ob->data; + MVert *mvert = me->mvert; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; + ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); if(dvert_array) { @@ -781,6 +1206,10 @@ static void vgroup_normalize_all(Object *ob, int lock_active) for(i = 0; i < dvert_tot; i++) { float lock_iweight= 1.0f; int j; + + if(use_vert_sel && !(mvert[i].flag & SELECT)) { + continue; + } tot_weight= 0.0f; dw_act= NULL; @@ -821,6 +1250,11 @@ static void vgroup_normalize_all(Object *ob, int lock_active) else { for(i = 0; i < dvert_tot; i++) { int j; + + if(use_vert_sel && !(mvert[i].flag & SELECT)) { + continue; + } + tot_weight= 0.0f; dvert = dvert_array[i]; @@ -848,12 +1282,45 @@ static void vgroup_normalize_all(Object *ob, int lock_active) } +static void vgroup_lock_all(Object *ob, int action) +{ + bDeformGroup *dg; + + if(action == SEL_TOGGLE) { + action= SEL_SELECT; + for(dg= ob->defbase.first; dg; dg= dg->next) { + if(dg->flag & DG_LOCK_WEIGHT) { + action= SEL_DESELECT; + break; + } + } + } + + for(dg= ob->defbase.first; dg; dg= dg->next) { + switch(action) { + case SEL_SELECT: + dg->flag |= DG_LOCK_WEIGHT; + break; + case SEL_DESELECT: + dg->flag &= ~DG_LOCK_WEIGHT; + break; + case SEL_INVERT: + dg->flag ^= DG_LOCK_WEIGHT; + break; + } + } +} + static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) { bDeformGroup *dg; MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; + + Mesh *me = ob->data; + MVert *mvert = me->mvert; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -864,6 +1331,10 @@ static void vgroup_invert(Object *ob, int auto_assign, int auto_remove) for(i = 0; i < dvert_tot; i++) { + + if(use_vert_sel && !(mvert[i].flag & SELECT)) { + continue; + } dvert = dvert_array[i]; if(auto_assign) { @@ -976,6 +1447,10 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, def_nr, dvert_tot=0; + + Mesh *me = ob->data; + MVert *mvert = me->mvert; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); @@ -985,6 +1460,10 @@ static void vgroup_clean(Object *ob, float eul, int keep_single) def_nr= ob->actdef-1; for(i = 0; i < dvert_tot; i++) { + + if(use_vert_sel && !(mvert[i].flag & SELECT)) { + continue; + } dvert = dvert_array[i]; dw= defvert_find_index(dvert, def_nr); @@ -1006,12 +1485,21 @@ static void vgroup_clean_all(Object *ob, float eul, int keep_single) MDeformWeight *dw; MDeformVert *dvert, **dvert_array=NULL; int i, dvert_tot=0; + + Mesh *me = ob->data; + MVert *mvert = me->mvert; + const int use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; ED_vgroup_give_parray(ob->data, &dvert_array, &dvert_tot); if(dvert_array) { for(i = 0; i < dvert_tot; i++) { int j; + + if(use_vert_sel && !(mvert[i].flag & SELECT)) { + continue; + } + dvert = dvert_array[i]; j= dvert->totweight; @@ -1832,6 +2320,82 @@ void OBJECT_OT_vertex_group_normalize_all(wmOperatorType *ot) RNA_def_boolean(ot->srna, "lock_active", TRUE, "Lock Active", "Keep the values of the active group while normalizing others"); } +static int vertex_group_fix_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_active_object(C); + Scene *scene= CTX_data_scene(C); + + float distToBe= RNA_float_get(op->ptr, "dist"); + float strength= RNA_float_get(op->ptr, "strength"); + float cp= RNA_float_get(op->ptr, "accuracy"); + ModifierData *md= ob->modifiers.first; + + while(md) { + if(md->type == eModifierType_Mirror && (md->mode&eModifierMode_Realtime)) { + break; + } + md = md->next; + } + + if(md && md->type == eModifierType_Mirror) { + BKE_report(op->reports, RPT_ERROR_INVALID_CONTEXT, "This operator does not support an active mirror modifier"); + return OPERATOR_CANCELLED; + } + vgroup_fix(scene, ob, distToBe, strength, cp); + + DAG_id_tag_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_vertex_group_fix(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Fix Vertex Group Deform"; + ot->idname= "OBJECT_OT_vertex_group_fix"; + ot->description= "Modify the position of selected vertices by changing only their respective groups' weights (this tool may be slow for many vertices)."; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_fix_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + RNA_def_float(ot->srna, "dist", 0.0f, -FLT_MAX, FLT_MAX, "Distance", "The distance to move to.", -10.0f, 10.0f); + RNA_def_float(ot->srna, "strength", 1.f, -2.0f, FLT_MAX, "Strength", "The distance moved can be changed by this multiplier.", -2.0f, 2.0f); + RNA_def_float(ot->srna, "accuracy", 1.0f, 0.05f, FLT_MAX, "Change Sensitivity", "Changes the amount weights are altered with each iteration: lower values are slower.", 0.05f, 1.f); +} + + +static int vertex_group_lock_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_active_object(C); + + int action = RNA_enum_get(op->ptr, "action"); + + vgroup_lock_all(ob, action); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_vertex_group_lock(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Change the Lock On Vertex Groups"; + ot->idname= "OBJECT_OT_vertex_group_lock"; + + /* api callbacks */ + ot->poll= vertex_group_poll; + ot->exec= vertex_group_lock_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + WM_operator_properties_select_all(ot); +} + static int vertex_group_invert_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 37c720ea43b..eb919261127 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -5409,6 +5409,15 @@ int facemask_paint_poll(bContext *C) return paint_facesel_test(CTX_data_active_object(C)); } +int vert_paint_poll(bContext *C) +{ + return paint_vertsel_test(CTX_data_active_object(C)); +} + +int mask_paint_poll(bContext *C) +{ + return paint_facesel_test(CTX_data_active_object(C)) || paint_vertsel_test(CTX_data_active_object(C)); +} /* use project paint to re-apply an image */ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op) { diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 5a0ee19d6c9..f671b7b1713 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -122,6 +122,11 @@ void PAINT_OT_face_select_inverse(struct wmOperatorType *ot); void PAINT_OT_face_select_hide(struct wmOperatorType *ot); void PAINT_OT_face_select_reveal(struct wmOperatorType *ot); +void PAINT_OT_vert_select_all(struct wmOperatorType *ot); +void PAINT_OT_vert_select_inverse(struct wmOperatorType *ot); +int vert_paint_poll(struct bContext *C); +int mask_paint_poll(struct bContext *C); + int facemask_paint_poll(struct bContext *C); /* stroke operator */ diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 69af50415cc..287d204115c 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -373,6 +373,10 @@ void ED_operatortypes_paint(void) WM_operatortype_append(PAINT_OT_weight_sample); WM_operatortype_append(PAINT_OT_weight_sample_group); + /* vertex selection */ + WM_operatortype_append(PAINT_OT_vert_select_all); + WM_operatortype_append(PAINT_OT_vert_select_inverse); + /* vertex */ WM_operatortype_append(PAINT_OT_vertex_paint_toggle); WM_operatortype_append(PAINT_OT_vertex_paint); @@ -607,6 +611,17 @@ void ED_keymap_paint(wmKeyConfig *keyconf) WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0); + + /*Weight paint's Vertex Selection Mode */ + keymap= WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0); + keymap->poll= vert_paint_poll; + WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "PAINT_OT_vert_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0); + RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0)->ptr, "deselect", 1); + WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0); + /* Image/Texture Paint mode */ keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0); keymap->poll= image_texture_paint_poll; diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 33b8a7ca686..d332dc6ec0d 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -1,5 +1,5 @@ /* - * $Id: + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -387,6 +387,49 @@ void PAINT_OT_face_select_all(wmOperatorType *ot) WM_operator_properties_select_all(ot); } + +static int vert_select_all_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_active_object(C); + paintvert_deselect_all_visible(ob, RNA_enum_get(op->ptr, "action"), TRUE); + ED_region_tag_redraw(CTX_wm_region(C)); + return OPERATOR_FINISHED; +} + + +void PAINT_OT_vert_select_all(wmOperatorType *ot) +{ + ot->name= "Vertex Selection"; + ot->description= "Change selection for all vertices"; + ot->idname= "PAINT_OT_vert_select_all"; + + ot->exec= vert_select_all_exec; + ot->poll= vert_paint_poll; + + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + WM_operator_properties_select_all(ot); +} + +static int vert_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Object *ob= CTX_data_active_object(C); + paintvert_deselect_all_visible(ob, SEL_INVERT, TRUE); + ED_region_tag_redraw(CTX_wm_region(C)); + return OPERATOR_FINISHED; +} + +void PAINT_OT_vert_select_inverse(wmOperatorType *ot) +{ + ot->name= "Vertex Select Invert"; + ot->description= "Invert selection of vertices"; + ot->idname= "PAINT_OT_vert_select_inverse"; + + ot->exec= vert_select_inverse_exec; + ot->poll= vert_paint_poll; + + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} static int face_select_inverse_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob= CTX_data_active_object(C); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index b2aa1be3b9f..11a46bb373b 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -64,6 +64,7 @@ #include "RNA_enum_types.h" #include "BKE_DerivedMesh.h" +#include "BKE_armature.h" #include "BKE_action.h" #include "BKE_brush.h" #include "BKE_context.h" @@ -390,25 +391,27 @@ void vpaint_fill(Object *ob, unsigned int paintcol) void wpaint_fill(VPaint *wp, Object *ob, float paintweight) { Mesh *me; - MFace *mface; MDeformWeight *dw, *uw; int *indexar; - int index, vgroup; - unsigned int faceverts[5]={0,0,0,0,0}; - unsigned char i; - int vgroup_mirror= -1; + unsigned int index; + int vgroup, vgroup_mirror= -1; int selected; + int use_vert_sel; + me= ob->data; if(me==NULL || me->totface==0 || me->dvert==NULL || !me->mface) return; selected= (me->editflag & ME_EDIT_PAINT_MASK); + + use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; indexar= get_indexarray(me); if(selected) { - for(index=0, mface=me->mface; index<me->totface; index++, mface++) { - if((mface->flag & ME_FACE_SEL)==0) + MFace *mf; + for(index=0, mf= me->mface; index<me->totface; index++, mf++) { + if((mf->flag & ME_FACE_SEL)==0) indexar[index]= 0; else indexar[index]= index+1; @@ -430,22 +433,25 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) for(index=0; index<me->totface; index++) { if(indexar[index] && indexar[index]<=me->totface) { - mface= me->mface + (indexar[index]-1); - /* just so we can loop through the verts */ - faceverts[0]= mface->v1; - faceverts[1]= mface->v2; - faceverts[2]= mface->v3; - faceverts[3]= mface->v4; - for (i=0; i<3 || faceverts[i]; i++) { - if(!((me->dvert+faceverts[i])->flag)) { - dw= defvert_verify_index(me->dvert+faceverts[i], vgroup); + MFace *mf= &me->mface[indexar[index]-1]; + unsigned int fidx= mf->v4 ? 3:2; + + do { + unsigned int vidx= *(&mf->v1 + fidx); + + if(!me->dvert[vidx].flag) { + if(use_vert_sel && !(me->mvert[vidx].flag & SELECT)) { + continue; + } + + dw= defvert_verify_index(&me->dvert[vidx], vgroup); if(dw) { - uw= defvert_verify_index(wp->wpaint_prev+faceverts[i], vgroup); + uw= defvert_verify_index(wp->wpaint_prev+vidx, vgroup); uw->weight= dw->weight; /* set the undo weight */ dw->weight= paintweight; - + if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ - int j= mesh_get_x_mirror_vert(ob, faceverts[i]); + int j= mesh_get_x_mirror_vert(ob, vidx); if(j>=0) { /* copy, not paint again */ if(vgroup_mirror != -1) { @@ -460,16 +466,19 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight) } } } - (me->dvert+faceverts[i])->flag= 1; + me->dvert[vidx].flag= 1; } - } + + + } while (fidx--); } } - - index=0; - while (index<me->totvert) { - (me->dvert+index)->flag= 0; - index++; + + { + MDeformVert *dv= me->dvert; + for(index= me->totvert; index != 0; index--, dv++) { + dv->flag= 0; + } } MEM_freeN(indexar); @@ -792,7 +801,7 @@ static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], fl return alpha; } -static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float alpha, float paintval, int flip) +static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float alpha, float paintval, int flip, int multipaint) { Brush *brush = paint_brush(&wp->paint); int tool = brush->vertexpaint_tool; @@ -830,7 +839,10 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float if (dw->weight > paintval) dw->weight = paintval*alpha + dw->weight*(1.0f-alpha); } - CLAMP(dw->weight, 0.0f, 1.0f); + /* delay clamping until the end so multi-paint can function when the active group is at the limits */ + if(multipaint == FALSE) { + CLAMP(dw->weight, 0.0f, 1.0f); + } /* if no spray, clip result with orig weight & orig alpha */ if((wp->flag & VP_SPRAY)==0) { @@ -857,15 +869,17 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float else testw = uw->weight; } - CLAMP(testw, 0.0f, 1.0f); - - if( testw<uw->weight ) { - if(dw->weight < testw) dw->weight= testw; - else if(dw->weight > uw->weight) dw->weight= uw->weight; - } - else { - if(dw->weight > testw) dw->weight= testw; - else if(dw->weight < uw->weight) dw->weight= uw->weight; + + if(multipaint == FALSE) { + CLAMP(testw, 0.0f, 1.0f); + if( testw<uw->weight ) { + if(dw->weight < testw) dw->weight= testw; + else if(dw->weight > uw->weight) dw->weight= uw->weight; + } + else { + if(dw->weight > testw) dw->weight= testw; + else if(dw->weight < uw->weight) dw->weight= uw->weight; + } } } @@ -980,7 +994,7 @@ static EnumPropertyItem *weight_paint_sample_enum_itemf(bContext *C, PointerRNA const int totgroup= BLI_countlist(&vc.obact->defbase); if(totgroup) { MFace *mf= ((MFace *)me->mface) + index-1; - int fidx= mf->v4 ? 3:2; + unsigned int fidx= mf->v4 ? 3:2; int *groups= MEM_callocN(totgroup*sizeof(int), "groups"); int found= FALSE; @@ -1062,6 +1076,7 @@ void PAINT_OT_weight_sample_group(wmOperatorType *ot) } +#if 0 /* UNUSED */ static void do_weight_paint_auto_normalize(MDeformVert *dvert, int paint_nr, char *map) { @@ -1096,41 +1111,600 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert, } } } +#endif + +/* the active group should be involved in auto normalize */ +static void do_weight_paint_auto_normalize_all_groups(MDeformVert *dvert, char *map, char do_auto_normalize) +{ +// MDeformWeight *dw = dvert->dw; + float sum=0.0f, fac=0.0f; + int i, tot=0; + + if (do_auto_normalize == FALSE) + return; + + for (i=0; i<dvert->totweight; i++) { + if (map[dvert->dw[i].def_nr]) { + tot += 1; + sum += dvert->dw[i].weight; + } + } + + if (!tot || sum == 1.0f) + return; + + fac = sum; + fac = fac==0.0f ? 1.0f : 1.0f / fac; + + for (i=0; i<dvert->totweight; i++) { + if (map[dvert->dw[i].def_nr]) { + dvert->dw[i].weight *= fac; + } + } +} + +/* +See if the current deform vertex has a locked group +*/ +static char has_locked_group(MDeformVert *dvert, const char *lock_flags) +{ + int i; + for(i = 0; i < dvert->totweight; i++) { + if(lock_flags[dvert->dw[i].def_nr] && dvert->dw[i].weight > 0.0f) { + return TRUE; + } + } + return FALSE; +} +/* + * gen_lck_flags gets the status of "flag" for each bDeformGroup + *in ob->defbase and returns an array containing them + */ +static char *gen_lock_flags(Object* ob, int defbase_tot) +{ + char is_locked = FALSE; + int i; + //int defbase_tot = BLI_countlist(&ob->defbase); + char *lock_flags = MEM_mallocN(defbase_tot*sizeof(char), "defflags"); + bDeformGroup *defgroup; + + for(i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) { + lock_flags[i] = ((defgroup->flag & DG_LOCK_WEIGHT) != 0); + is_locked |= lock_flags[i]; + } + if(is_locked){ + return lock_flags; + } + + MEM_freeN(lock_flags); + return NULL; +} + +static int has_locked_group_selected(int defbase_tot, char *defbase_sel, char *lock_flags) +{ + int i; + for(i = 0; i < defbase_tot; i++) { + if(defbase_sel[i] && lock_flags[i]) { + return TRUE; + } + } + return FALSE; +} + + +#if 0 /* UNUSED */ +static int has_unselected_unlocked_bone_group(int defbase_tot, char *defbase_sel, int selected, char *lock_flags, char *vgroup_validmap) +{ + int i; + if(defbase_tot == selected) { + return FALSE; + } + for(i = 0; i < defbase_tot; i++) { + if(vgroup_validmap[i] && !defbase_sel[i] && !lock_flags[i]) { + return TRUE; + } + } + return FALSE; +} +#endif + + +static void multipaint_selection(MDeformVert *dvert, float change, char *defbase_sel, int defbase_tot) +{ + int i; + MDeformWeight *dw; + float val; + /* make sure they are all at most 1 after the change */ + for(i = 0; i < defbase_tot; i++) { + if(defbase_sel[i]) { + dw = defvert_find_index(dvert, i); + if(dw && dw->weight) { + val = dw->weight * change; + if(val > 1) { + /* TODO: when the change is reduced, you need to recheck + * the earlier values to make sure they are not 0 + * (precision error) */ + change = 1.0f/dw->weight; + } + /* the value should never reach zero while multi-painting if it + * was nonzero beforehand */ + if(val <= 0) { + return; + } + } + } + } + /* apply the valid change */ + for(i = 0; i < defbase_tot; i++) { + if(defbase_sel[i]) { + dw = defvert_find_index(dvert, i); + if(dw && dw->weight) { + dw->weight = dw->weight * change; + } + } + } +} + +/* move all change onto valid, unchanged groups. If there is change left over, + * then return it. + * assumes there are valid groups to shift weight onto */ +static float redistribute_change(MDeformVert *ndv, char *change_status, int changeme, int changeto, float totchange, float total_valid, char do_auto_normalize) +{ + float was_change; + float change; + float oldval; + MDeformWeight *ndw; + int i; + do { + /* assume there is no change until you see one */ + was_change = FALSE; + /* change each group by the same amount each time */ + change = totchange/total_valid; + for(i = 0; i < ndv->totweight && total_valid && totchange; i++) { + ndw = (ndv->dw+i); + /* change only the groups with a valid status */ + if(change_status[ndw->def_nr] == changeme) { + oldval = ndw->weight; + /* if auto normalize is active, don't worry about upper bounds */ + if(do_auto_normalize == FALSE && ndw->weight + change > 1) { + totchange -= 1-ndw->weight; + ndw->weight = 1; + /* stop the changes to this group */ + change_status[ndw->def_nr] = changeto; + total_valid--; + } + else if(ndw->weight + change < 0) { /* check the lower bound */ + totchange -= ndw->weight; + ndw->weight = 0; + change_status[ndw->def_nr] = changeto; + total_valid--; + } + else {/* a perfectly valid change occurred to ndw->weight */ + totchange -= change; + ndw->weight += change; + } + /* see if there was a change */ + if(oldval != ndw->weight) { + was_change = TRUE; + } + } + } + /* don't go again if there was no change, if there is no valid group, + * or there is no change left */ + } while(was_change && total_valid && totchange); + /* left overs */ + return totchange; +} + +/* observe the changes made to the weights of groups. + * make sure all locked groups on the vertex have the same deformation + * by moving the changes made to groups onto other unlocked groups */ +static void enforce_locks(MDeformVert *odv, MDeformVert *ndv, int defbase_tot, + const char *lock_flags, const char *vgroup_validmap, char do_auto_normalize) +{ + float totchange = 0.0f; + float totchange_allowed = 0.0f; + float left_over; + + int total_valid = 0; + int total_changed = 0; + unsigned int i; + MDeformWeight *ndw; + MDeformWeight *odw; + MDeformWeight *ndw2; + MDeformWeight *odw2; + int designatedw = -1; + int designatedw_changed = FALSE; + float storedw; + char *change_status; + char new_weight_has_zero = FALSE; + + if(!lock_flags || !has_locked_group(ndv, lock_flags)) { + return; + } + /* record if a group was changed, unlocked and not changed, or locked */ + change_status = MEM_callocN(sizeof(char)*defbase_tot, "unlocked_unchanged"); + + for(i = 0; i < defbase_tot; i++) { + ndw = defvert_find_index(ndv, i); + odw = defvert_find_index(odv, i); + /* the weights are zero, so we can assume a lot */ + if(!ndw || !odw) { + if (!lock_flags[i] && vgroup_validmap[i]){ + defvert_verify_index(odv, i); + defvert_verify_index(ndv, i); + total_valid++; + change_status[i] = 1; /* can be altered while redistributing */ + } + continue; + } + /* locked groups should not be changed */ + if(lock_flags[i]) { + ndw->weight = odw->weight; + } + else if(ndw->weight != odw->weight) { /* changed groups are handled here */ + totchange += ndw->weight - odw->weight; + change_status[i] = 2; /* was altered already */ + total_changed++; + if(ndw->weight == 0) { + new_weight_has_zero = TRUE; + } + else if(designatedw == -1){ + designatedw = i; + } + } /* unchanged, unlocked bone groups are handled here */ + else if (vgroup_validmap[i]){ + totchange_allowed += ndw->weight; + total_valid++; + change_status[i] = 1; /* can be altered while redistributing */ + } + } + /* if there was any change, redistribute it */ + if(total_changed) { + /* auto normalize will allow weights to temporarily go above 1 in redistribution */ + if(vgroup_validmap && total_changed < 0 && total_valid) { + totchange_allowed = total_valid; + } + /* there needs to be change allowed, or you should not bother */ + if(totchange_allowed) { + /* the way you modify the unlocked+unchanged groups is different depending + * on whether or not you are painting the weight(s) up or down */ + if(totchange < 0) { + totchange_allowed = total_valid - totchange_allowed; + } + else { + totchange_allowed *= -1; + } + left_over = 0; + if(fabsf(totchange_allowed) < fabsf(totchange)) { + /* this amount goes back onto the changed, unlocked weights */ + left_over = fabsf(fabsf(totchange) - fabsf(totchange_allowed)); + if(totchange > 0) { + left_over *= -1; + } + } + else { + /* all of the change will be permitted */ + totchange_allowed = -totchange; + } + /* move the weight evenly between the allowed groups, move excess back onto the used groups based on the change */ + totchange_allowed = redistribute_change(ndv, change_status, 1, -1, totchange_allowed, total_valid, do_auto_normalize); + left_over += totchange_allowed; + if(left_over) { + /* more than one nonzero weights were changed with the same ratio, so keep them changed that way! */ + if(total_changed > 1 && !new_weight_has_zero && designatedw >= 0) { + /* this dw is special, it is used as a base to determine how to change the others */ + ndw = defvert_find_index(ndv, designatedw); + odw = defvert_find_index(odv, designatedw); + storedw = ndw->weight; + for(i = 0; i < ndv->totweight; i++) { + if(change_status[ndw->def_nr] == 2) { + odw2 = &odv->dw[i]; + ndw2 = &ndv->dw[i]; + if(!designatedw_changed) { + ndw->weight = (totchange_allowed + odw->weight + odw2->weight)/(1.0f + ndw2->weight/ndw->weight); + designatedw_changed = TRUE; + } + ndw2->weight = ndw->weight * ndw2->weight / storedw; + } + } + } + /* a weight was changed to zero, only one weight was changed, + * or designatedw is still -1 put weight back as evenly as possible */ + else { + redistribute_change(ndv, change_status, 2, -2, left_over, total_changed, do_auto_normalize); + } + } + } + else { + /* reset the weights */ + unsigned int i; + MDeformWeight *dw_old= odv->dw; + MDeformWeight *dw_new= ndv->dw; + + for (i= odv->totweight; i != 0; i--, dw_old++, dw_new++) { + dw_new->weight= dw_old->weight; + } + } + } + + MEM_freeN(change_status); +} -static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, - float alpha, float paintweight, int flip, - int vgroup_mirror, char *validmap) +/* multi-paint's initial, potential change is computed here based on the user's stroke */ +static float get_mp_change(MDeformVert *odv, char *defbase_sel, float brush_change) +{ + float selwsum = 0.0f; + unsigned int i; + MDeformWeight *dw= odv->dw; + + for (i= odv->totweight; i != 0; i--, dw++) { + if(defbase_sel[dw->def_nr]) { + selwsum += dw->weight; + } + } + if(selwsum && selwsum+brush_change > 0) { + return (selwsum+brush_change)/selwsum; + } + return 0.0f; +} + +/* change the weights back to the wv's weights + * it assumes you already have the correct pointer index */ +static void reset_to_prev(MDeformVert *wv, MDeformVert *dvert) +{ + MDeformWeight *dw= dvert->dw; + MDeformWeight *w; + unsigned int i; + for (i= dvert->totweight; i != 0; i--, dw++) { + w= defvert_find_index(wv, dw->def_nr); + /* if there was no w when there is a d, then the old weight was 0 */ + dw->weight = w ? w->weight : 0.0f; + } +} + +static void clamp_weights(MDeformVert *dvert) +{ + MDeformWeight *dw= dvert->dw; + unsigned int i; + for (i= dvert->totweight; i != 0; i--, dw++) { + CLAMP(dw->weight, 0.0f, 1.0f); + } +} + +/* struct to avoid passing many args each call to do_weight_paint_vertex() + * this _could_ be made a part of the operators 'WPaintData' struct, or at + * least a member, but for now keep its own struct, initialized on every + * paint stroke update - campbell */ +typedef struct WeightPaintInfo { + + int defbase_tot; + + /* both must add up to 'defbase_tot' */ + int defbase_tot_sel; + int defbase_tot_unsel; + + int vgroup_mirror; /* mirror group or -1 */ + + char *lock_flags; /* boolean array for locked bones, + * length of defbase_tot */ + char *defbase_sel; /* boolean array for selected bones, + * length of defbase_tot */ + + char *vgroup_validmap; /* same as WeightPaintData.vgroup_validmap, + * only added here for convenience */ + + char do_flip; + char do_multipaint; + char do_auto_normalize; +} WeightPaintInfo; + +/* fresh start to make multi-paint and locking modular */ +/* returns TRUE if it thinks you need to reset the weights due to + * normalizing while multi-painting */ +static int apply_mp_locks_normalize(Mesh *me, const WeightPaintInfo *wpi, + const unsigned int index, + MDeformWeight *dw, MDeformWeight *tdw, + float change, float oldChange, + float oldw, float neww) +{ + MDeformVert *dv= &me->dvert[index]; + MDeformVert dv_test= {NULL}; + + dv_test.dw= MEM_dupallocN(dv->dw); + dv_test.flag = dv->flag; + dv_test.totweight = dv->totweight; + /* do not multi-paint if a locked group is selected or the active group is locked + * !lock_flags[dw->def_nr] helps if nothing is selected, but active group is locked */ + if( (wpi->lock_flags == NULL) || + ((wpi->lock_flags[dw->def_nr] == FALSE) && + has_locked_group_selected(wpi->defbase_tot, wpi->defbase_sel, wpi->lock_flags) == FALSE)) + { + if(wpi->do_multipaint && wpi->defbase_tot_sel > 1) { + if(change && change!=1) { + multipaint_selection(dv, change, wpi->defbase_sel, wpi->defbase_tot); + } + } + else { /* this lets users paint normally, but don't let them paint locked groups */ + dw->weight = neww; + } + } + clamp_weights(dv); + + enforce_locks(&dv_test, dv, wpi->defbase_tot, wpi->lock_flags, wpi->vgroup_validmap, wpi->do_auto_normalize); + + do_weight_paint_auto_normalize_all_groups(dv, wpi->vgroup_validmap, wpi->do_auto_normalize); + + if(oldChange && wpi->do_multipaint && wpi->defbase_tot_sel > 1) { + if(tdw->weight != oldw) { + if(neww > oldw) { + if(tdw->weight <= oldw) { + MEM_freeN(dv_test.dw); + return TRUE; + } + } + else { + if(tdw->weight >= oldw) { + MEM_freeN(dv_test.dw); + return TRUE; + } + } + } + } + MEM_freeN(dv_test.dw); + return FALSE; +} + +/* within the current dvert index, get the dw that is selected and has a weight + * above 0, this helps multi-paint */ +static int get_first_selected_nonzero_weight(MDeformVert *dvert, char *defbase_sel) +{ + int i; + MDeformWeight *dw= dvert->dw; + for(i=0; i< dvert->totweight; i++, dw++) { + if(defbase_sel[dw->def_nr] && dw->weight > 0.0f) { + return i; + } + } + return -1; +} + + +static char *wpaint_make_validmap(Object *ob); + + +static void do_weight_paint_vertex( /* vars which remain the same for every vert */ + VPaint *wp, Object *ob, const WeightPaintInfo *wpi, + /* vars which change on each stroke */ + const unsigned int index, float alpha, float paintweight + ) { Mesh *me= ob->data; + MDeformWeight *dw, *uw; int vgroup= ob->actdef-1; - + if(wp->flag & VP_ONLYVGROUP) { - dw= defvert_find_index(me->dvert+index, vgroup); + dw= defvert_find_index(&me->dvert[index], vgroup); uw= defvert_find_index(wp->wpaint_prev+index, vgroup); } else { - dw= defvert_verify_index(me->dvert+index, vgroup); + dw= defvert_verify_index(&me->dvert[index], vgroup); uw= defvert_verify_index(wp->wpaint_prev+index, vgroup); } if(dw==NULL || uw==NULL) return; - - wpaint_blend(wp, dw, uw, alpha, paintweight, flip); - do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap); - if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ - int j= mesh_get_x_mirror_vert(ob, index); - if(j>=0) { - /* copy, not paint again */ - if(vgroup_mirror != -1) - uw= defvert_verify_index(me->dvert+j, vgroup_mirror); - else - uw= defvert_verify_index(me->dvert+j, vgroup); - - uw->weight= dw->weight; + /* TODO: De-duplicate the simple weight paint - jason */ + /* ... or not, since its <10 SLOC - campbell */ + + /* If there are no locks or multipaint, + * then there is no need to run the more complicated checks */ + if( (wpi->do_multipaint == FALSE || wpi->defbase_tot_sel <= 1) && + (wpi->lock_flags == NULL || has_locked_group(&me->dvert[index], wpi->lock_flags) == FALSE)) + { + wpaint_blend(wp, dw, uw, alpha, paintweight, wpi->do_flip, FALSE); + do_weight_paint_auto_normalize_all_groups(&me->dvert[index], wpi->vgroup_validmap, wpi->do_auto_normalize); + + if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ + int j= mesh_get_x_mirror_vert(ob, index); + if(j>=0) { + /* copy, not paint again */ + uw= defvert_verify_index(me->dvert+j, (wpi->vgroup_mirror != -1) ? wpi->vgroup_mirror : vgroup); + + uw->weight= dw->weight; - do_weight_paint_auto_normalize(me->dvert+j, vgroup, validmap); + do_weight_paint_auto_normalize_all_groups(me->dvert+j, wpi->vgroup_validmap, wpi->do_auto_normalize); + } + } + } + else { + /* use locks and/or multipaint */ + float oldw; + float neww; + float testw=0; + float change = 0; + float oldChange = 0; + int i; + MDeformWeight *tdw = NULL, *tuw; + MDeformVert dv= {NULL}; + + oldw = dw->weight; + wpaint_blend(wp, dw, uw, alpha, paintweight, wpi->do_flip, wpi->do_multipaint && wpi->defbase_tot_sel >1); + neww = dw->weight; + dw->weight = oldw; + + /* setup multi-paint */ + if(wpi->defbase_tot_sel > 1 && wpi->do_multipaint) { + dv.dw= MEM_dupallocN(me->dvert[index].dw); + dv.flag = me->dvert[index].flag; + dv.totweight = me->dvert[index].totweight; + tdw = dw; + tuw = uw; + change = get_mp_change(wp->wpaint_prev+index, wpi->defbase_sel, neww - oldw); + if(change) { + if(!tdw->weight) { + i = get_first_selected_nonzero_weight(&me->dvert[index], wpi->defbase_sel); + if(i>=0) { + tdw = &(me->dvert[index].dw[i]); + tuw = defvert_verify_index(wp->wpaint_prev+index, tdw->def_nr); + } + else { + change = 0; + } + } + if(change && tuw->weight && tuw->weight * change) { + if(tdw->weight != tuw->weight) { + oldChange = tdw->weight/tuw->weight; + testw = tuw->weight*change; + if( testw > tuw->weight ) { + if(change > oldChange) { + /* reset the weights and use the new change */ + reset_to_prev(wp->wpaint_prev+index, &me->dvert[index]); + } + else { + /* the old change was more significant, so set + * the change to 0 so that it will not do another multi-paint */ + change = 0; + } + } + else { + if(change < oldChange) { + reset_to_prev(wp->wpaint_prev+index, &me->dvert[index]); + } + else { + change = 0; + } + } + } + } + else { + change = 0; + } + } + } + + if(apply_mp_locks_normalize(me, wpi, index, dw, tdw, change, oldChange, oldw, neww)) { + reset_to_prev(&dv, &me->dvert[index]); + change = 0; + oldChange = 0; + } + if(dv.dw) { + MEM_freeN(dv.dw); + } + /* dvert may have been altered greatly */ + dw = defvert_find_index(&me->dvert[index], vgroup); + + if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */ + int j= mesh_get_x_mirror_vert(ob, index); + if(j>=0) { + /* copy, not paint again */ + uw= defvert_verify_index(me->dvert+j, (wpi->vgroup_mirror != -1) ? wpi->vgroup_mirror : vgroup); + + //uw->weight= dw->weight; + + apply_mp_locks_normalize(me, wpi, j, uw, tdw, change, oldChange, oldw, neww); + } } } } @@ -1227,16 +1801,15 @@ struct WPaintData { /*variables for auto normalize*/ int auto_normalize; char *vgroup_validmap; /*stores if vgroups tie to deforming bones or not*/ + char *lock_flags; + int defbase_tot; }; static char *wpaint_make_validmap(Object *ob) { bDeformGroup *dg; ModifierData *md; - char *validmap; - bPose *pose; - bPoseChannel *chan; - ArmatureModifierData *amd; + char *vgroup_validmap; GHash *gh = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "wpaint_make_validmap gh"); int i = 0, step1=1; @@ -1248,7 +1821,7 @@ static char *wpaint_make_validmap(Object *ob) if (!i) return NULL; - validmap = MEM_callocN(i, "wpaint valid map"); + vgroup_validmap= MEM_callocN(i, "wpaint valid map"); /*now loop through the armature modifiers and identify deform bones*/ for (md = ob->modifiers.first; md; md= !md->next && step1 ? (step1=0), modifiers_getVirtualModifierList(ob) : md->next) { @@ -1257,10 +1830,11 @@ static char *wpaint_make_validmap(Object *ob) if (md->type == eModifierType_Armature) { - amd = (ArmatureModifierData*) md; + ArmatureModifierData *amd= (ArmatureModifierData*) md; if(amd->object && amd->object->pose) { - pose = amd->object->pose; + bPose *pose= amd->object->pose; + bPoseChannel *chan; for (chan=pose->chanbase.first; chan; chan=chan->next) { if (chan->bone->flag & BONE_NO_DEFORM) @@ -1278,13 +1852,13 @@ static char *wpaint_make_validmap(Object *ob) /*add all names to a hash table*/ for (dg=ob->defbase.first, i=0; dg; dg=dg->next, i++) { if (BLI_ghash_lookup(gh, dg->name) != NULL) { - validmap[i] = 1; + vgroup_validmap[i] = TRUE; } } BLI_ghash_free(gh, NULL, NULL); - return validmap; + return vgroup_validmap; } static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) @@ -1318,7 +1892,9 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED /*set up auto-normalize, and generate map for detecting which vgroups affect deform bones*/ wpd->auto_normalize = ts->auto_normalize; - if (wpd->auto_normalize) + wpd->defbase_tot = BLI_countlist(&ob->defbase); + wpd->lock_flags = gen_lock_flags(ob, wpd->defbase_tot); + if (wpd->auto_normalize || ts->multipaint || wpd->lock_flags) wpd->vgroup_validmap = wpaint_make_validmap(ob); // if(qual & LR_CTRLKEY) { @@ -1385,14 +1961,19 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P float mat[4][4]; float paintweight; int *indexar; - int totindex, index, totw, flip; + int totw; + unsigned int index, totindex; float alpha; float mval[2], pressure; - + int use_vert_sel; + + /* intentionally dont initialize as NULL, make sure we initialize all members below */ + WeightPaintInfo wpi; + /* cannot paint if there is no stroke data */ if (wpd == NULL) { - // XXX: force a redraw here, since even though we can't paint, - // at least view won't freeze until stroke ends + /* XXX: force a redraw here, since even though we can't paint, + * at least view won't freeze until stroke ends */ ED_region_tag_redraw(CTX_wm_region(C)); return; } @@ -1407,17 +1988,39 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P /* load projection matrix */ mul_m4_m4m4(mat, ob->obmat, vc->rv3d->persmat); - flip = RNA_boolean_get(itemptr, "pen_flip"); pressure = RNA_float_get(itemptr, "pressure"); RNA_float_get_array(itemptr, "mouse", mval); mval[0]-= vc->ar->winrct.xmin; mval[1]-= vc->ar->winrct.ymin; - + + + + /* *** setup WeightPaintInfo - pass onto do_weight_paint_vertex *** */ + wpi.defbase_tot= wpd->defbase_tot; + wpi.defbase_sel= MEM_mallocN(wpi.defbase_tot*sizeof(char), "wpi.defbase_sel"); + wpi.defbase_tot_sel= get_selected_defgroups(ob, wpi.defbase_sel, wpi.defbase_tot); + if(wpi.defbase_tot_sel == 0 && ob->actdef) wpi.defbase_tot_sel = 1; + wpi.defbase_tot_unsel= wpi.defbase_tot - wpi.defbase_tot_sel; + wpi.vgroup_mirror= wpd->vgroup_mirror; + wpi.lock_flags= wpd->lock_flags; + wpi.vgroup_validmap= wpd->vgroup_validmap; + wpi.do_flip= RNA_boolean_get(itemptr, "pen_flip"); + wpi.do_multipaint= (ts->multipaint != 0); + wpi.do_auto_normalize= (ts->auto_normalize != 0); + /* *** done setting up WeightPaintInfo *** */ + + + swap_m4m4(wpd->vc.rv3d->persmat, mat); - + + use_vert_sel= (me->editflag & ME_EDIT_VERT_SEL) != 0; + /* which faces are involved */ if(wp->flag & VP_AREA) { + /* Ugly hack, to avoid drawing vertex index when getting the face index buffer - campbell */ + me->editflag &= ~ME_EDIT_VERT_SEL; totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush_size(brush)); + me->editflag |= use_vert_sel ? ME_EDIT_VERT_SEL : 0; } else { indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]); @@ -1460,30 +2063,40 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P for(index=0; index<totindex; index++) { if(indexar[index] && indexar[index]<=me->totface) { MFace *mface= me->mface + (indexar[index]-1); - - (me->dvert+mface->v1)->flag= 1; - (me->dvert+mface->v2)->flag= 1; - (me->dvert+mface->v3)->flag= 1; - if(mface->v4) (me->dvert+mface->v4)->flag= 1; + + if(use_vert_sel) { + me->dvert[mface->v1].flag = (me->mvert[mface->v1].flag & SELECT); + me->dvert[mface->v2].flag = (me->mvert[mface->v2].flag & SELECT); + me->dvert[mface->v3].flag = (me->mvert[mface->v3].flag & SELECT); + if(mface->v4) me->dvert[mface->v4].flag = (me->mvert[mface->v4].flag & SELECT); + } + else { + me->dvert[mface->v1].flag= 1; + me->dvert[mface->v2].flag= 1; + me->dvert[mface->v3].flag= 1; + if(mface->v4) me->dvert[mface->v4].flag= 1; + } if(brush->vertexpaint_tool==VP_BLUR) { MDeformWeight *dw, *(*dw_func)(MDeformVert *, const int); + unsigned int fidx= mface->v4 ? 3:2; if(wp->flag & VP_ONLYVGROUP) dw_func= (MDeformWeight *(*)(MDeformVert *, const int))defvert_find_index; else dw_func= defvert_verify_index; - - dw= dw_func(me->dvert+mface->v1, ob->actdef-1); - if(dw) {paintweight+= dw->weight; totw++;} - dw= dw_func(me->dvert+mface->v2, ob->actdef-1); - if(dw) {paintweight+= dw->weight; totw++;} - dw= dw_func(me->dvert+mface->v3, ob->actdef-1); - if(dw) {paintweight+= dw->weight; totw++;} - if(mface->v4) { - dw= dw_func(me->dvert+mface->v4, ob->actdef-1); - if(dw) {paintweight+= dw->weight; totw++;} - } + + do { + unsigned int vidx= *(&mface->v1 + fidx); + + dw= dw_func(me->dvert+vidx, ob->actdef-1); + if(dw) { + paintweight+= dw->weight; + totw++; + } + + } while (fidx--); + } } } @@ -1494,52 +2107,28 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P for(index=0; index<totindex; index++) { if(indexar[index] && indexar[index]<=me->totface) { - MFace *mface= me->mface + (indexar[index]-1); - - if((me->dvert+mface->v1)->flag) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v1, mval, pressure); - if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v1, - alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap); - } - (me->dvert+mface->v1)->flag= 0; - } - - if((me->dvert+mface->v2)->flag) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v2, mval, pressure); - if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v2, - alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap); - } - (me->dvert+mface->v2)->flag= 0; - } - - if((me->dvert+mface->v3)->flag) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v3, mval, pressure); - if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v3, - alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap); - } - (me->dvert+mface->v3)->flag= 0; - } - - if((me->dvert+mface->v4)->flag) { - if(mface->v4) { - alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v4, mval, pressure); + MFace *mf= me->mface + (indexar[index]-1); + unsigned int fidx= mf->v4 ? 3:2;; + do { + unsigned int vidx= *(&mf->v1 + fidx); + + if(me->dvert[vidx].flag) { + alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*vidx, mval, pressure); if(alpha) { - do_weight_paint_vertex(wp, ob, mface->v4, - alpha, paintweight, flip, wpd->vgroup_mirror, - wpd->vgroup_validmap); + do_weight_paint_vertex(wp, ob, &wpi, vidx, alpha, paintweight); } - (me->dvert+mface->v4)->flag= 0; + me->dvert[vidx].flag= 0; } - } + } while (fidx--); } } - + + + /* *** free wpi members */ + MEM_freeN(wpi.defbase_sel); + /* *** dont freeing wpi members */ + + swap_m4m4(vc->rv3d->persmat, mat); DAG_id_tag_update(ob->data, 0); @@ -1559,7 +2148,9 @@ static void wpaint_stroke_done(bContext *C, struct PaintStroke *stroke) if (wpd->vgroup_validmap) MEM_freeN(wpd->vgroup_validmap); - + if(wpd->lock_flags) + MEM_freeN(wpd->lock_flags); + MEM_freeN(wpd); } @@ -1633,7 +2224,7 @@ static int weight_paint_set_exec(bContext *C, wmOperator *UNUSED(op)) Object *obact = CTX_data_active_object(C); wpaint_fill(scene->toolsettings->wpaint, obact, scene->toolsettings->vgroup_weight); - ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views + ED_region_tag_redraw(CTX_wm_region(C)); /* XXX - should redraw all 3D views */ return OPERATOR_FINISHED; } @@ -1645,7 +2236,7 @@ void PAINT_OT_weight_set(wmOperatorType *ot) /* api callbacks */ ot->exec= weight_paint_set_exec; - ot->poll= facemask_paint_poll; + ot->poll= mask_paint_poll; /* it was facemask_paint_poll */ /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -1781,12 +2372,12 @@ static int vpaint_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent return 1; } -static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index, const float mval[2], float pressure, int UNUSED(flip)) +static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, const unsigned int index, const float mval[2], float pressure, int UNUSED(flip)) { ViewContext *vc = &vpd->vc; Brush *brush = paint_brush(&vp->paint); Mesh *me = get_mesh(ob); - MFace *mface= ((MFace*)me->mface) + index; + MFace *mface= &me->mface[index]; unsigned int *mcol= ((unsigned int*)me->mcol) + 4*index; unsigned int *mcolorig= ((unsigned int*)vp->vpaint_prev) + 4*index; float alpha; diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c index 539e975095e..5b72e87f95a 100644 --- a/source/blender/editors/sound/sound_ops.c +++ b/source/blender/editors/sound/sound_ops.c @@ -436,7 +436,7 @@ static void mixdown_draw(bContext *C, wmOperator *op) } #endif // WITH_AUDASPACE -void SOUND_OT_mixdown(wmOperatorType *ot) +static void SOUND_OT_mixdown(wmOperatorType *ot) { #ifdef WITH_AUDASPACE static EnumPropertyItem format_items[] = { diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index 32594e710a4..dc81fb1e8bc 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -1139,7 +1139,7 @@ static void mouse_action_keys (bAnimContext *ac, const int mval[2], short select static int actkeys_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *event) { bAnimContext ac; - ARegion *ar; + /* ARegion *ar; */ /* UNUSED */ short selectmode, column; /* get editor data */ @@ -1147,7 +1147,7 @@ static int actkeys_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *even return OPERATOR_CANCELLED; /* get useful pointers from animation context data */ - ar= ac.ar; + /* ar= ac.ar; */ /* UNUSED */ /* select mode is either replace (deselect all, then add) or add/extend */ if (RNA_boolean_get(op->ptr, "extend")) diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index afab4ede229..e345caf1359 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -595,7 +595,7 @@ static void image_refresh(const bContext *C, ScrArea *UNUSED(sa)) tf = EM_get_active_mtface(em, NULL, NULL, 1); /* partially selected face is ok */ - if(tf && (tf->mode & TF_TEX)) { + if(tf) { /* don't need to check for pin here, see above */ sima->image= tf->tpage; diff --git a/source/blender/editors/space_logic/logic_ops.c b/source/blender/editors/space_logic/logic_ops.c index 60e9595b77a..b7f9af09348 100644 --- a/source/blender/editors/space_logic/logic_ops.c +++ b/source/blender/editors/space_logic/logic_ops.c @@ -43,6 +43,7 @@ #include "BKE_context.h" #include "BKE_main.h" #include "BKE_sca.h" +#include "BKE_material.h" //for texface convert #include "ED_logic.h" #include "ED_object.h" @@ -57,6 +58,11 @@ #include "logic_intern.h" +// temporary new includes for texface functions +#include "DNA_mesh_types.h" +#include "DNA_material_types.h" +#include "DNA_meshdata_types.h" + /* ************* Generic Operator Helpers ************* */ static int edit_sensor_poll(bContext *C) { @@ -687,6 +693,36 @@ static void LOGIC_OT_actuator_move(wmOperatorType *ot) RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Direction", "Move Up or Down"); } +/* ************* TexFace Converter Operator ************* */ +static int texface_convert_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Main *bmain= CTX_data_main(C); + do_version_tface(bmain, 0); + + return OPERATOR_FINISHED; +} + +static int texface_convert_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) +{ + return texface_convert_exec(C, op); +} + + static void LOGIC_OT_texface_convert(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "TexFace to Material Converter"; + ot->description = "Convert old texface settings into material. It may create new materials if needed"; + ot->idname= "LOGIC_OT_texface_convert"; + + /* api callbacks */ + ot->invoke= texface_convert_invoke; + ot->exec= texface_convert_exec; +// ot->poll= texface_convert_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + void ED_operatortypes_logic(void) { @@ -699,4 +735,5 @@ void ED_operatortypes_logic(void) WM_operatortype_append(LOGIC_OT_actuator_remove); WM_operatortype_append(LOGIC_OT_actuator_add); WM_operatortype_append(LOGIC_OT_actuator_move); + WM_operatortype_append(LOGIC_OT_texface_convert); } diff --git a/source/blender/editors/space_nla/nla_select.c b/source/blender/editors/space_nla/nla_select.c index 5ea7f357ecf..05d38a63109 100644 --- a/source/blender/editors/space_nla/nla_select.c +++ b/source/blender/editors/space_nla/nla_select.c @@ -606,8 +606,8 @@ static void mouse_nla_strips (bContext *C, bAnimContext *ac, const int mval[2], static int nlaedit_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *event) { bAnimContext ac; - Scene *scene; - ARegion *ar; + /* Scene *scene; */ /* UNUSED */ + /* ARegion *ar; */ /* UNUSED */ // View2D *v2d; /*UNUSED*/ short selectmode; @@ -616,8 +616,8 @@ static int nlaedit_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *even return OPERATOR_CANCELLED; /* get useful pointers from animation context data */ - scene= ac.scene; - ar= ac.ar; + /* scene= ac.scene; */ /* UNUSED */ + /* ar= ac.ar; */ /* UNUSED */ // v2d= &ar->v2d; /* select mode is either replace (deselect all, then add) or add/extend */ diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index cd521f7e8c7..f34cef4d2aa 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -179,6 +179,7 @@ static void node_socket_button_color(const bContext *C, uiBlock *block, /* ****************** BASE DRAW FUNCTIONS FOR NEW OPERATOR NODES ***************** */ +#if 0 /* UNUSED */ static void node_draw_socket_new(bNodeSocket *sock, float size) { float x=sock->locx, y=sock->locy; @@ -216,6 +217,7 @@ static void node_draw_socket_new(bNodeSocket *sock, float size) glDisable( GL_LINE_SMOOTH ); glDisable(GL_BLEND); } +#endif /* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */ @@ -894,14 +896,14 @@ static void node_browse_text_cb(bContext *C, void *ntree_v, void *node_v) Main *bmain= CTX_data_main(C); bNodeTree *ntree= ntree_v; bNode *node= node_v; - ID *oldid; + /* ID *oldid; */ /* UNUSED */ if(node->menunr<1) return; if(node->id) { node->id->us--; } - oldid= node->id; + /* oldid= node->id; */ /* UNUSED */ node->id= BLI_findlink(&bmain->text, node->menunr-1); id_us_plus(node->id); BLI_strncpy(node->name, node->id->name+2, sizeof(node->name)); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index a966caa4d70..7cb8351cd12 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -757,6 +757,8 @@ void ED_node_update_hierarchy(bContext *UNUSED(C), bNodeTree *ntree) /* ***************** generic operator functions for nodes ***************** */ +#if 0 /* UNUSED */ + static int edit_node_poll(bContext *C) { return ED_operator_node_active(C); @@ -815,6 +817,7 @@ static void edit_node_properties_get(wmOperator *op, bNodeTree *ntree, bNode **r if (rin_out) *rin_out = in_out; } +#endif /* ***************** Edit Group operator ************* */ @@ -902,7 +905,7 @@ static int node_group_socket_add_exec(bContext *C, wmOperator *op) char name[32]= ""; int type= SOCK_FLOAT; bNodeTree *ngroup= snode->edittree; - bNodeSocket *sock; + /* bNodeSocket *sock; */ /* UNUSED */ ED_preview_kill_jobs(C); @@ -918,7 +921,7 @@ static int node_group_socket_add_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* using placeholder subtype first */ - sock = node_group_add_socket(ngroup, name, type, in_out); + /* sock = */ /* UNUSED */ node_group_add_socket(ngroup, name, type, in_out); ntreeUpdateTree(ngroup); diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index ca9ecf2c328..e2b0b9c65d0 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -109,7 +109,7 @@ static int node_select_exec(bContext *C, wmOperator *op) ARegion *ar= CTX_wm_region(C); int mval[2]; short extend; - bNode *node= NULL; + /* bNode *node= NULL; */ /* UNUSED */ /* get settings from RNA properties for operator */ mval[0] = RNA_int_get(op->ptr, "mouse_x"); @@ -118,7 +118,7 @@ static int node_select_exec(bContext *C, wmOperator *op) extend = RNA_boolean_get(op->ptr, "extend"); /* perform the select */ - node= node_mouse_select(bmain, snode, ar, mval, extend); + /* node= */ /* UNUSED*/ node_mouse_select(bmain, snode, ar, mval, extend); /* send notifiers */ WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); diff --git a/source/blender/editors/space_node/node_state.c b/source/blender/editors/space_node/node_state.c index c4567bea648..13a5f3cb3dc 100644 --- a/source/blender/editors/space_node/node_state.c +++ b/source/blender/editors/space_node/node_state.c @@ -214,12 +214,11 @@ void NODE_OT_visibility_toggle(wmOperatorType *ot) static void snode_home(ScrArea *UNUSED(sa), ARegion *ar, SpaceNode* snode) { bNode *node; - rctf *cur, *tot; + rctf *cur; float oldwidth, oldheight, width, height; int first= 1; cur= &ar->v2d.cur; - tot= &ar->v2d.tot; oldwidth= cur->xmax - cur->xmin; oldheight= cur->ymax - cur->ymin; diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c index 68b2d3d586f..6bfe370d105 100644 --- a/source/blender/editors/space_outliner/outliner_edit.c +++ b/source/blender/editors/space_outliner/outliner_edit.c @@ -969,7 +969,7 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle ListBase hierarchy = {NULL, NULL}; LinkData *ld; TreeElement *tem, *temnext, *temsub; - TreeStoreElem *tse, *tsenext; + TreeStoreElem *tse /* , *tsenext */ /* UNUSED */; PointerRNA *ptr, *nextptr; PropertyRNA *prop; char *newpath=NULL; @@ -1018,7 +1018,7 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle char buf[128], *name; temnext= (TreeElement*)(ld->next->data); - tsenext= TREESTORE(temnext); + /* tsenext= TREESTORE(temnext); */ /* UNUSED */ nextptr= &temnext->rnaptr; name= RNA_struct_name_get_alloc(nextptr, buf, sizeof(buf)); diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c index 0a1f7a3599d..9fe0ed0543f 100644 --- a/source/blender/editors/space_outliner/outliner_tree.c +++ b/source/blender/editors/space_outliner/outliner_tree.c @@ -1151,7 +1151,7 @@ static int need_add_seq_dup(Sequence *seq) static void outliner_add_seq_dup(SpaceOops *soops, Sequence *seq, TreeElement *te, short index) { - TreeElement *ch; + /* TreeElement *ch; */ /* UNUSED */ Sequence *p; p= seq; @@ -1162,7 +1162,7 @@ static void outliner_add_seq_dup(SpaceOops *soops, Sequence *seq, TreeElement *t } if(!strcmp(p->strip->stripdata->name, seq->strip->stripdata->name)) - ch= outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index); + /* ch= */ /* UNUSED */ outliner_add_element(soops, &te->subtree, (void*)p, te, TSE_SEQUENCE, index); p= p->next; } } diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index da769184669..bd93a1270f6 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -1483,9 +1483,13 @@ static int sequencer_cut_exec(bContext *C, wmOperator *op) sort_seq(scene); } - WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); - - return OPERATOR_FINISHED; + if(changed) { + WM_event_add_notifier(C, NC_SCENE|ND_SEQUENCER, scene); + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } } diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 3d49bc7ffa0..685b15aed50 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -1291,7 +1291,7 @@ static void draw_documentation(SpaceText *st, ARegion *ar) TextLine *tmp; char *docs, buf[DOC_WIDTH+1], *p; int i, br, lines; - int boxw, boxh, l, x, y, top; + int boxw, boxh, l, x, y /* , top */ /* UNUSED */; if(!st || !st->text) return; if(!texttool_text_is_active(st->text)) return; @@ -1314,7 +1314,7 @@ static void draw_documentation(SpaceText *st, ARegion *ar) x += SUGG_LIST_WIDTH*st->cwidth + 50; } - top= y= ar->winy - st->lheight*l - 2; + /* top= */ /* UNUSED */ y= ar->winy - st->lheight*l - 2; boxw= DOC_WIDTH*st->cwidth + 20; boxh= (DOC_HEIGHT+1)*st->lheight; diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 6e02ecbd5a8..b6e76885719 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -64,6 +64,7 @@ #include "GPU_buffers.h" #include "GPU_extensions.h" #include "GPU_draw.h" +#include "GPU_material.h" #include "ED_mesh.h" @@ -207,44 +208,71 @@ static Material *give_current_material_or_def(Object *ob, int matnr) return ma?ma:&defmaterial; } -static int set_draw_settings_cached(int clearcache, int textured, MTFace *texface, int lit, Object *litob, int litmatnr, int doublesided) +/* Icky globals, fix with userdata parameter */ + +static struct TextureDrawState { + Object *ob; + int islit, istex; + int color_profile; + unsigned char obcol[4]; +} Gtexdraw = {NULL, 0, 0, 0, {0, 0, 0, 0}}; + +static int set_draw_settings_cached(int clearcache, MTFace *texface, Material *ma, struct TextureDrawState gtexdraw) { + static Material *c_ma; static int c_textured; - static int c_lit; - static int c_doublesided; static MTFace *c_texface; - static Object *c_litob; - static int c_litmatnr; + static int c_backculled; static int c_badtex; + static int c_lit; + Object *litob = NULL; //to get mode to turn off mipmap in painting mode + int backculled = 0; + int alphablend = 0; + int textured = 0; + int lit = 0; + if (clearcache) { - c_textured= c_lit= c_doublesided= -1; + c_textured= c_lit= c_backculled= -1; c_texface= (MTFace*) -1; - c_litob= (Object*) -1; - c_litmatnr= -1; c_badtex= 0; + } else { + textured = gtexdraw.istex; + litob = gtexdraw.ob; + } + + /* convert number of lights into boolean */ + if (gtexdraw.islit) lit = 1; + + if (ma) { + alphablend = ma->game.alpha_blend; + if (ma->mode & MA_SHLESS) lit = 0; + backculled = ma->game.flag & GEMAT_BACKCULL; } if (texface) { - lit = lit && (lit==-1 || texface->mode&TF_LIGHT); - textured = textured && (texface->mode&TF_TEX); - doublesided = texface->mode&TF_TWOSIDE; - } else { - textured = 0; + textured = textured && (texface->tpage); + + /* no material, render alpha if texture has depth=32 */ + if (!ma && BKE_image_has_alpha(texface->tpage)) + alphablend = GPU_BLEND_ALPHA; } - if (doublesided!=c_doublesided) { - if (doublesided) glDisable(GL_CULL_FACE); - else glEnable(GL_CULL_FACE); + else + textured = 0; + + if (backculled!=c_backculled) { + if (backculled) glEnable(GL_CULL_FACE); + else glDisable(GL_CULL_FACE); - c_doublesided= doublesided; + c_backculled= backculled; } if (textured!=c_textured || texface!=c_texface) { if (textured ) { - c_badtex= !GPU_set_tpage(texface, !(litob->mode & OB_MODE_TEXTURE_PAINT)); + c_badtex= !GPU_set_tpage(texface, !(litob->mode & OB_MODE_TEXTURE_PAINT), alphablend); } else { - GPU_set_tpage(NULL, 0); + GPU_set_tpage(NULL, 0, 0); c_badtex= 0; } c_textured= textured; @@ -252,10 +280,10 @@ static int set_draw_settings_cached(int clearcache, int textured, MTFace *texfac } if (c_badtex) lit= 0; - if (lit!=c_lit || litob!=c_litob || litmatnr!=c_litmatnr) { + if (lit!=c_lit || ma!=c_ma) { if (lit) { - Material *ma= give_current_material_or_def(litob, litmatnr+1); float spec[4]; + if (!ma)ma= give_current_material_or_def(NULL, 0); //default material spec[0]= ma->spec*ma->specr; spec[1]= ma->spec*ma->specg; @@ -273,22 +301,11 @@ static int set_draw_settings_cached(int clearcache, int textured, MTFace *texfac glDisable(GL_COLOR_MATERIAL); } c_lit= lit; - c_litob= litob; - c_litmatnr= litmatnr; } return c_badtex; } -/* Icky globals, fix with userdata parameter */ - -static struct TextureDrawState { - Object *ob; - int islit, istex; - int color_profile; - unsigned char obcol[4]; -} Gtexdraw = {NULL, 0, 0, 0, {0, 0, 0, 0}}; - static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob) { unsigned char obcol[4]; @@ -318,14 +335,14 @@ static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, O Gtexdraw.istex = istex; Gtexdraw.color_profile = scene->r.color_mgt_flag & R_COLOR_MANAGEMENT; memcpy(Gtexdraw.obcol, obcol, sizeof(obcol)); - set_draw_settings_cached(1, 0, NULL, Gtexdraw.islit, NULL, 0, 0); + set_draw_settings_cached(1, NULL, NULL, Gtexdraw); glShadeModel(GL_SMOOTH); } static void draw_textured_end(void) { /* switch off textures */ - GPU_set_tpage(NULL, 0); + GPU_set_tpage(NULL, 0, 0); glShadeModel(GL_FLAT); glDisable(GL_CULL_FACE); @@ -347,18 +364,22 @@ static void draw_textured_end(void) static int draw_tface__set_draw_legacy(MTFace *tface, MCol *mcol, int matnr) { - if (tface && (tface->mode&TF_INVISIBLE)) return 0; + Material *ma= give_current_material(Gtexdraw.ob, matnr+1); + int validtexture=0; + + if (ma && (ma->game.flag & GEMAT_INVISIBLE)) return 0; + + validtexture = set_draw_settings_cached(0, tface, ma, Gtexdraw); - if (tface && set_draw_settings_cached(0, Gtexdraw.istex, tface, Gtexdraw.islit, Gtexdraw.ob, matnr, TF_TWOSIDE)) { + if (tface && validtexture) { glColor3ub(0xFF, 0x00, 0xFF); return 2; /* Don't set color */ - } else if (tface && tface->mode&TF_OBCOL) { + } else if (ma && ma->shade_flag&MA_OBCOLOR) { glColor3ubv(Gtexdraw.obcol); return 2; /* Don't set color */ } else if (!mcol) { if (tface) glColor3f(1.0, 1.0, 1.0); else { - Material *ma= give_current_material(Gtexdraw.ob, matnr+1); if(ma) { float col[3]; if(Gtexdraw.color_profile) linearrgb_to_srgb_v3_v3(col, &ma->r); @@ -375,9 +396,11 @@ static int draw_tface__set_draw_legacy(MTFace *tface, MCol *mcol, int matnr) } static int draw_tface__set_draw(MTFace *tface, MCol *mcol, int matnr) { - if (tface && (tface->mode&TF_INVISIBLE)) return 0; + Material *ma= give_current_material(Gtexdraw.ob, matnr+1); + + if (ma && (ma->game.flag & GEMAT_INVISIBLE)) return 0; - if (tface && set_draw_settings_cached(0, Gtexdraw.istex, tface, Gtexdraw.islit, Gtexdraw.ob, matnr, TF_TWOSIDE)) { + if (tface && set_draw_settings_cached(0, tface, ma, Gtexdraw)) { return 2; /* Don't set color */ } else if (tface && tface->mode&TF_OBCOL) { return 2; /* Don't set color */ @@ -399,7 +422,9 @@ static void add_tface_color_layer(DerivedMesh *dm) finalCol = MEM_mallocN(sizeof(MCol)*4*dm->getNumFaces(dm),"add_tface_color_layer"); for(i=0;i<dm->getNumFaces(dm);i++) { - if (tface && (tface->mode&TF_INVISIBLE)) { + Material *ma= give_current_material(Gtexdraw.ob, mface[i].mat_nr+1); + + if (ma && (ma->game.flag&GEMAT_INVISIBLE)) { if( mcol ) memcpy(&finalCol[i*4],&mcol[i*4],sizeof(MCol)*4); else @@ -409,7 +434,7 @@ static void add_tface_color_layer(DerivedMesh *dm) finalCol[i*4+j].r = 255; } } - else if (tface && mface && set_draw_settings_cached(0, Gtexdraw.istex, tface, Gtexdraw.islit, Gtexdraw.ob, mface[i].mat_nr, TF_TWOSIDE)) { + else if (tface && mface && set_draw_settings_cached(0, tface, ma, Gtexdraw)) { for(j=0;j<4;j++) { finalCol[i*4+j].b = 255; finalCol[i*4+j].g = 0; @@ -494,10 +519,13 @@ static int wpaint__setSolidDrawOptions(void *userData, int index, int *drawSmoot { Mesh *me = (Mesh*)userData; - if ( (me->mface && me->mface[index].flag & ME_HIDE) || - (me->mtface && (me->mtface[index].mode & TF_INVISIBLE)) - ) { - return 0; + if (me->mface) { + short matnr= me->mface[index].mat_nr; + Material *ma= me->mat[matnr]; + + if (ma && (ma->game.flag & GEMAT_INVISIBLE)) { + return 0; + } } *drawSmooth_r = 1; @@ -523,17 +551,18 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl) if(ob->mode & OB_MODE_EDIT) return; else if(ob==OBACT) - if(paint_facesel_test(ob)) + if(paint_facesel_test(ob) || paint_vertsel_test(ob)) return; ddm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); for(a=0, mf=mface; a<totface; a++, tface++, mf++) { - int mode= tface->mode; - int matnr= mf->mat_nr; + short matnr= mf->mat_nr; int mf_smooth= mf->flag & ME_SMOOTH; + Material *mat = me->mat[matnr]; + int mode= mat->game.flag; - if (!(mf->flag&ME_HIDE) && !(mode&TF_INVISIBLE) && (mode&TF_BMFONT)) { + if (!(mode&GEMAT_INVISIBLE) && (mode&GEMAT_TEXT)) { float v1[3], v2[3], v3[3], v4[3]; char string[MAX_PROPSTRING]; int characters, i, glattrib= -1, badtex= 0; @@ -549,7 +578,7 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl) } } else { - badtex = set_draw_settings_cached(0, Gtexdraw.istex, tface, Gtexdraw.islit, Gtexdraw.ob, matnr, TF_TWOSIDE); + badtex = set_draw_settings_cached(0, tface, mat, Gtexdraw); if (badtex) { if (mcol) mcol+=4; continue; @@ -578,7 +607,7 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl) glNormal3fv(nor); } - GPU_render_text(tface, tface->mode, string, characters, + GPU_render_text(tface, mode, string, characters, (unsigned int*)mcol, v1, v2, v3, (mf->v4? v4: NULL), glattrib); } if (mcol) { diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 0e8e6cdfee1..44d68ded679 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -220,16 +220,13 @@ int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt) return (scene->gm.matmode == GAME_MAT_GLSL) && (dt > OB_SOLID); } -static int check_material_alpha(Base *base, Mesh *me, int glsl) +static int check_material_alpha(Base *base, int glsl) { if(base->flag & OB_FROMDUPLI) return 0; if(G.f & G_PICKSEL) return 0; - - if(me->edit_mesh) - return 0; return (glsl || (base->object->dtx & OB_DRAWTRANSP)); } @@ -1740,6 +1737,31 @@ void mesh_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, EditVe dm->release(dm); } +/* draw callback */ +static void drawSelectedVertices__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) +{ + MVert *mv = &((MVert *)userData)[index]; + + if(!(mv->flag & ME_HIDE)) { + const char sel= mv->flag & SELECT; + + // TODO define selected color + if(sel) { + glColor3f(1.0f, 1.0f, 0.0f); + } + else { + glColor3f(0.0f, 0.0f, 0.0f); + } + + glVertex3fv(co); + } +} + +static void drawSelectedVertices(DerivedMesh *dm, Mesh *me) { + glBegin(GL_POINTS); + dm->foreachMappedVert(dm, drawSelectedVertices__mapFunc, me->mvert); + glEnd(); +} static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0co, float *v1co) { struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData; @@ -2924,7 +2946,16 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D bglPolygonOffset(rv3d->dist, 0.0); } } - + + if(paint_vertsel_test(ob)) { + + glColor3f(0.0f, 0.0f, 0.0f); + glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE)); + + drawSelectedVertices(dm, ob->data); + + glPointSize(1.0f); + } dm->release(dm); } @@ -2964,12 +2995,16 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D scene->customdata_mask); if(dt>OB_WIRE) { - // no transp in editmode, the fancy draw over goes bad then glsl = draw_glsl_material(scene, ob, v3d, dt); - GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL); + check_alpha = check_material_alpha(base, glsl); + + GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, + (check_alpha)? &do_alpha_pass: NULL); } - draw_em_fancy(scene, v3d, rv3d, ob, em, cageDM, finalDM, dt); + // transp in editmode makes the fancy draw over go bad + if (!do_alpha_pass) + draw_em_fancy(scene, v3d, rv3d, ob, em, cageDM, finalDM, dt); GPU_end_object_materials(); @@ -2980,7 +3015,7 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D /* don't create boundbox here with mesh_get_bb(), the derived system will make it, puts deformed bb's OK */ if(me->totface<=4 || ED_view3d_boundbox_clip(rv3d, ob->obmat, (ob->bb)? ob->bb: me->bb)) { glsl = draw_glsl_material(scene, ob, v3d, dt); - check_alpha = check_material_alpha(base, me, glsl); + check_alpha = check_material_alpha(base, glsl); if(dt==OB_SOLID || glsl) { GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, @@ -4022,7 +4057,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv if(draw_as==PART_DRAW_PATH){ ParticleCacheKey **cache, *path; - float *cd2=NULL,*cdata2=NULL; + float /* *cd2=NULL, */ /* UNUSED */ *cdata2=NULL; /* setup gl flags */ if (1) { //ob_dt > OB_WIRE) { @@ -4090,7 +4125,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv if(cdata2) MEM_freeN(cdata2); - cd2=cdata2=NULL; + /* cd2= */ /* UNUSED */ cdata2=NULL; glLineWidth(1.0f); @@ -6516,6 +6551,32 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) /* ***************** BACKBUF SEL (BBS) ********* */ +static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) +{ + struct {void* offset; MVert *mvert;} *data = userData; + MVert *mv = &data->mvert[index]; + int offset = (intptr_t) data->offset; + + if (!(mv->flag & ME_HIDE)) { + WM_set_framebuffer_index_color(offset+index); + bglVertex3fv(co); + } +} + +static void bbs_obmode_mesh_verts(Object *ob, DerivedMesh *dm, int offset) +{ + struct {void* offset; struct MVert *mvert;} data; + Mesh *me = ob->data; + MVert *mvert = me->mvert; + data.mvert = mvert; + data.offset = (void*)(intptr_t) offset; + glPointSize( UI_GetThemeValuef(TH_VERTEX_SIZE) ); + bglBegin(GL_POINTS); + dm->foreachMappedVert(dm, bbs_obmode_mesh_verts__mapFunc, &data); + bglEnd(); + glPointSize(1.0); +} + static void bbs_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { int offset = (intptr_t) userData; @@ -6614,6 +6675,17 @@ static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index, int *UNUS } } +// must have called WM_set_framebuffer_index_color beforehand +static int bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index, int *UNUSED(drawSmooth_r)) +{ + Mesh *me = userData; + + if (!(me->mface[index].flag & ME_HIDE)) { + return 1; + } else { + return 0; + } +} static void bbs_mesh_solid(Scene *scene, Object *ob) { DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask); @@ -6672,7 +6744,21 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec EM_free_index_arrays(); } else { - bbs_mesh_solid(scene, ob); + Mesh *me= ob->data; + if(me->editflag & ME_EDIT_VERT_SEL) { + DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask); + glColor3ub(0, 0, 0); + + dm->drawMappedFaces(dm, bbs_mesh_solid_hide2__setDrawOpts, me, 0, GPU_enable_material, NULL); + + + bbs_obmode_mesh_verts(ob, dm, 1); + em_vertoffs = me->totvert+1; + dm->release(dm); + } + else { + bbs_mesh_solid(scene, ob); + } } break; case OB_CURVE: diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index 8da6f49e089..e87ace19edb 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -183,7 +183,7 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3 float viewnormal[3]; int i, j, n, good_index; - float d, d0, dd, ds; + float d /*, d0 */ /* UNUSED */, dd, ds; float *points = NULL; int numpoints = 0; float cor[3] = {1.,1.,1.}; @@ -390,7 +390,8 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3 // (a,b,c), the plane normal, are given by viewdir // d is the parameter along the view direction. the first d is given by // inserting previously found vertex into the plane equation - d0 = (viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]); + + /* d0 = (viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]); */ /* UNUSED */ ds = (ABS(viewnormal[0])*size[0] + ABS(viewnormal[1])*size[1] + ABS(viewnormal[2])*size[2]); dd = 0.05; // ds/512.0f; n = 0; diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 6833dec2e43..c46b6b6d70b 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -371,6 +371,10 @@ static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar) keymap= WM_keymap_find(wm->defaultconf, "Face Mask", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); + + keymap= WM_keymap_find(wm->defaultconf, "Weight Paint Vertex Selection", 0, 0); + WM_event_add_keymap_handler(&ar->handlers, keymap); + /* pose is not modal, operator poll checks for this */ keymap= WM_keymap_find(wm->defaultconf, "Pose", 0, 0); WM_event_add_keymap_handler(&ar->handlers, keymap); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 2f2e2c5c282..0854f9f3685 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -2786,7 +2786,7 @@ void VIEW3D_OT_viewnumpad(wmOperatorType *ot) ot->flag= 0; RNA_def_enum(ot->srna, "type", prop_view_items, 0, "View", "The Type of view"); - RNA_def_boolean(ot->srna, "align_active", 0, "Align Active", "Align to the active objects axis"); + RNA_def_boolean(ot->srna, "align_active", 0, "Align Active", "Align to the active object's axis"); } static EnumPropertyItem prop_view_orbit_items[] = { diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 55b30aec804..0776ca752a9 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -516,7 +516,15 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) PointerRNA meshptr; RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr); - uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + if(ob->mode & (OB_MODE_TEXTURE_PAINT|OB_MODE_VERTEX_PAINT)) { + uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + } + else { + + row= uiLayoutRow(layout, 1); + uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE); + } } else { const char *str_menu; diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 36ae6b65038..1c98397c7f6 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -54,6 +54,11 @@ #include "BLI_linklist.h" #include "BLI_utildefines.h" +/* vertex box select */ +#include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" +#include "BKE_global.h" + #include "BKE_context.h" #include "BKE_paint.h" #include "BKE_armature.h" @@ -198,6 +203,24 @@ static void EM_backbuf_checkAndSelectFaces(EditMesh *em, int select) } } + +/* object mode, EM_ prefix is confusing here, rename? */ +static void EM_backbuf_checkAndSelectVerts_obmode(Mesh *me, int select) +{ + MVert *mv = me->mvert; + int a; + + if (mv) { + for(a=1; a<=me->totvert; a++, mv++) { + if(EM_check_backbuf(a)) { + if(!(mv->flag & ME_HIDE)) { + mv->flag = select?(mv->flag|SELECT):(mv->flag&~SELECT); + } + } + } + } +} +/* object mode, EM_ prefix is confusing here, rename? */ static void EM_backbuf_checkAndSelectTFaces(Mesh *me, int select) { MFace *mface = me->mface; @@ -231,7 +254,7 @@ static int view3d_selectable_data(bContext *C) if (ob->mode & OB_MODE_SCULPT) { return 0; } - if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT) && !paint_facesel_test(ob)) { + if (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT) && !paint_facesel_test(ob) && !paint_vertsel_test(ob)) { return 0; } } @@ -727,6 +750,88 @@ static void do_lasso_select_meta(ViewContext *vc, int mcords[][2], short moves, } } +int do_paintvert_box_select(ViewContext *vc, rcti *rect, int select, int extend) +{ + Mesh *me; + MVert *mvert; + struct ImBuf *ibuf; + unsigned int *rt; + int a, index; + char *selar; + int sx= rect->xmax-rect->xmin+1; + int sy= rect->ymax-rect->ymin+1; + + me= vc->obact->data; + + if(me==NULL || me->totvert==0 || sx*sy <= 0) + return OPERATOR_CANCELLED; + + selar= MEM_callocN(me->totvert+1, "selar"); + + if (extend == 0 && select) + paintvert_deselect_all_visible(vc->obact, SEL_DESELECT, FALSE); + + view3d_validate_backbuf(vc); + + ibuf = IMB_allocImBuf(sx,sy,32,IB_rect); + rt = ibuf->rect; + glReadPixels(rect->xmin+vc->ar->winrct.xmin, rect->ymin+vc->ar->winrct.ymin, sx, sy, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); + if(ENDIAN_ORDER==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf); + + a= sx*sy; + while(a--) { + if(*rt) { + index= WM_framebuffer_to_index(*rt); + if(index<=me->totvert) selar[index]= 1; + } + rt++; + } + + mvert= me->mvert; + for(a=1; a<=me->totvert; a++, mvert++) { + if(selar[a]) { + if(mvert->flag & ME_HIDE); + else { + if(select) mvert->flag |= SELECT; + else mvert->flag &= ~SELECT; + } + } + } + + IMB_freeImBuf(ibuf); + MEM_freeN(selar); + +#ifdef __APPLE__ + glReadBuffer(GL_BACK); +#endif + + paintvert_flush_flags(vc->obact); + + return OPERATOR_FINISHED; +} + +static void do_lasso_select_paintvert(ViewContext *vc, int mcords[][2], short moves, short extend, short select) +{ + Object *ob= vc->obact; + Mesh *me= ob?ob->data:NULL; + rcti rect; + + if(me==NULL || me->totvert==0) + return; + + if(extend==0 && select) + paintvert_deselect_all_visible(ob, SEL_DESELECT, FALSE); /* flush selection at the end */ + em_vertoffs= me->totvert+1; /* max index array */ + + lasso_select_boundbox(&rect, mcords, moves); + EM_mask_init_backbuf_border(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax); + + EM_backbuf_checkAndSelectVerts_obmode(me, select); + + EM_free_backbuf(); + + paintvert_flush_flags(ob); +} static void do_lasso_select_paintface(ViewContext *vc, int mcords[][2], short moves, short extend, short select) { Object *ob= vc->obact; @@ -789,6 +894,8 @@ static void view3d_lasso_select(bContext *C, ViewContext *vc, int mcords[][2], s if(vc->obedit==NULL) { /* Object Mode */ if(paint_facesel_test(ob)) do_lasso_select_paintface(vc, mcords, moves, extend, select); + else if(paint_vertsel_test(ob)) + do_lasso_select_paintvert(vc, mcords, moves, extend, select); else if(ob && ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)) ; else if(ob && ob->mode & OB_MODE_PARTICLE_EDIT) @@ -1798,6 +1905,9 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op) else if(vc.obact && paint_facesel_test(vc.obact)) { ret= do_paintface_box_select(&vc, &rect, select, extend); } + else if(vc.obact && paint_vertsel_test(vc.obact)) { + ret= do_paintvert_box_select(&vc, &rect, select, extend); + } else if(vc.obact && vc.obact->mode & OB_MODE_PARTICLE_EDIT) { ret= PE_border_select(C, &rect, select, extend); } @@ -1834,6 +1944,58 @@ void VIEW3D_OT_select_border(wmOperatorType *ot) WM_operator_properties_gesture_border(ot, TRUE); } +/* much like facesel_face_pick()*/ +/* returns 0 if not found, otherwise 1 */ +static int vertsel_vert_pick(struct bContext *C, Mesh *me, const int mval[2], unsigned int *index, short rect) +{ + ViewContext vc; + view3d_set_viewcontext(C, &vc); + + if (!me || me->totvert==0) + return 0; + + if (rect) { + /* sample rect to increase changes of selecting, so that when clicking + on an face in the backbuf, we can still select a vert */ + + int dist; + *index = view3d_sample_backbuf_rect(&vc, mval, 3, 1, me->totvert+1, &dist,0,NULL, NULL); + } + else { + /* sample only on the exact position */ + *index = view3d_sample_backbuf(&vc, mval[0], mval[1]); + } + + if ((*index)<=0 || (*index)>(unsigned int)me->totvert) + return 0; + + (*index)--; + + return 1; +} + +/* mouse selection in weight paint */ +/* gets called via generic mouse select operator */ +static int mouse_weight_paint_vertex_select(bContext *C, const int mval[2], short extend, Object *obact) +{ + Mesh* me= obact->data; /* already checked for NULL */ + unsigned int index = 0; + MVert *mv; + if(vertsel_vert_pick(C, me, mval, &index, 1)) { + mv = me->mvert+index; + if(extend) { + mv->flag ^= SELECT; + } else { + paintvert_deselect_all_visible(obact, SEL_DESELECT, FALSE); + mv->flag |= SELECT; + } + paintvert_flush_flags(obact); + WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); + return 1; + } + return 0; +} + /* ****** Mouse Select ****** */ @@ -1878,6 +2040,8 @@ static int view3d_select_invoke(bContext *C, wmOperator *op, wmEvent *event) return PE_mouse_particles(C, event->mval, extend); else if(obact && paint_facesel_test(obact)) retval = paintface_mouse_select(C, obact, event->mval, extend); + else if (paint_vertsel_test(obact)) + retval = mouse_weight_paint_vertex_select(C, event->mval, extend, obact); else retval = mouse_select(C, event->mval, extend, center, enumerate); @@ -1992,18 +2156,36 @@ static void paint_facesel_circle_select(ViewContext *vc, int select, const int m { Object *ob= vc->obact; Mesh *me = ob?ob->data:NULL; - int bbsel; + /* int bbsel; */ /* UNUSED */ if (me) { em_vertoffs= me->totface+1; /* max index array */ - bbsel= EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0f)); + /* bbsel= */ /* UNUSED */ EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0f)); EM_backbuf_checkAndSelectTFaces(me, select==LEFTMOUSE); EM_free_backbuf(); } } +static void paint_vertsel_circle_select(ViewContext *vc, int select, const int mval[2], float rad) +{ + Object *ob= vc->obact; + Mesh *me = ob?ob->data:NULL; + /* int bbsel; */ /* UNUSED */ + /* struct {ViewContext *vc; short select; int mval[2]; float radius; } data = {NULL}; */ /* UNUSED */ + if (me) { + em_vertoffs= me->totvert+1; /* max index array */ + + /* bbsel= */ /* UNUSED */ EM_init_backbuf_circle(vc, mval[0], mval[1], (short)(rad+1.0f)); + EM_backbuf_checkAndSelectVerts_obmode(me, select==LEFTMOUSE); + EM_free_backbuf(); + + paintvert_flush_flags(ob); + } +} + + static void nurbscurve_circle_doSelect(void *userData, Nurb *UNUSED(nu), BPoint *bp, BezTriple *bezt, int beztindex, int x, int y) { struct {ViewContext *vc; short select; int mval[2]; float radius; } *data = userData; @@ -2258,7 +2440,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) select= (gesture_mode==GESTURE_MODAL_SELECT); - if( CTX_data_edit_object(C) || paint_facesel_test(obact) || + if( CTX_data_edit_object(C) || paint_facesel_test(obact) || paint_vertsel_test(obact) || (obact && (obact->mode & (OB_MODE_PARTICLE_EDIT|OB_MODE_POSE))) ) { ViewContext vc; @@ -2278,6 +2460,10 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) paint_facesel_circle_select(&vc, select, mval, (float)radius); WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); } + else if(paint_vertsel_test(obact)) { + paint_vertsel_circle_select(&vc, select, mval, (float)radius); + WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obact->data); + } else if(obact->mode & OB_MODE_POSE) pose_circle_select(&vc, select, mval, (float)radius); else diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 45d832d4739..8227ba87021 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -1667,7 +1667,7 @@ static void RestoreState(bContext *C, wmWindow *win) win->queue= queue_back; GPU_state_init(); - GPU_set_tpage(NULL, 0); + GPU_set_tpage(NULL, 0, 0); glPopAttrib(); } diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index c8b95727304..f6b4f32adef 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -4260,7 +4260,6 @@ static int createSlideVerts(TransInfo *t) LinkNode *edgelist = NULL, *vertlist=NULL, *look; GHash *vertgh; TransDataSlideVert *tempsv; - float vertdist; // XXX, projectMat[4][4]; int i, j, numsel, numadded=0, timesthrough = 0, vertsel=0; /* UV correction vars */ GHash **uvarray= NULL; @@ -4525,7 +4524,6 @@ static int createSlideVerts(TransInfo *t) look = vertlist; nearest = NULL; - vertdist = -1; while(look) { tempsv = BLI_ghash_lookup(vertgh,(EditVert*)look->link); @@ -5563,7 +5561,7 @@ static void applyTimeTranslate(TransInfo *t, float UNUSED(sval)) const short autosnap= getAnimEdit_SnapMode(t); - float deltax, val, valprev; + float deltax, val /* , valprev */; /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */ for (i = 0 ; i < t->total; i++, td++, td2d++) { @@ -5573,7 +5571,7 @@ static void applyTimeTranslate(TransInfo *t, float UNUSED(sval)) */ AnimData *adt= (t->spacetype != SPACE_NLA) ? td->extra : NULL; - valprev = *td->val; + /* valprev = *td->val; */ /* UNUSED */ /* check if any need to apply nla-mapping */ if (adt && t->spacetype != SPACE_SEQ) { diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index d76e5c8a88a..77d2e6e7ff0 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -1983,7 +1983,7 @@ static void createTransEditVerts(bContext *C, TransInfo *t) float *mappedcos = NULL, *quats= NULL; float mtx[3][3], smtx[3][3], (*defmats)[3][3] = NULL, (*defcos)[3] = NULL; int count=0, countsel=0, a, totleft; - int propmode = t->flag & T_PROP_EDIT; + int propmode = (t->flag & T_PROP_EDIT) ? (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) : 0; int mirror = 0; short selectmode = ts->selectmode; @@ -2053,7 +2053,9 @@ static void createTransEditVerts(bContext *C, TransInfo *t) copy_m3_m4(mtx, t->obedit->obmat); invert_m3_m3(smtx, mtx); - if(propmode) editmesh_set_connectivity_distance(em, mtx); + if(propmode & T_PROP_CONNECTED) { + editmesh_set_connectivity_distance(em, mtx); + } /* detect CrazySpace [tm] */ if(modifiers_getCageIndex(t->scene, t->obedit, NULL, 1)>=0) { @@ -3406,7 +3408,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) const char sel3= use_handle ? bezt->f3 & SELECT : 0; TransDataCurveHandleFlags *hdata = NULL; - short h1=1, h2=1; + /* short h1=1, h2=1; */ /* UNUSED */ /* only include handles if selected, irrespective of the interpolation modes. * also, only treat handles specially if the center point isn't selected. @@ -3416,16 +3418,18 @@ static void createTransGraphEditData(bContext *C, TransInfo *t) hdata = initTransDataCurveHandles(td, bezt); bezt_to_transdata(td++, td2d++, adt, bezt, 0, 1, 1, intvals, mtx, smtx); } - else - h1= 0; + else { + /* h1= 0; */ /* UNUSED */ + } if (sel3) { if (hdata==NULL) hdata = initTransDataCurveHandles(td, bezt); bezt_to_transdata(td++, td2d++, adt, bezt, 2, 1, 1, intvals, mtx, smtx); } - else - h2= 0; + else { + /* h2= 0; */ /* UNUSED */ + } } /* only include main vert if selected */ diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index 3b895f5fbd0..36373562956 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -446,13 +446,13 @@ int calc_manipulator_stats(const bContext *C) } else if(obedit->type==OB_MBALL) { MetaBall *mb = (MetaBall*)obedit->data; - MetaElem *ml, *ml_sel=NULL; + MetaElem *ml /* , *ml_sel=NULL */ /* UNUSED */; ml= mb->editelems->first; while(ml) { if(ml->flag & SELECT) { calc_tw_center(scene, &ml->x); - ml_sel = ml; + /* ml_sel = ml; */ /* UNUSED */ totsel++; } ml= ml->next; diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 3489bf41143..d6e8e4aa695 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -795,7 +795,7 @@ void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot) ot->cancel = transform_cancel; ot->poll = ED_operator_sequencer_active; - RNA_def_float_vector(ot->srna, "value", 2, VecOne, -FLT_MAX, FLT_MAX, "angle", "", -FLT_MAX, FLT_MAX); + RNA_def_float_vector(ot->srna, "value", 2, VecOne, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX); Transform_Properties(ot, P_SNAP); } diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 9a21305457c..61b3a9ca1ca 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -125,14 +125,12 @@ void ED_uvedit_assign_image(Scene *scene, Object *obedit, Image *ima, Image *pre if(uvedit_face_visible(scene, previma, efa, tf)) { if(ima) { tf->tpage= ima; - tf->mode |= TF_TEX; if(ima->id.us==0) id_us_plus(&ima->id); else id_lib_extern(&ima->id); } else { tf->tpage= NULL; - tf->mode &= ~TF_TEX; } update = 1; @@ -2519,7 +2517,7 @@ static void UV_OT_snap_cursor(wmOperatorType *ot) ot->poll= ED_operator_image_active; /* requires space image */; /* properties */ - RNA_def_enum(ot->srna, "target", target_items, 0, "Target", "Target to snap the selected UV's to"); + RNA_def_enum(ot->srna, "target", target_items, 0, "Target", "Target to snap the selected UVs to"); } /* ******************** snap selection operator **************** */ @@ -2761,7 +2759,7 @@ static void UV_OT_snap_selected(wmOperatorType *ot) ot->poll= ED_operator_image_active; /* requires space image */; /* properties */ - RNA_def_enum(ot->srna, "target", target_items, 0, "Target", "Target to snap the selected UV's to"); + RNA_def_enum(ot->srna, "target", target_items, 0, "Target", "Target to snap the selected UVs to"); } /* ******************** pin operator **************** */ |