diff options
author | Ton Roosendaal <ton@blender.org> | 2006-09-03 16:16:14 +0400 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2006-09-03 16:16:14 +0400 |
commit | 4603f452c23f0711e18fb7f652abad529f94c203 (patch) | |
tree | 17d42fe5337adb1e269f3d8eaa26237511383760 | |
parent | 7970da34edbfba8b317fff23fb276e78bf67e460 (diff) |
Animation department feature request: support for vertex groups in Lattices
In a quick glance: (temp image)
http://www.blender.org/bf/rt.png
Main reason is that Lattices are useful a lot for Armature deformation.
Lattices just provide much more precise and interesting control. However,
with only bone envelopes it's very hard to use.
Working with Lattice vertex groups is nearly identical to Mesh:
- on CTRL+P 'make parent' you can choose the deform option now
- In editmode, the buttons to control vertex groups are available
- In outliner you can select vertexgroups too
- Deforming Lattices with Armatures has all options as for Mesh now.
Note:
- No WeightPaint has been added yet. To compensate, the editmode
drawing for a Lattice with vertex group shows weight values for the active
vertex group.
- Lattice editmode doesn't undo/redo weight editing yet.
- Softbody for Lattice still uses own vertex weights
Implementation notes:
- derivedmesh weight_to_rgb() is now exported to drawobject.c
- been doing cleanups in code (order of includes, var declarations, etc)
- weightpaint button handling now is generic
I've checked on Brecht's proposal for Custom Element data;
http://mediawiki.blender.org/index.php/BlenderDev/CustomElementData
It could have been used, but that would mean the existing code for
vertexgroup handling and armature deform couldn't be re-used. I guess this
is really a later todo.
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 38 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 14 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/softbody.c | 25 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 52 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 48 | ||||
-rw-r--r-- | source/blender/include/BIF_editdeform.h | 4 | ||||
-rw-r--r-- | source/blender/include/butspace.h | 53 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_lattice_types.h | 3 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Mesh.c | 2 | ||||
-rw-r--r-- | source/blender/python/api2_2x/NMesh.c | 6 | ||||
-rw-r--r-- | source/blender/src/butspace.c | 3 | ||||
-rw-r--r-- | source/blender/src/buttons_editing.c | 138 | ||||
-rw-r--r-- | source/blender/src/drawobject.c | 43 | ||||
-rw-r--r-- | source/blender/src/editarmature.c | 2 | ||||
-rw-r--r-- | source/blender/src/editdeform.c | 257 | ||||
-rw-r--r-- | source/blender/src/editlattice.c | 27 | ||||
-rw-r--r-- | source/blender/src/editobject.c | 8 | ||||
-rw-r--r-- | source/blender/src/vpaint.c | 2 |
20 files changed, 451 insertions, 278 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index fe371c32529..fdba213ce6e 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -402,5 +402,7 @@ DerivedMesh *editmesh_get_derived_base(void); DerivedMesh *editmesh_get_derived_cage(int *needsFree_r); DerivedMesh *editmesh_get_derived_cage_and_final(DerivedMesh **final_r, int *cageNeedsFree_r, int *finalNeedsFree_r); +void weight_to_rgb(float input, float *fr, float *fg, float *fb); + #endif diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index cb1ecffd2da..f0737a4a404 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -3128,7 +3128,7 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r, DerivedMesh **final_r) * happens on enter/exit wpaint. */ -static void weight_to_rgb(float input, float *fr, float *fg, float *fb) +void weight_to_rgb(float input, float *fr, float *fg, float *fb) { float blend; diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index cab7bf30908..8d86a3d6ad9 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -37,29 +37,30 @@ #include "BLI_arithb.h" #include "BLI_blenlib.h" -#include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" #include "DNA_armature_types.h" #include "DNA_action_types.h" +#include "DNA_constraint_types.h" +#include "DNA_mesh_types.h" +#include "DNA_lattice_types.h" +#include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_view3d_types.h" -#include "DNA_constraint_types.h" +#include "BKE_armature.h" +#include "BKE_action.h" +#include "BKE_blender.h" +#include "BKE_constraint.h" #include "BKE_curve.h" +#include "BKE_deform.h" #include "BKE_depsgraph.h" #include "BKE_DerivedMesh.h" #include "BKE_displist.h" #include "BKE_global.h" -#include "BKE_main.h" #include "BKE_library.h" -#include "BKE_blender.h" -#include "BKE_armature.h" -#include "BKE_action.h" -#include "BKE_constraint.h" +#include "BKE_main.h" #include "BKE_object.h" #include "BKE_object.h" -#include "BKE_deform.h" #include "BKE_utildefines.h" #include "BIF_editdeform.h" @@ -670,8 +671,8 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, MDeformVert *dverts = NULL; float obinv[4][4], premat[4][4], postmat[4][4]; int use_envelope = deformflag & ARM_DEF_ENVELOPE; - int numGroups = 0; /* safety for vertexgroup index overflow too */ - int i; + int numGroups = 0; /* safety for vertexgroup index overflow */ + int i, target_totvert = 0; /* safety for vertexgroup overflow */ int use_dverts = 0; int armature_def_nr = -1; bDeformGroup *dg; @@ -700,10 +701,19 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, /* get a vertex-deform-index to posechannel array */ if(deformflag & ARM_DEF_VGROUP) { - if(target->type == OB_MESH){ + if(ELEM(target->type, OB_MESH, OB_LATTICE)) { numGroups = BLI_countlist(&target->defbase); - dverts = ((Mesh*)target->data)->dvert; + if(target->type==OB_MESH) { + Mesh *me= target->data; + dverts = me->dvert; + target_totvert = me->totvert; + } + else { + Lattice *lt= target->data; + dverts = lt->dvert; + target_totvert = lt->pntsu*lt->pntsv*lt->pntsw; + } /* if we have a DerivedMesh, only use dverts if it has them */ if(dm) if(dm->getVertData(dm, 0, LAYERTYPE_MDEFORMVERT)) @@ -742,7 +752,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, if(use_dverts || armature_def_nr >= 0) { if(dm) dvert = dm->getVertData(dm, i, LAYERTYPE_MDEFORMVERT); - else if(i < ((Mesh*)target->data)->totvert) dvert = dverts + i; + else if(i < target_totvert) dvert = dverts + i; } else dvert = NULL; diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 768fedd86ea..fe28d0f3150 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -65,6 +65,7 @@ #include "BKE_lattice.h" #include "BKE_library.h" #include "BKE_main.h" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_object.h" #include "BKE_screen.h" @@ -106,6 +107,12 @@ void resizelattice(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb) float fu, fv, fw, uc, vc, wc, du=0.0, dv=0.0, dw=0.0; float *co, (*vertexCos)[3] = NULL; + /* vertex weight groups are just freed all for now */ + if(lt->dvert) { + free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); + lt->dvert= NULL; + } + while(uNew*vNew*wNew > 32000) { if( uNew>=vNew && uNew>=wNew) uNew--; else if( vNew>=uNew && vNew>=wNew) vNew--; @@ -222,12 +229,19 @@ Lattice *copy_lattice(Lattice *lt) ltn->key= copy_key(ltn->key); if(ltn->key) ltn->key->from= (ID *)ltn; + if(lt->dvert) { + int tot= lt->pntsu*lt->pntsv*lt->pntsw; + ltn->dvert = MEM_mallocN (sizeof (MDeformVert)*tot, "Lattice MDeformVert"); + copy_dverts(ltn->dvert, lt->dvert, tot); + } + return ltn; } void free_lattice(Lattice *lt) { if(lt->def) MEM_freeN(lt->def); + if(lt->dvert) free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); } diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 79418ed92eb..bdc9b2342ee 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -1218,19 +1218,26 @@ static void get_scalar_from_vertexgroup(Object *ob, int vertID, short groupindex -- and yes this function must not be here but in a *vertex group module* */ { - MDeformVert *dv; + MDeformVert *dv= NULL; int i; /* spot the vert in deform vert list at mesh */ if(ob->type==OB_MESH) { - if (((Mesh *)ob->data)->dvert) { - dv = ((Mesh*)ob->data)->dvert + vertID; - /* Lets see if this vert is in the weight group */ - for (i=0; i<dv->totweight; i++){ - if (dv->dw[i].def_nr == groupindex){ - *target= dv->dw[i].weight; /* got it ! */ - break; - } + Mesh *me= ob->data; + if (me->dvert) + dv = me->dvert + vertID; + } + else if(ob->type==OB_LATTICE) { /* not yet supported in softbody btw */ + Lattice *lt= ob->data; + if (lt->dvert) + dv = lt->dvert + vertID; + } + if(dv) { + /* Lets see if this vert is in the weight group */ + for (i=0; i<dv->totweight; i++){ + if (dv->dw[i].def_nr == groupindex){ + *target= dv->dw[i].weight; /* got it ! */ + break; } } } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 6176d01e967..09b040be731 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1652,30 +1652,6 @@ static void direct_link_camera(FileData *fd, Camera *ca) } -/* ************ READ LATTICE ***************** */ - -static void lib_link_latt(FileData *fd, Main *main) -{ - Lattice *lt; - - lt= main->latt.first; - while(lt) { - if(lt->id.flag & LIB_NEEDLINK) { - - lt->ipo= newlibadr_us(fd, lt->id.lib, lt->ipo); - lt->key= newlibadr_us(fd, lt->id.lib, lt->key); - - lt->id.flag -= LIB_NEEDLINK; - } - lt= lt->id.next; - } -} - -static void direct_link_latt(FileData *fd, Lattice *lt) -{ - lt->def= newdataadr(fd, lt->def); -} - /* ************ READ LAMP ***************** */ static void lib_link_lamp(FileData *fd, Main *main) @@ -2288,6 +2264,34 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh) } } +/* ************ READ LATTICE ***************** */ + +static void lib_link_latt(FileData *fd, Main *main) +{ + Lattice *lt; + + lt= main->latt.first; + while(lt) { + if(lt->id.flag & LIB_NEEDLINK) { + + lt->ipo= newlibadr_us(fd, lt->id.lib, lt->ipo); + lt->key= newlibadr_us(fd, lt->id.lib, lt->key); + + lt->id.flag -= LIB_NEEDLINK; + } + lt= lt->id.next; + } +} + +static void direct_link_latt(FileData *fd, Lattice *lt) +{ + lt->def= newdataadr(fd, lt->def); + + lt->dvert= newdataadr(fd, lt->dvert); + direct_link_dverts(fd, lt->pntsu*lt->pntsv*lt->pntsw, lt->dvert); +} + + /* ************ READ OBJECT ***************** */ static void lib_link_modifiers__linkModifiers(void *userData, Object *ob, diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 7156b6ffcab..38b58d8794f 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -977,13 +977,13 @@ static void write_curves(WriteData *wd, ListBase *idbase) static void write_dverts(WriteData *wd, int count, MDeformVert *dvlist) { - int i; - - /* Write the dvert list */ - writestruct(wd, DATA, "MDeformVert", count, dvlist); - - /* Write deformation data for each dvert */ if (dvlist) { + int i; + + /* Write the dvert list */ + writestruct(wd, DATA, "MDeformVert", count, dvlist); + + /* Write deformation data for each dvert */ for (i=0; i<count; i++) { if (dvlist[i].dw) writestruct(wd, DATA, "MDeformWeight", dvlist[i].totweight, dvlist[i].dw); @@ -1030,6 +1030,26 @@ static void write_meshs(WriteData *wd, ListBase *idbase) } } +static void write_lattices(WriteData *wd, ListBase *idbase) +{ + Lattice *lt; + + lt= idbase->first; + while(lt) { + if(lt->id.us>0 || wd->current) { + /* write LibData */ + writestruct(wd, ID_LT, "Lattice", 1, lt); + + /* direct data */ + writestruct(wd, DATA, "BPoint", lt->pntsu*lt->pntsv*lt->pntsw, lt->def); + + write_dverts(wd, lt->pntsu*lt->pntsv*lt->pntsw, lt->dvert); + + } + lt= lt->id.next; + } +} + static void write_images(WriteData *wd, ListBase *idbase) { Image *ima; @@ -1155,22 +1175,6 @@ static void write_lamps(WriteData *wd, ListBase *idbase) } } -static void write_lattices(WriteData *wd, ListBase *idbase) -{ - Lattice *lt; - - lt= idbase->first; - while(lt) { - if(lt->id.us>0 || wd->current) { - /* write LibData */ - writestruct(wd, ID_LT, "Lattice", 1, lt); - - /* direct data */ - writestruct(wd, DATA, "BPoint", lt->pntsu*lt->pntsv*lt->pntsw, lt->def); - } - lt= lt->id.next; - } -} static void write_scenes(WriteData *wd, ListBase *scebase) { diff --git a/source/blender/include/BIF_editdeform.h b/source/blender/include/BIF_editdeform.h index 4c22cb678da..8336997f815 100644 --- a/source/blender/include/BIF_editdeform.h +++ b/source/blender/include/BIF_editdeform.h @@ -54,13 +54,13 @@ void sel_verts_defgroup (int select); struct MDeformWeight *get_defweight (struct MDeformVert *dv, int defgroup); struct MDeformWeight *verify_defweight (struct MDeformVert *dv, int defgroup); -void verify_defgroups (struct Object *ob); + void add_vert_to_defgroup (struct Object *ob, struct bDeformGroup *dg, int vertnum, float weight, int assignmode); void remove_vert_defgroup (struct Object *ob, struct bDeformGroup *dg, int vertnum); -void create_dverts(Mesh *me); +void create_dverts(ID *id); void vertexgroup_select_by_name(struct Object *ob, char *name); diff --git a/source/blender/include/butspace.h b/source/blender/include/butspace.h index a73c92cc2f5..81ed1debf6d 100644 --- a/source/blender/include/butspace.h +++ b/source/blender/include/butspace.h @@ -90,6 +90,7 @@ extern void get_constraint_ipo_context(void *ob_v, char *actname); extern void editing_panels(void); extern void do_common_editbuts(unsigned short event); extern void do_meshbuts(unsigned short event); +extern void do_vgroupbuts(unsigned short event); extern void do_curvebuts(unsigned short event); extern void do_fontbuts(unsigned short event); extern void do_mballbuts(unsigned short event); @@ -367,7 +368,7 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la #define B_NEXTKEY 2046 #define B_LOCKKEY 2047 -#define B_MESHBUTS 2100 +#define B_MESHBUTS 2090 #define B_FLIPNORM 2050 #define B_SPIN 2051 @@ -378,34 +379,40 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la #define B_SPLIT 2056 #define B_REMDOUB 2057 #define B_SUBDIV 2058 -#define B_FRACSUBDIV 2059 +#define B_FRACSUBDIV 2059 #define B_XSORT 2060 #define B_HASH 2061 #define B_DELSTICKY 2062 #define B_DELVERTCOL 2063 #define B_MAKE_TFACES 2064 -#define B_TOSPHERE 2065 +#define B_TOSPHERE 2065 #define B_DEL_TFACES 2066 -#define B_NEWVGROUP 2067 -#define B_DELVGROUP 2068 -#define B_ASSIGNVGROUP 2069 -#define B_REMOVEVGROUP 2070 -#define B_SELVGROUP 2071 -#define B_DESELVGROUP 2072 -#define B_DECIM_FACES 2073 -#define B_DECIM_CANCEL 2074 -#define B_DECIM_APPLY 2075 -#define B_AUTOVGROUP 2076 -#define B_SLOWERDRAW 2077 -#define B_FASTERDRAW 2078 -#define B_VERTEXNOISE 2079 -#define B_VERTEXSMOOTH 2080 -#define B_MAKESTICKY 2082 -#define B_MAKEVERTCOL 2083 -#define B_CHROMADEPTH 2084 -#define B_DRAWEDGES 2087 -#define B_DRAWCREASES 2088 -#define B_LINKEDVGROUP 2089 +#define B_DECIM_FACES 2067 +#define B_DECIM_CANCEL 2068 +#define B_DECIM_APPLY 2069 +#define B_SLOWERDRAW 2070 +#define B_FASTERDRAW 2071 +#define B_VERTEXNOISE 2072 +#define B_VERTEXSMOOTH 2073 +#define B_MAKESTICKY 2074 +#define B_MAKEVERTCOL 2075 +#define B_CHROMADEPTH 2076 +#define B_DRAWEDGES 2077 +#define B_DRAWCREASES 2078 + +/* *********************** */ +#define B_VGROUPBUTS 2100 + +#define B_NEWVGROUP 2091 +#define B_DELVGROUP 2092 +#define B_ASSIGNVGROUP 2093 +#define B_REMOVEVGROUP 2094 +#define B_SELVGROUP 2095 +#define B_DESELVGROUP 2096 +#define B_AUTOVGROUP 2097 +#define B_LINKEDVGROUP 2098 + + /* *********************** */ #define B_CURVEBUTS 2200 diff --git a/source/blender/makesdna/DNA_lattice_types.h b/source/blender/makesdna/DNA_lattice_types.h index 3d77e7feb02..823dc2ba485 100644 --- a/source/blender/makesdna/DNA_lattice_types.h +++ b/source/blender/makesdna/DNA_lattice_types.h @@ -37,6 +37,7 @@ struct BPoint; struct Ipo; struct Key; +struct MDeformVert; typedef struct Lattice { ID id; @@ -52,6 +53,8 @@ typedef struct Lattice { struct Ipo *ipo; struct Key *key; + + struct MDeformVert *dvert; } Lattice; /* ***************** LATTICE ********************* */ diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index ff3102a28ff..7047d4701b9 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -5953,7 +5953,7 @@ static PyObject *Mesh_assignVertsToGroup( BPy_Mesh * self, PyObject * args ) /* makes a set of dVerts corresponding to the mVerts */ if( !mesh->dvert ) - create_dverts( mesh ); + create_dverts( &mesh->id ); /* loop list adding verts to group */ for( x = 0; x < PyList_Size( listObject ); x++ ) { diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c index b16463bbe62..722593569a3 100644 --- a/source/blender/python/api2_2x/NMesh.c +++ b/source/blender/python/api2_2x/NMesh.c @@ -3006,7 +3006,7 @@ static void check_dverts(Mesh *me, int old_totvert) else if (totvert > old_totvert) { MDeformVert *mdv = me->dvert; me->dvert = NULL; - create_dverts(me); + create_dverts( &me->id ); copy_dverts(me->dvert, mdv, old_totvert); free_dverts(mdv, old_totvert); } @@ -3014,7 +3014,7 @@ static void check_dverts(Mesh *me, int old_totvert) else { MDeformVert *mdv = me->dvert; me->dvert = NULL; - create_dverts(me); + create_dverts( &me->id ); copy_dverts(me->dvert, mdv, totvert); free_dverts(mdv, old_totvert); } @@ -3897,7 +3897,7 @@ static PyObject *NMesh_assignVertsToGroup( PyObject * self, PyObject * args ) //makes a set of dVerts corresponding to the mVerts if( !( ( Mesh * ) object->data )->dvert ) { - create_dverts( ( Mesh * ) object->data ); + create_dverts( object->data ); } //loop list adding verts to group for( x = 0; x < PyList_Size( listObject ); x++ ) { diff --git a/source/blender/src/butspace.c b/source/blender/src/butspace.c index 061b505240b..a4a8a55aac3 100644 --- a/source/blender/src/butspace.c +++ b/source/blender/src/butspace.c @@ -569,6 +569,9 @@ void do_butspace(unsigned short event) else if(event<=B_MESHBUTS) { do_meshbuts(event); } + else if(event<=B_VGROUPBUTS) { + do_vgroupbuts(event); + } else if(event<=B_CURVEBUTS) { do_curvebuts(event); } diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c index 0f11953b502..335a11a9bb6 100644 --- a/source/blender/src/buttons_editing.c +++ b/source/blender/src/buttons_editing.c @@ -3409,27 +3409,18 @@ static void copy_linked_vgroup_channels(Object *ob) allqueue(REDRAWBUTSEDIT, 0); } -void do_meshbuts(unsigned short event) +void do_vgroupbuts(unsigned short event) { - Object *ob; - Mesh *me; - float fac; - short randfac; - int count; /* store num of changes made to see if redraw & undo are needed*/ - ob= OBACT; - if(ob && ob->type==OB_MESH) { - - me= get_mesh(ob); - if(me==0) return; - - switch(event) { + Object *ob= OBACT; + + switch(event) { case B_NEWVGROUP: - add_defgroup (G.obedit); + add_defgroup (ob); scrarea_queue_winredraw(curarea); allqueue(REDRAWOOPS, 0); break; case B_DELVGROUP: - del_defgroup (G.obedit); + del_defgroup (ob); allqueue (REDRAWVIEW3D, 1); allqueue(REDRAWOOPS, 0); BIF_undo_push("Delete vertex group"); @@ -3460,6 +3451,24 @@ void do_meshbuts(unsigned short event) case B_LINKEDVGROUP: copy_linked_vgroup_channels(ob); break; + } +} + +void do_meshbuts(unsigned short event) +{ + Object *ob; + Mesh *me; + float fac; + int count; /* store num of changes made to see if redraw & undo are needed*/ + short randfac; + + ob= OBACT; + if(ob && ob->type==OB_MESH) { + + me= get_mesh(ob); + if(me==NULL) return; + + switch(event) { case B_DELSTICKY: if(me->msticky) MEM_freeN(me->msticky); @@ -3514,7 +3523,7 @@ void do_meshbuts(unsigned short event) break; } } - if(G.obedit==0 || (G.obedit->type!=OB_MESH)) return; + if(G.obedit==NULL || (G.obedit->type!=OB_MESH)) return; switch(event) { case B_SPIN: @@ -3811,12 +3820,7 @@ static void editing_panel_links(Object *ob) } - - - /* to be sure */ - if ELEM6(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_EMPTY); - else return; - + /* empty display handling, note it returns! */ if (ob->type==OB_EMPTY) { uiDefBut(block, LABEL,0,"Empty Display:", xco, 154, 130,20, 0, 0, 0, 0, 0, ""); @@ -3829,47 +3833,18 @@ static void editing_panel_links(Object *ob) uiBlockEndAlign(block); return; } - - if(ob->type==OB_MESH) poin= &( ((Mesh *)ob->data)->texflag ); - else if(ob->type==OB_MBALL) poin= &( ((MetaBall *)ob->data)->texflag ); - else poin= &( ((Curve *)ob->data)->texflag ); - uiDefButBitI(block, TOG, AUTOSPACE, B_AUTOTEX, "AutoTexSpace", 143,15,140,19, poin, 0, 0, 0, 0, "Adjusts active object's texture space automatically when transforming object"); - - sprintf(str,"%d Mat ", ob->totcol); - if(ob->totcol) min= 1.0; else min= 0.0; - ma= give_current_material(ob, ob->actcol); - - if(ma) uiDefBut(block, LABEL, 0, ma->id.name+2, 318,153, 103, 20, 0, 0, 0, 0, 0, ""); - - uiBlockBeginAlign(block); - if(ma) uiDefButF(block, COL, B_REDR, "", 292,123,31,30, &(ma->r), 0, 0, 0, 0, ""); - uiDefButC(block, NUM, B_ACTCOL, str, 324,123,100,30, &ob->actcol, min, (float)(ob->totcol), 0, 0, "Displays total number of material indices and the current index"); - uiDefBut(block, BUT,B_MATWICH, "?", 424,123,30,30, 0, 0, 0, 0, 0, "In EditMode, sets the active material index from selected faces"); - - uiBlockBeginAlign(block); - uiDefBut(block, BUT,B_MATNEW, "New", 292,98,80,20, 0, 0, 0, 0, 0, "Adds a new Material index"); - uiDefBut(block, BUT,B_MATDEL, "Delete", 374,98,80,20, 0, 0, 0, 0, 0, "Deletes this Material index"); - uiDefBut(block, BUT,B_MATSEL, "Select", 292,76,80,20, 0, 0, 0, 0, 0, "In EditMode, selects faces that have the active index"); - uiDefBut(block, BUT,B_MATDESEL, "Deselect", 374,76,80,20, 0, 0, 0, 0, 0, "Deselects everything with current indexnumber"); - uiDefBut(block, BUT,B_MATASS, "Assign", 292,47,162,26, 0, 0, 0, 0, 0, "In EditMode, assigns the active index to selected faces"); - - uiBlockBeginAlign(block); - uiDefBut(block, BUT,B_SETSMOOTH,"Set Smooth", 291,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'smooth' rendering of selected faces"); - uiDefBut(block, BUT,B_SETSOLID, "Set Solid", 373,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'solid' rendering of selected faces"); - uiBlockEndAlign(block); - + /* vertex group... partially editmode... */ - if(ob->type==OB_MESH) { - Mesh *me= ob->data; + if(ob->type==OB_MESH || ob->type==OB_LATTICE) { + bDeformGroup *defGroup; uiBut *but; int defCount; - bDeformGroup *defGroup; - + uiDefBut(block, LABEL,0,"Vertex Groups", 143,153,130,20, 0, 0, 0, 0, 0, ""); - + defCount=BLI_countlist(&ob->defbase); - + uiBlockBeginAlign(block); if (defCount) { char *menustr= get_vertexgroup_menustr(ob); @@ -3883,28 +3858,63 @@ static void editing_panel_links(Object *ob) but= uiDefBut(block, TEX, REDRAWBUTSEDIT,"", 161,132,140-18,21, defGroup->name, 0, 31, 0, 0, "Displays current vertex group name. Click to change. (Match bone name for deformation.)"); uiButSetFunc(but, verify_vertexgroup_name_func, defGroup, NULL); uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)ob); - + uiDefButF(block, NUM, REDRAWVIEW3D, "Weight:", 143, 111, 140, 21, &editbutvweight, 0, 1, 10, 0, "Sets the current vertex group's bone deformation strength"); } uiBlockEndAlign(block); - + if (G.obedit && G.obedit==ob){ uiBlockBeginAlign(block); uiDefBut(block, BUT,B_NEWVGROUP,"New", 143,90,70,21, 0, 0, 0, 0, 0, "Creates a new vertex group"); uiDefBut(block, BUT,B_DELVGROUP,"Delete", 213,90,70,21, 0, 0, 0, 0, 0, "Removes the current vertex group"); - + uiDefBut(block, BUT,B_ASSIGNVGROUP,"Assign", 143,69,70,21, 0, 0, 0, 0, 0, "Assigns selected vertices to the current vertex group"); uiDefBut(block, BUT,B_REMOVEVGROUP,"Remove", 213,69,70,21, 0, 0, 0, 0, 0, "Removes selected vertices from the current vertex group"); - + uiDefBut(block, BUT,B_SELVGROUP,"Select", 143,48,70,21, 0, 0, 0, 0, 0, "Selects vertices belonging to the current vertex group"); uiDefBut(block, BUT,B_DESELVGROUP,"Desel.", 213,48,70,21, 0, 0, 0, 0, 0, "Deselects vertices belonging to the current vertex group"); uiBlockEndAlign(block); } else { - if(me->id.us>1) - uiDefBut(block, BUT,B_LINKEDVGROUP, "Copy To Linked", 143,69,140,20, 0, 0, 0, 0, 0, "Creates identical vertex group names in other Objects using this Mesh"); + ID *id= ob->data; + if(id->us>1) + uiDefBut(block, BUT,B_LINKEDVGROUP, "Copy To Linked", 143,69,140,20, 0, 0, 0, 0, 0, "Creates identical vertex group names in other Objects using this Object-data"); } - } + } + + + /* now only objects that can be visible rendered */ + if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL); + else return; + + + if(ob->type==OB_MESH) poin= &( ((Mesh *)ob->data)->texflag ); + else if(ob->type==OB_MBALL) poin= &( ((MetaBall *)ob->data)->texflag ); + else poin= &( ((Curve *)ob->data)->texflag ); + uiDefButBitI(block, TOG, AUTOSPACE, B_AUTOTEX, "AutoTexSpace", 143,15,140,19, poin, 0, 0, 0, 0, "Adjusts active object's texture space automatically when transforming object"); + + sprintf(str,"%d Mat ", ob->totcol); + if(ob->totcol) min= 1.0; else min= 0.0; + ma= give_current_material(ob, ob->actcol); + + if(ma) uiDefBut(block, LABEL, 0, ma->id.name+2, 318,153, 103, 20, 0, 0, 0, 0, 0, ""); + + uiBlockBeginAlign(block); + if(ma) uiDefButF(block, COL, B_REDR, "", 292,123,31,30, &(ma->r), 0, 0, 0, 0, ""); + uiDefButC(block, NUM, B_ACTCOL, str, 324,123,100,30, &ob->actcol, min, (float)(ob->totcol), 0, 0, "Displays total number of material indices and the current index"); + uiDefBut(block, BUT,B_MATWICH, "?", 424,123,30,30, 0, 0, 0, 0, 0, "In EditMode, sets the active material index from selected faces"); + + uiBlockBeginAlign(block); + uiDefBut(block, BUT,B_MATNEW, "New", 292,98,80,20, 0, 0, 0, 0, 0, "Adds a new Material index"); + uiDefBut(block, BUT,B_MATDEL, "Delete", 374,98,80,20, 0, 0, 0, 0, 0, "Deletes this Material index"); + uiDefBut(block, BUT,B_MATSEL, "Select", 292,76,80,20, 0, 0, 0, 0, 0, "In EditMode, selects faces that have the active index"); + uiDefBut(block, BUT,B_MATDESEL, "Deselect", 374,76,80,20, 0, 0, 0, 0, 0, "Deselects everything with current indexnumber"); + uiDefBut(block, BUT,B_MATASS, "Assign", 292,47,162,26, 0, 0, 0, 0, 0, "In EditMode, assigns the active index to selected faces"); + + uiBlockBeginAlign(block); + uiDefBut(block, BUT,B_SETSMOOTH,"Set Smooth", 291,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'smooth' rendering of selected faces"); + uiDefBut(block, BUT,B_SETSOLID, "Set Solid", 373,15,80,20, 0, 0, 0, 0, 0, "In EditMode, sets 'solid' rendering of selected faces"); + uiBlockEndAlign(block); } diff --git a/source/blender/src/drawobject.c b/source/blender/src/drawobject.c index 878aa0ad50e..76099d83fae 100644 --- a/source/blender/src/drawobject.c +++ b/source/blender/src/drawobject.c @@ -96,15 +96,16 @@ #include "BKE_verse.h" #endif +#include "BIF_editarmature.h" +#include "BIF_editdeform.h" +#include "BIF_editmesh.h" +#include "BIF_glutil.h" #include "BIF_gl.h" #include "BIF_glutil.h" #include "BIF_mywindow.h" +#include "BIF_resources.h" #include "BIF_screen.h" #include "BIF_space.h" -#include "BIF_editarmature.h" -#include "BIF_editmesh.h" -#include "BIF_glutil.h" -#include "BIF_resources.h" #include "BDR_drawmesh.h" #include "BDR_drawobject.h" @@ -999,26 +1000,42 @@ void lattice_foreachScreenVert(void (*func)(void *userData, BPoint *bp, int x, i } } -static void drawlattice__point(Lattice *lt, DispList *dl, int u, int v, int w) +static void drawlattice__point(Lattice *lt, DispList *dl, int u, int v, int w, int use_wcol) { int index = ((w*lt->pntsv + v)*lt->pntsu) + u; + if(use_wcol) { + float col[3]; + MDeformWeight *mdw= get_defweight (lt->dvert+index, use_wcol-1); + + weight_to_rgb(mdw?mdw->weight:0.0f, col, col+1, col+2); + glColor3fv(col); + } + if (dl) { glVertex3fv(&dl->verts[index*3]); } else { glVertex3fv(lt->def[index].vec); } } + +/* lattice color is hardcoded, now also shows weightgroup values in edit mode */ static void drawlattice(Object *ob) { Lattice *lt; DispList *dl; int u, v, w; + int use_wcol= 0; lt= (ob==G.obedit)?editLatt:ob->data; dl= find_displist(&ob->disp, DL_VERTS); if(ob==G.obedit) { cpack(0x004000); + + if(ob->defbase.first && lt->dvert) { + use_wcol= ob->actdef; + glShadeModel(GL_SMOOTH); + } } glBegin(GL_LINES); @@ -1030,22 +1047,26 @@ static void drawlattice(Object *ob) int uxt = (u==0 || u==lt->pntsu-1); if(w && ((uxt || vxt) || !(lt->flag & LT_OUTSIDE))) { - drawlattice__point(lt, dl, u, v, w-1); - drawlattice__point(lt, dl, u, v, w); + drawlattice__point(lt, dl, u, v, w-1, use_wcol); + drawlattice__point(lt, dl, u, v, w, use_wcol); } if(v && ((uxt || wxt) || !(lt->flag & LT_OUTSIDE))) { - drawlattice__point(lt, dl, u, v-1, w); - drawlattice__point(lt, dl, u, v, w); + drawlattice__point(lt, dl, u, v-1, w, use_wcol); + drawlattice__point(lt, dl, u, v, w, use_wcol); } if(u && ((vxt || wxt) || !(lt->flag & LT_OUTSIDE))) { - drawlattice__point(lt, dl, u-1, v, w); - drawlattice__point(lt, dl, u, v, w); + drawlattice__point(lt, dl, u-1, v, w, use_wcol); + drawlattice__point(lt, dl, u, v, w, use_wcol); } } } } glEnd(); + /* restoration for weight colors */ + if(use_wcol) + glShadeModel(GL_FLAT); + if(ob==G.obedit) { if(G.vd->zbuf) glDisable(GL_DEPTH_TEST); diff --git a/source/blender/src/editarmature.c b/source/blender/src/editarmature.c index f749ceda127..87ef080807f 100644 --- a/source/blender/src/editarmature.c +++ b/source/blender/src/editarmature.c @@ -2231,7 +2231,7 @@ void create_vgroups_from_armature(Object *ob, Object *par) bone_looper(ob, arm->bonebase.first, NULL, add_defgroup_unique_bone); if (ob->type == OB_MESH) - create_dverts((Mesh*)ob->data); + create_dverts(ob->data); break; diff --git a/source/blender/src/editdeform.c b/source/blender/src/editdeform.c index 22fd58c8059..b7a2f43ea3a 100644 --- a/source/blender/src/editdeform.c +++ b/source/blender/src/editdeform.c @@ -37,6 +37,7 @@ #include "MEM_guardedalloc.h" #include "DNA_curve_types.h" +#include "DNA_lattice_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" @@ -46,10 +47,12 @@ #include "BKE_DerivedMesh.h" #include "BKE_depsgraph.h" -#include "BKE_global.h" #include "BKE_deform.h" #include "BKE_displist.h" +#include "BKE_global.h" +#include "BKE_lattice.h" #include "BKE_mesh.h" +#include "BKE_utildefines.h" #include "BIF_editdeform.h" #include "BIF_editmesh.h" @@ -61,26 +64,21 @@ #include <config.h> #endif -/* ----------------- function prototypes ---------------- */ -void remove_vert_def_nr (Object *, int , int ); -void add_vert_defnr (Object *, int , int vertnum, float , int ); - - +/* only in editmode */ void sel_verts_defgroup (int select) { - EditMesh *em = G.editMesh; - EditVert *eve; - Object *ob; - int i; + EditVert *eve; + Object *ob; + int i; - ob=G.obedit; + ob= G.obedit; if (!ob) return; switch (ob->type){ case OB_MESH: - for (eve=em->verts.first; eve; eve=eve->next){ + for (eve=G.editMesh->verts.first; eve; eve=eve->next){ if (eve->totweight){ for (i=0; i<eve->totweight; i++){ if (eve->dw[i].def_nr == (ob->actdef-1)){ @@ -92,14 +90,37 @@ void sel_verts_defgroup (int select) } } } + /* this has to be called, because this function operates on vertices only */ + if(select) EM_select_flush(); // vertices to edges/faces + else EM_deselect_flush(); + break; + case OB_LATTICE: + if(editLatt->dvert) { + BPoint *bp; + MDeformVert *dvert= editLatt->dvert; + int a, tot; + + tot= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw; + for(a=0, bp= editLatt->def; a<tot; a++, bp++, dvert++) { + for (i=0; i<dvert->totweight; i++){ + if (dvert->dw[i].def_nr == (ob->actdef-1)) { + if(select) bp->f1 |= SELECT; + else bp->f1 &= ~SELECT; + + break; + } + } + } + } + break; + default: break; } + countall(); - /* this has to be called, because this function operates on vertices only */ - if(select) EM_select_flush(); // vertices to edges/faces - else EM_deselect_flush(); + } /* check if deform vertex has defgroup index */ @@ -139,7 +160,7 @@ MDeformWeight *verify_defweight (MDeformVert *dv, int defgroup) } dv->dw=newdw; - dv->dw[dv->totweight].weight=0; + dv->dw[dv->totweight].weight=0.0f; dv->dw[dv->totweight].def_nr=defgroup; /* Group index */ @@ -174,12 +195,9 @@ bDeformGroup *add_defgroup_name (Object *ob, char *name) void del_defgroup (Object *ob) { - EditMesh *em = G.editMesh; bDeformGroup *defgroup; - EditVert *eve; int i; - if (!ob) return; @@ -194,14 +212,32 @@ void del_defgroup (Object *ob) remove_verts_defgroup(1); /* Make sure that any verts with higher indices are adjusted accordingly */ - for (eve=em->verts.first; eve; eve=eve->next){ - for (i=0; i<eve->totweight; i++){ - if (eve->dw[i].def_nr > (ob->actdef-1)) - eve->dw[i].def_nr--; + if(ob->type==OB_MESH) { + EditMesh *em = G.editMesh; + EditVert *eve; + + for (eve=em->verts.first; eve; eve=eve->next){ + for (i=0; i<eve->totweight; i++){ + if (eve->dw[i].def_nr > (ob->actdef-1)) + eve->dw[i].def_nr--; + } + } + } + else { + BPoint *bp; + MDeformVert *dvert= editLatt->dvert; + int a, tot; + + tot= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw; + for(a=0, bp= editLatt->def; a<tot; a++, bp++, dvert++) { + for (i=0; i<dvert->totweight; i++){ + if (dvert->dw[i].def_nr > (ob->actdef-1)) + dvert->dw[i].def_nr--; + } } } - /* Update the active material index if necessary */ + /* Update the active deform index if necessary */ if (ob->actdef==BLI_countlist(&ob->defbase)) ob->actdef--; @@ -216,19 +252,23 @@ void del_defgroup (Object *ob) } } -void create_dverts(Mesh *me) +void create_dverts(ID *id) { - /* create deform verts for the mesh + /* create deform verts */ - int i; - me->dvert= MEM_mallocN(sizeof(MDeformVert)*me->totvert, "deformVert"); - for (i=0; i < me->totvert; ++i) { - me->dvert[i].totweight = 0; - me->dvert[i].dw = NULL; + if( GS(id->name)==ID_ME) { + Mesh *me= (Mesh *)id; + me->dvert= MEM_callocN(sizeof(MDeformVert)*me->totvert, "deformVert"); + } + else if( GS(id->name)==ID_LT) { + Lattice *lt= (Lattice *)id; + lt->dvert= MEM_callocN(sizeof(MDeformVert)*lt->pntsu*lt->pntsv*lt->pntsw, "lattice deformVert"); } } +/* for mesh in object mode + lattice can be in editmode */ void remove_vert_def_nr (Object *ob, int def_nr, int vertnum) { /* This routine removes the vertex from the deform @@ -242,18 +282,26 @@ void remove_vert_def_nr (Object *ob, int def_nr, int vertnum) */ MDeformWeight *newdw; - MDeformVert *dvert; + MDeformVert *dvert= NULL; int i; - /* if this mesh has no deform mesh abort - */ - if (!((Mesh*)ob->data)->dvert) return; - - /* get the deform mesh cooresponding to the + /* get the deform vertices corresponding to the * vertnum */ - dvert = ((Mesh*)ob->data)->dvert + vertnum; - + if(ob->type==OB_MESH) { + if( ((Mesh*)ob->data)->dvert ) + dvert = ((Mesh*)ob->data)->dvert + vertnum; + } + else if(ob->type==OB_LATTICE) { + Lattice *lt= ob->data; + + if(ob==G.obedit) + lt= editLatt; + + if(lt->dvert) + dvert = lt->dvert + vertnum; + } + /* for all of the deform weights in the * deform vert */ @@ -293,22 +341,36 @@ void remove_vert_def_nr (Object *ob, int def_nr, int vertnum) } +/* for Mesh in Object mode */ +/* allows editmode for Lattice */ void add_vert_defnr (Object *ob, int def_nr, int vertnum, float weight, int assignmode) { /* add the vert to the deform group with the * specified number */ - - MDeformVert *dv; + MDeformVert *dv= NULL; MDeformWeight *newdw; int i; - /* get the vert - */ - if(((Mesh*)ob->data)->dvert) - dv = ((Mesh*)ob->data)->dvert + vertnum; - else + /* get the vert */ + if(ob->type==OB_MESH) { + if(((Mesh*)ob->data)->dvert) + dv = ((Mesh*)ob->data)->dvert + vertnum; + } + else if(ob->type==OB_LATTICE) { + Lattice *lt; + + if(ob==G.obedit) + lt= editLatt; + else + lt= ob->data; + + if(lt->dvert) + dv = lt->dvert + vertnum; + } + + if(dv==NULL) return; /* Lets first check to see if this vert is @@ -377,6 +439,7 @@ void add_vert_defnr (Object *ob, int def_nr, int vertnum, } } +/* called while not in editmode */ void add_vert_to_defgroup (Object *ob, bDeformGroup *dg, int vertnum, float weight, int assignmode) { @@ -391,11 +454,16 @@ void add_vert_to_defgroup (Object *ob, bDeformGroup *dg, int vertnum, def_nr = get_defgroup_num(ob, dg); if (def_nr < 0) return; - /* if this mesh has no deform verts then + /* if there's no deform verts then * create some */ - if (!((Mesh*)ob->data)->dvert) { - create_dverts((Mesh*)ob->data); + if(ob->type==OB_MESH) { + if (!((Mesh*)ob->data)->dvert) + create_dverts(ob->data); + } + else if(ob->type==OB_LATTICE) { + if (!((Lattice*)ob->data)->dvert) + create_dverts(ob->data); } /* call another function to do the work @@ -403,19 +471,17 @@ void add_vert_to_defgroup (Object *ob, bDeformGroup *dg, int vertnum, add_vert_defnr (ob, def_nr, vertnum, weight, assignmode); } - -void assign_verts_defgroup (void) /* Only available in editmode */ +void assign_verts_defgroup (void) { - EditMesh *em = G.editMesh; + extern float editbutvweight; /* buttons.c */ Object *ob; EditVert *eve; - bDeformGroup *dg, *eg; - extern float editbutvweight; /* buttons.c */ - int i, done; + bDeformGroup *dg, *eg; MDeformWeight *newdw; + int i, done; - ob=G.obedit; + ob= G.obedit; if (!ob) return; @@ -429,7 +495,7 @@ void assign_verts_defgroup (void) switch (ob->type){ case OB_MESH: /* Go through the list of editverts and assign them */ - for (eve=em->verts.first; eve; eve=eve->next){ + for (eve=G.editMesh->verts.first; eve; eve=eve->next){ if (eve->f & 1){ done=0; /* See if this vert already has a reference to this group */ @@ -453,8 +519,8 @@ void assign_verts_defgroup (void) } eve->dw=newdw; - eve->dw[eve->totweight].weight=editbutvweight; - eve->dw[eve->totweight].def_nr=ob->actdef-1; + eve->dw[eve->totweight].weight= editbutvweight; + eve->dw[eve->totweight].def_nr= ob->actdef-1; eve->totweight++; @@ -462,6 +528,21 @@ void assign_verts_defgroup (void) } } break; + case OB_LATTICE: + { + BPoint *bp; + int a, tot; + + if(editLatt->dvert==NULL) + create_dverts(&editLatt->id); + + tot= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw; + for(a=0, bp= editLatt->def; a<tot; a++, bp++) { + if(bp->f1 & SELECT) + add_vert_defnr (ob, ob->actdef-1, a, editbutvweight, WEIGHT_REPLACE); + } + } + break; default: printf ("Assigning deformation groups to unknown object type\n"); break; @@ -469,6 +550,7 @@ void assign_verts_defgroup (void) } +/* mesh object mode, lattice can be in editmode */ void remove_vert_defgroup (Object *ob, bDeformGroup *dg, int vertnum) { /* This routine removes the vertex from the specified @@ -482,10 +564,6 @@ void remove_vert_defgroup (Object *ob, bDeformGroup *dg, int vertnum) if (!ob) return; - /* if this isn't a mesh abort - */ - if (ob->type != OB_MESH) return; - /* get the deform number that cooresponds * to this deform group, and abort if it * can not be found. @@ -498,17 +576,17 @@ void remove_vert_defgroup (Object *ob, bDeformGroup *dg, int vertnum) remove_vert_def_nr (ob, def_nr, vertnum); } -void remove_verts_defgroup (int allverts) /* Only available in editmode */ +/* removes from active defgroup, if allverts==0 only selected vertices */ +void remove_verts_defgroup (int allverts) { - EditMesh *em = G.editMesh; Object *ob; EditVert *eve; MDeformWeight *newdw; - bDeformGroup *dg, *eg; + bDeformGroup *dg, *eg; int i; - ob=G.obedit; + ob= G.obedit; if (!ob) return; @@ -521,7 +599,7 @@ void remove_verts_defgroup (int allverts) switch (ob->type){ case OB_MESH: - for (eve=em->verts.first; eve; eve=eve->next){ + for (eve=G.editMesh->verts.first; eve; eve=eve->next){ if (eve->dw && ((eve->f & 1) || allverts)){ for (i=0; i<eve->totweight; i++){ /* Find group */ @@ -547,42 +625,32 @@ void remove_verts_defgroup (int allverts) } } break; - default: - printf ("Removing deformation groups from unknown object type\n"); - break; - } -} - -void verify_defgroups (Object *ob) -{ - /* Ensure the defbase & the dverts match */ - switch (ob->type){ - case OB_MESH: - - /* I'm pretty sure this means "If there are no - * deform groups defined, yet there are deform - * vertices, then delete the deform vertices - */ - if (!ob->defbase.first){ - if (((Mesh*)ob->data)->dvert){ - free_dverts(((Mesh*)ob->data)->dvert, - ((Mesh*)ob->data)->totvert); - ((Mesh*)ob->data)->dvert=NULL; + case OB_LATTICE: + + if(editLatt->dvert) { + BPoint *bp; + int a, tot= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw; + + for(a=0, bp= editLatt->def; a<tot; a++, bp++) { + if(allverts || (bp->f1 & SELECT)) + remove_vert_defgroup (ob, dg, a); } } break; + default: + printf ("Removing deformation groups from unknown object type\n"); break; } } void unique_vertexgroup_name (bDeformGroup *dg, Object *ob) { - char tempname[64]; - int number; - char *dot; - int exists = 0; bDeformGroup *curdef; + int number; + int exists = 0; + char tempname[64]; + char *dot; if (!ob) return; @@ -628,7 +696,8 @@ void vertexgroup_select_by_name(Object *ob, char *name) bDeformGroup *curdef; int actdef= 1; - if(ob==NULL || ob->type!=OB_MESH) return; + if(ob==NULL) return; + for (curdef = ob->defbase.first; curdef; curdef=curdef->next, actdef++){ if (!strcmp(curdef->name, name)) { ob->actdef= actdef; diff --git a/source/blender/src/editlattice.c b/source/blender/src/editlattice.c index 244b035db15..9aa363a654f 100644 --- a/source/blender/src/editlattice.c +++ b/source/blender/src/editlattice.c @@ -47,6 +47,7 @@ #include "DNA_curve_types.h" #include "DNA_key_types.h" #include "DNA_lattice_types.h" +#include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_view3d_types.h" @@ -55,6 +56,7 @@ #include "BKE_global.h" #include "BKE_key.h" #include "BKE_lattice.h" +#include "BKE_mesh.h" #include "BKE_utildefines.h" #include "BIF_editlattice.h" @@ -80,8 +82,11 @@ void free_editLatt(void) { if(editLatt) { if(editLatt->def) MEM_freeN(editLatt->def); + if(editLatt->dvert) + free_dverts(editLatt->dvert, editLatt->pntsu*editLatt->pntsv*editLatt->pntsw); + MEM_freeN(editLatt); - editLatt= 0; + editLatt= NULL; } } @@ -123,7 +128,12 @@ void make_editLatt(void) editLatt= MEM_dupallocN(lt); editLatt->def= MEM_dupallocN(lt->def); - setflagsLatt(0); + if(lt->dvert) { + int tot= lt->pntsu*lt->pntsv*lt->pntsw; + editLatt->dvert = MEM_mallocN (sizeof (MDeformVert)*tot, "Lattice MDeformVert"); + copy_dverts(editLatt->dvert, lt->dvert, tot); + } + BIF_undo_push("original"); } @@ -171,6 +181,19 @@ void load_editLatt(void) lt->typev= editLatt->typev; lt->typew= editLatt->typew; } + + if(lt->dvert) { + free_dverts(lt->dvert, lt->pntsu*lt->pntsv*lt->pntsw); + lt->dvert= NULL; + } + + if(editLatt->dvert) { + int tot= lt->pntsu*lt->pntsv*lt->pntsw; + + lt->dvert = MEM_mallocN (sizeof (MDeformVert)*tot, "Lattice MDeformVert"); + copy_dverts(lt->dvert, editLatt->dvert, tot); + } + } void remake_editLatt(void) diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index ede9d198b15..ea8305cde95 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -1284,7 +1284,7 @@ void make_parent(void) while(base) { if TESTBASELIB(base) { if(base!=BASACT) { - if(base->object->type==OB_MESH) { + if(ELEM(base->object->type, OB_MESH, OB_LATTICE)) { if(par->flag & OB_POSEMODE) mode= pupmenu("Make Parent To%t|Bone %x1|Armature %x2|Object %x3"); else @@ -1393,7 +1393,7 @@ void make_parent(void) memset(base->object->loc, 0, 3*sizeof(float)); } else { - if(mode==PARSKEL && par->type == OB_ARMATURE) { + if(mode==PARSKEL && base->object->type==OB_MESH && par->type == OB_ARMATURE) { /* Prompt the user as to whether he wants to * add some vertex groups based on the bones * in the parent armature. @@ -1410,10 +1410,6 @@ void make_parent(void) what_does_parent(base->object); Mat4Invert(base->object->parentinv, workob.obmat); } - - if(par->type==OB_ARMATURE && mode == PARSKEL){ - verify_defgroups(base->object); - } } } } diff --git a/source/blender/src/vpaint.c b/source/blender/src/vpaint.c index 3128572723b..380763834ac 100644 --- a/source/blender/src/vpaint.c +++ b/source/blender/src/vpaint.c @@ -1182,7 +1182,7 @@ void weight_paint(void) /* if nothing was added yet, we make dverts and a vertex deform group */ if (!me->dvert) - create_dverts(me); + create_dverts(&me->id); if(G.qual & LR_CTRLKEY) { sample_wpaint(0); |