2011-02-23 10:52:22 +00:00
/*
2009-01-07 19:23:22 +00:00
* $ Id $
*
* * * * * * BEGIN GPL LICENSE BLOCK * * * * *
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
2010-02-12 13:34:04 +00:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2009-01-07 19:23:22 +00:00
*
* The Original Code is Copyright ( C ) 2001 - 2002 by NaN Holding BV .
* All rights reserved .
*
* The Original Code is : all of this file .
*
* Contributor ( s ) : none yet .
*
* * * * * * END GPL LICENSE BLOCK * * * * *
*/
2011-02-27 20:29:51 +00:00
/** \file blender/editors/object/object_vgroup.c
* \ ingroup edobj
*/
2009-01-07 19:23:22 +00:00
# include <string.h>
2010-02-02 21:43:26 +00:00
# include <stddef.h>
2009-11-20 05:09:57 +00:00
# include <math.h>
2011-01-21 05:09:32 +00:00
# include <assert.h>
2009-01-07 19:23:22 +00:00
# include "MEM_guardedalloc.h"
# include "DNA_cloth_types.h"
# include "DNA_curve_types.h"
# include "DNA_lattice_types.h"
# include "DNA_meshdata_types.h"
# include "DNA_modifier_types.h"
# include "DNA_object_types.h"
# include "DNA_object_force.h"
# include "DNA_scene_types.h"
# include "DNA_particle_types.h"
# include "BLI_blenlib.h"
# include "BLI_editVert.h"
2011-01-07 18:36:47 +00:00
# include "BLI_utildefines.h"
2009-01-07 19:23:22 +00:00
2009-07-01 22:25:49 +00:00
# include "BKE_context.h"
2009-01-07 19:23:22 +00:00
# include "BKE_customdata.h"
# include "BKE_deform.h"
2009-07-01 22:25:49 +00:00
# include "BKE_depsgraph.h"
2009-01-07 19:23:22 +00:00
# include "BKE_global.h"
# include "BKE_mesh.h"
2010-02-17 22:26:50 +00:00
# include "BKE_report.h"
2009-01-07 19:23:22 +00:00
2009-07-01 22:25:49 +00:00
# include "RNA_access.h"
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
# include "RNA_define.h"
2009-07-01 22:25:49 +00:00
# include "WM_api.h"
# include "WM_types.h"
2009-01-07 19:23:22 +00:00
# include "ED_mesh.h"
2009-07-01 22:25:49 +00:00
2009-11-22 06:20:56 +00:00
# include "UI_resources.h"
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
2009-07-01 22:25:49 +00:00
# include "object_intern.h"
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/************************ Exported Functions **********************/
2010-02-09 22:00:19 +00:00
static void vgroup_remap_update_users ( Object * ob , int * map ) ;
2011-01-07 09:50:23 +00:00
static void vgroup_delete_edit_mode ( Object * ob , bDeformGroup * defgroup ) ;
static void vgroup_delete_object_mode ( Object * ob , bDeformGroup * dg ) ;
2011-06-07 18:04:03 +00:00
static void vgroup_delete_all ( Object * ob ) ;
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
static Lattice * vgroup_edit_lattice ( Object * ob )
2009-01-13 15:18:41 +00:00
{
2011-03-30 02:59:32 +00:00
Lattice * lt = ob - > data ;
BLI_assert ( ob - > type = = OB_LATTICE ) ;
return ( lt - > editlatt ) ? lt - > editlatt - > latt : lt ;
2009-01-07 19:23:22 +00:00
}
2011-01-07 09:50:23 +00:00
int ED_vgroup_object_is_edit_mode ( Object * ob )
{
if ( ob - > type = = OB_MESH )
return ( ( ( Mesh * ) ob - > data ) - > edit_mesh ! = NULL ) ;
else if ( ob - > type = = OB_LATTICE )
return ( ( ( Lattice * ) ob - > data ) - > editlatt ! = NULL ) ;
return 0 ;
}
2010-11-17 09:45:45 +00:00
bDeformGroup * ED_vgroup_add_name ( Object * ob , const char * name )
2009-01-07 19:23:22 +00:00
{
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
bDeformGroup * defgroup ;
2009-01-07 19:23:22 +00:00
2010-08-27 02:33:35 +00:00
if ( ! ob | | ! ELEM ( ob - > type , OB_MESH , OB_LATTICE ) )
2009-01-07 19:23:22 +00:00
return NULL ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
defgroup = MEM_callocN ( sizeof ( bDeformGroup ) , " add deformGroup " ) ;
2009-01-07 19:23:22 +00:00
2010-04-22 08:25:05 +00:00
BLI_strncpy ( defgroup - > name , name , sizeof ( defgroup - > name ) ) ;
2009-01-07 19:23:22 +00:00
BLI_addtail ( & ob - > defbase , defgroup ) ;
2010-01-26 13:50:17 +00:00
defgroup_unique_name ( defgroup , ob ) ;
2009-01-07 19:23:22 +00:00
ob - > actdef = BLI_countlist ( & ob - > defbase ) ;
return defgroup ;
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
bDeformGroup * ED_vgroup_add ( Object * ob )
2009-01-07 19:23:22 +00:00
{
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
return ED_vgroup_add_name ( ob , " Group " ) ;
2009-01-07 19:23:22 +00:00
}
2011-01-07 09:50:23 +00:00
void ED_vgroup_delete ( Object * ob , bDeformGroup * defgroup )
{
bDeformGroup * dg = ( bDeformGroup * ) ob - > defbase . first ;
while ( dg ) {
if ( dg = = defgroup )
break ;
dg = dg - > next ;
}
if ( dg = = NULL )
return ;
if ( ED_vgroup_object_is_edit_mode ( ob ) )
vgroup_delete_edit_mode ( ob , dg ) ;
else
vgroup_delete_object_mode ( ob , dg ) ;
}
2011-06-07 18:04:03 +00:00
int ED_vgroup_data_create ( ID * id )
2009-01-07 19:23:22 +00:00
{
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* create deform verts */
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( GS ( id - > name ) = = ID_ME ) {
Mesh * me = ( Mesh * ) id ;
me - > dvert = CustomData_add_layer ( & me - > vdata , CD_MDEFORMVERT , CD_CALLOC , NULL , me - > totvert ) ;
2011-06-07 18:04:03 +00:00
return TRUE ;
2009-06-08 20:08:19 +00:00
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
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 " ) ;
2011-06-07 18:04:03 +00:00
return TRUE ;
}
else {
return FALSE ;
2009-01-07 19:23:22 +00:00
}
}
2011-02-14 17:55:27 +00:00
static int ED_vgroup_give_parray ( ID * id , MDeformVert * * * dvert_arr , int * dvert_tot )
2010-05-04 12:31:24 +00:00
{
2011-06-07 18:04:03 +00:00
* dvert_tot = 0 ;
* dvert_arr = NULL ;
2010-05-04 12:31:24 +00:00
if ( id ) {
switch ( GS ( id - > name ) ) {
case ID_ME :
{
Mesh * me = ( Mesh * ) id ;
2010-06-07 18:50:19 +00:00
if ( me - > edit_mesh ) {
2010-05-04 12:31:24 +00:00
EditMesh * em = me - > edit_mesh ;
EditVert * eve ;
int i ;
if ( ! CustomData_has_layer ( & em - > vdata , CD_MDEFORMVERT ) ) {
return 0 ;
}
2011-01-21 05:09:32 +00:00
i = BLI_countlist ( & em - > verts ) ;
2010-05-04 12:31:24 +00:00
* dvert_arr = MEM_mallocN ( sizeof ( void * ) * i , " vgroup parray from me " ) ;
* dvert_tot = i ;
i = 0 ;
for ( eve = em - > verts . first ; eve ; eve = eve - > next , i + + ) {
( * dvert_arr ) [ i ] = CustomData_em_get ( & em - > vdata , eve - > data , CD_MDEFORMVERT ) ;
}
2010-06-07 18:50:19 +00:00
return 1 ;
}
else if ( me - > dvert ) {
int i ;
* dvert_tot = me - > totvert ;
* dvert_arr = MEM_mallocN ( sizeof ( void * ) * me - > totvert , " vgroup parray from me " ) ;
for ( i = 0 ; i < me - > totvert ; i + + ) {
( * dvert_arr ) [ i ] = me - > dvert + i ;
}
return 1 ;
2010-05-04 12:31:24 +00:00
}
2011-06-07 18:04:03 +00:00
else {
2010-07-07 17:32:50 +00:00
return 0 ;
2011-06-07 18:04:03 +00:00
}
2010-05-04 12:31:24 +00:00
}
case ID_LT :
{
int i = 0 ;
Lattice * lt = ( Lattice * ) id ;
2010-08-10 06:36:42 +00:00
lt = ( lt - > editlatt ) ? lt - > editlatt - > latt : lt ;
2010-05-04 12:31:24 +00:00
2011-03-22 10:13:42 +00:00
if ( lt - > dvert ) {
* dvert_tot = lt - > pntsu * lt - > pntsv * lt - > pntsw ;
* dvert_arr = MEM_mallocN ( sizeof ( void * ) * ( * dvert_tot ) , " vgroup parray from me " ) ;
2010-05-04 12:31:24 +00:00
2011-03-22 10:13:42 +00:00
for ( i = 0 ; i < * dvert_tot ; i + + ) {
( * dvert_arr ) [ i ] = lt - > dvert + i ;
}
2010-05-04 12:31:24 +00:00
2011-03-22 10:13:42 +00:00
return 1 ;
}
else {
return 0 ;
}
2010-05-04 12:31:24 +00:00
}
}
}
return 0 ;
}
2009-10-20 10:19:48 +00:00
/* returns true if the id type supports weights */
int ED_vgroup_give_array ( ID * id , MDeformVert * * dvert_arr , int * dvert_tot )
{
if ( id ) {
switch ( GS ( id - > name ) ) {
case ID_ME :
{
Mesh * me = ( Mesh * ) id ;
* dvert_arr = me - > dvert ;
* dvert_tot = me - > totvert ;
return TRUE ;
}
case ID_LT :
{
Lattice * lt = ( Lattice * ) id ;
2010-08-10 06:36:42 +00:00
lt = ( lt - > editlatt ) ? lt - > editlatt - > latt : lt ;
2009-10-20 10:19:48 +00:00
* dvert_arr = lt - > dvert ;
* dvert_tot = lt - > pntsu * lt - > pntsv * lt - > pntsw ;
return TRUE ;
}
}
}
* dvert_arr = NULL ;
* dvert_tot = 0 ;
return FALSE ;
}
2010-02-09 22:00:19 +00:00
/* matching index only */
int ED_vgroup_copy_array ( Object * ob , Object * ob_from )
{
2010-05-04 12:31:24 +00:00
MDeformVert * * dvert_array_from , * * dvf ;
MDeformVert * * dvert_array , * * dv ;
2010-02-09 22:00:19 +00:00
int dvert_tot_from ;
int dvert_tot ;
int i ;
int totdef_from = BLI_countlist ( & ob_from - > defbase ) ;
int totdef = BLI_countlist ( & ob - > defbase ) ;
2011-06-07 18:04:03 +00:00
short new_vgroup = FALSE ;
2010-02-09 22:00:19 +00:00
2010-05-04 12:31:24 +00:00
ED_vgroup_give_parray ( ob_from - > data , & dvert_array_from , & dvert_tot_from ) ;
ED_vgroup_give_parray ( ob - > data , & dvert_array , & dvert_tot ) ;
2010-02-09 22:00:19 +00:00
2011-06-07 18:04:03 +00:00
if ( ( dvert_array = = NULL ) & & ( dvert_array_from ! = NULL ) & & ED_vgroup_data_create ( ob - > data ) ) {
ED_vgroup_give_parray ( ob - > data , & dvert_array , & dvert_tot ) ;
new_vgroup = TRUE ;
}
2010-05-04 12:31:24 +00:00
if ( ob = = ob_from | | dvert_tot = = 0 | | ( dvert_tot ! = dvert_tot_from ) | | dvert_array_from = = NULL | | dvert_array = = NULL ) {
if ( dvert_array ) MEM_freeN ( dvert_array ) ;
if ( dvert_array_from ) MEM_freeN ( dvert_array_from ) ;
2011-06-07 18:04:03 +00:00
if ( new_vgroup = = TRUE ) {
/* free the newly added vgroup since it wasn't compatible */
2011-06-07 18:34:33 +00:00
vgroup_delete_all ( ob ) ;
2011-06-07 18:04:03 +00:00
}
2010-02-09 22:00:19 +00:00
return 0 ;
2010-05-04 12:31:24 +00:00
}
2010-02-09 22:00:19 +00:00
/* do the copy */
BLI_freelistN ( & ob - > defbase ) ;
BLI_duplicatelist ( & ob - > defbase , & ob_from - > defbase ) ;
ob - > actdef = ob_from - > actdef ;
if ( totdef_from < totdef ) {
/* correct vgroup indices because the number of vgroups is being reduced. */
int * remap = MEM_mallocN ( sizeof ( int ) * ( totdef + 1 ) , " ED_vgroup_copy_array " ) ;
for ( i = 0 ; i < = totdef_from ; i + + ) remap [ i ] = i ;
2010-02-10 08:53:08 +00:00
for ( ; i < = totdef ; i + + ) remap [ i ] = 0 ; /* can't use these, so disable */
2010-02-09 22:00:19 +00:00
vgroup_remap_update_users ( ob , remap ) ;
MEM_freeN ( remap ) ;
}
dvf = dvert_array_from ;
dv = dvert_array ;
for ( i = 0 ; i < dvert_tot ; i + + , dvf + + , dv + + ) {
2010-05-04 12:31:24 +00:00
if ( ( * dv ) - > dw )
MEM_freeN ( ( * dv ) - > dw ) ;
2010-02-09 22:00:19 +00:00
2010-05-04 12:31:24 +00:00
* ( * dv ) = * ( * dvf ) ;
2010-02-09 22:00:19 +00:00
2010-05-04 12:31:24 +00:00
if ( ( * dv ) - > dw )
( * dv ) - > dw = MEM_dupallocN ( ( * dv ) - > dw ) ;
2010-02-09 22:00:19 +00:00
}
2010-05-04 12:31:24 +00:00
MEM_freeN ( dvert_array ) ;
MEM_freeN ( dvert_array_from ) ;
2010-02-09 22:00:19 +00:00
return 1 ;
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* for mesh in object mode
lattice can be in editmode */
2011-02-14 17:55:27 +00:00
static void ED_vgroup_nr_vert_remove ( Object * ob , int def_nr , int vertnum )
2009-01-07 19:23:22 +00:00
{
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* This routine removes the vertex from the deform
* group with number def_nr .
*
* This routine is meant to be fast , so it is the
* responsibility of the calling routine to :
* a ) test whether ob is non - NULL
* b ) test whether ob is a mesh
* c ) calculate def_nr
*/
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
MDeformWeight * newdw ;
MDeformVert * dvert = NULL ;
2009-10-20 10:19:48 +00:00
int i , tot ;
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* get the deform vertices corresponding to the
* vertnum
*/
2009-10-20 10:19:48 +00:00
ED_vgroup_give_array ( ob - > data , & dvert , & tot ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( dvert = = NULL )
return ;
2009-10-20 10:19:48 +00:00
dvert + = vertnum ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* for all of the deform weights in the
* deform vert
*/
for ( i = dvert - > totweight - 1 ; i > = 0 ; i - - ) {
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* if the def_nr is the same as the one
* for our weight group then remove it
* from this deform vert .
*/
if ( dvert - > dw [ i ] . def_nr = = def_nr ) {
dvert - > totweight - - ;
2011-04-21 13:11:51 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* if there are still other deform weights
* attached to this vert then remove this
* deform weight , and reshuffle the others
*/
if ( dvert - > totweight ) {
newdw = MEM_mallocN ( sizeof ( MDeformWeight ) * ( dvert - > totweight ) ,
" deformWeight " ) ;
if ( dvert - > dw ) {
memcpy ( newdw , dvert - > dw , sizeof ( MDeformWeight ) * i ) ;
memcpy ( newdw + i , dvert - > dw + i + 1 ,
sizeof ( MDeformWeight ) * ( dvert - > totweight - i ) ) ;
MEM_freeN ( dvert - > dw ) ;
}
dvert - > dw = newdw ;
}
/* if there are no other deform weights
* left then just remove the deform weight
*/
else {
MEM_freeN ( dvert - > dw ) ;
dvert - > dw = NULL ;
break ;
2009-01-07 19:23:22 +00:00
}
}
}
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* for Mesh in Object mode */
/* allows editmode for Lattice */
2011-02-14 17:55:27 +00:00
static void ED_vgroup_nr_vert_add ( Object * ob , int def_nr , int vertnum , float weight , int assignmode )
2009-01-07 19:23:22 +00:00
{
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* add the vert to the deform group with the
* specified number
*/
MDeformVert * dv = NULL ;
MDeformWeight * newdw ;
2009-10-20 10:19:48 +00:00
int i , tot ;
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* get the vert */
2009-10-20 10:19:48 +00:00
ED_vgroup_give_array ( ob - > data , & dv , & tot ) ;
2009-06-08 20:08:19 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( dv = = NULL )
2009-01-07 19:23:22 +00:00
return ;
2009-06-08 20:08:19 +00:00
2010-04-05 07:16:22 +00:00
/* check that vertnum is valid before trying to get the relevant dvert */
if ( ( vertnum < 0 ) | | ( vertnum > = tot ) )
return ;
else
dv + = vertnum ;
2009-10-20 10:19:48 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* Lets first check to see if this vert is
* already in the weight group - - if so
* lets update it
*/
for ( i = 0 ; i < dv - > totweight ; i + + ) {
/* if this weight cooresponds to the
* deform group , then add it using
* the assign mode provided
*/
if ( dv - > dw [ i ] . def_nr = = def_nr ) {
switch ( assignmode ) {
case WEIGHT_REPLACE :
dv - > dw [ i ] . weight = weight ;
break ;
case WEIGHT_ADD :
dv - > dw [ i ] . weight + = weight ;
2011-03-27 14:59:55 +00:00
if ( dv - > dw [ i ] . weight > = 1.0f )
dv - > dw [ i ] . weight = 1.0f ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
break ;
case WEIGHT_SUBTRACT :
dv - > dw [ i ] . weight - = weight ;
/* if the weight is zero or less then
* remove the vert from the deform group
*/
2011-03-27 14:59:55 +00:00
if ( dv - > dw [ i ] . weight < = 0.0f )
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
ED_vgroup_nr_vert_remove ( ob , def_nr , vertnum ) ;
break ;
2009-01-07 19:23:22 +00:00
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
return ;
2009-01-07 19:23:22 +00:00
}
}
/* if the vert wasn't in the deform group then
* we must take a different form of action . . .
*/
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
switch ( assignmode ) {
2009-01-07 19:23:22 +00:00
case WEIGHT_SUBTRACT :
/* if we are subtracting then we don't
* need to do anything
*/
return ;
case WEIGHT_REPLACE :
case WEIGHT_ADD :
/* if we are doing an additive assignment, then
* we need to create the deform weight
*/
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
newdw = MEM_callocN ( sizeof ( MDeformWeight ) * ( dv - > totweight + 1 ) ,
2009-01-07 19:23:22 +00:00
" deformWeight " ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( dv - > dw ) {
memcpy ( newdw , dv - > dw , sizeof ( MDeformWeight ) * dv - > totweight ) ;
MEM_freeN ( dv - > dw ) ;
2009-01-07 19:23:22 +00:00
}
dv - > dw = newdw ;
2011-04-21 13:11:51 +00:00
2009-01-07 19:23:22 +00:00
dv - > dw [ dv - > totweight ] . weight = weight ;
dv - > dw [ dv - > totweight ] . def_nr = def_nr ;
2011-04-21 13:11:51 +00:00
2009-01-07 19:23:22 +00:00
dv - > totweight + + ;
break ;
}
}
/* called while not in editmode */
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
void ED_vgroup_vert_add ( Object * ob , bDeformGroup * dg , int vertnum , float weight , int assignmode )
2009-01-07 19:23:22 +00:00
{
/* add the vert to the deform group with the
* specified assign mode
*/
int def_nr ;
2009-10-20 10:19:48 +00:00
MDeformVert * dv = NULL ;
int tot ;
2009-01-07 19:23:22 +00:00
/* get the deform group number, exit if
* it can ' t be found
*/
2010-01-26 13:50:17 +00:00
def_nr = defgroup_find_index ( ob , dg ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( def_nr < 0 ) return ;
2009-01-07 19:23:22 +00:00
2009-10-20 10:19:48 +00:00
/* if there's no deform verts then create some,
2009-01-07 19:23:22 +00:00
*/
2009-10-20 10:19:48 +00:00
if ( ED_vgroup_give_array ( ob - > data , & dv , & tot ) & & dv = = NULL )
ED_vgroup_data_create ( ob - > data ) ;
2009-01-07 19:23:22 +00:00
/* call another function to do the work
*/
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
ED_vgroup_nr_vert_add ( ob , def_nr , vertnum , weight , assignmode ) ;
2009-01-07 19:23:22 +00:00
}
/* mesh object mode, lattice can be in editmode */
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
void ED_vgroup_vert_remove ( Object * ob , bDeformGroup * dg , int vertnum )
2009-01-07 19:23:22 +00:00
{
/* This routine removes the vertex from the specified
* deform group .
*/
2011-01-21 05:09:32 +00:00
const int def_nr = defgroup_find_index ( ob , dg ) ;
if ( def_nr < 0 )
2009-01-07 19:23:22 +00:00
return ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
ED_vgroup_nr_vert_remove ( ob , def_nr , vertnum ) ;
2009-01-07 19:23:22 +00:00
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
static float get_vert_def_nr ( Object * ob , int def_nr , int vertnum )
2009-01-07 19:23:22 +00:00
{
2011-04-23 07:28:30 +00:00
MDeformVert * dvert = NULL ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
EditVert * eve ;
Mesh * me ;
2009-01-07 19:23:22 +00:00
int i ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* get the deform vertices corresponding to the vertnum */
2009-01-07 19:23:22 +00:00
if ( ob - > type = = OB_MESH ) {
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
me = ob - > data ;
if ( me - > edit_mesh ) {
eve = BLI_findlink ( & me - > edit_mesh - > verts , vertnum ) ;
2011-04-23 07:28:30 +00:00
if ( ! eve ) {
return 0.0f ;
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
dvert = CustomData_em_get ( & me - > edit_mesh - > vdata , eve - > data , CD_MDEFORMVERT ) ;
2009-10-12 17:16:44 +00:00
vertnum = 0 ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
2011-03-30 02:59:32 +00:00
else {
if ( vertnum > = me - > totvert ) {
return 0.0f ;
}
2009-10-12 17:16:44 +00:00
dvert = me - > dvert ;
2011-03-30 02:59:32 +00:00
}
2009-01-07 19:23:22 +00:00
}
else if ( ob - > type = = OB_LATTICE ) {
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
Lattice * lt = vgroup_edit_lattice ( ob ) ;
2011-03-30 02:59:32 +00:00
if ( lt - > dvert ) {
if ( vertnum > = lt - > pntsu * lt - > pntsv * lt - > pntsw ) {
return 0.0f ;
}
2009-10-12 17:16:44 +00:00
dvert = lt - > dvert ;
2011-03-30 02:59:32 +00:00
}
2009-01-07 19:23:22 +00:00
}
if ( dvert = = NULL )
2011-01-07 09:50:23 +00:00
return - 1 ;
2009-01-07 19:23:22 +00:00
2009-10-12 17:16:44 +00:00
dvert + = vertnum ;
2009-01-07 19:23:22 +00:00
for ( i = dvert - > totweight - 1 ; i > = 0 ; i - - )
if ( dvert - > dw [ i ] . def_nr = = def_nr )
return dvert - > dw [ i ] . weight ;
2011-01-07 09:50:23 +00:00
return - 1 ;
2009-01-07 19:23:22 +00:00
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
float ED_vgroup_vert_weight ( Object * ob , bDeformGroup * dg , int vertnum )
2009-01-07 19:23:22 +00:00
{
int def_nr ;
2011-01-07 09:50:23 +00:00
if ( ! ob ) return - 1 ;
2009-01-07 19:23:22 +00:00
2010-01-26 13:50:17 +00:00
def_nr = defgroup_find_index ( ob , dg ) ;
2011-01-07 09:50:23 +00:00
if ( def_nr < 0 ) return - 1 ;
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
return get_vert_def_nr ( ob , def_nr , vertnum ) ;
}
2011-02-07 22:48:23 +00:00
void ED_vgroup_select_by_name ( Object * ob , const char * name )
2010-08-22 14:15:28 +00:00
{ /* note: ob->actdef==0 signals on painting to create a new one, if a bone in posemode is selected */
ob - > actdef = defgroup_name_index ( ob , name ) + 1 ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
/********************** Operator Implementations *********************/
/* only in editmode */
static void vgroup_select_verts ( Object * ob , int select )
{
EditVert * eve ;
MDeformVert * dvert ;
int i ;
if ( ob - > type = = OB_MESH ) {
Mesh * me = ob - > data ;
EditMesh * em = BKE_mesh_get_editmesh ( me ) ;
for ( eve = em - > verts . first ; eve ; eve = eve - > next ) {
dvert = CustomData_em_get ( & em - > vdata , eve - > data , CD_MDEFORMVERT ) ;
if ( dvert & & dvert - > totweight ) {
for ( i = 0 ; i < dvert - > totweight ; i + + ) {
if ( dvert - > dw [ i ] . def_nr = = ( ob - > actdef - 1 ) ) {
2011-01-07 04:38:31 +00:00
if ( ! eve - > h ) {
if ( select ) eve - > f | = SELECT ;
else eve - > f & = ~ SELECT ;
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
break ;
}
}
}
}
/* this has to be called, because this function operates on vertices only */
if ( select ) EM_select_flush ( em ) ; // vertices to edges/faces
else EM_deselect_flush ( em ) ;
BKE_mesh_end_editmesh ( me , em ) ;
}
else if ( ob - > type = = OB_LATTICE ) {
Lattice * lt = vgroup_edit_lattice ( ob ) ;
if ( lt - > dvert ) {
BPoint * bp ;
int a , tot ;
dvert = lt - > dvert ;
tot = lt - > pntsu * lt - > pntsv * lt - > pntsw ;
for ( a = 0 , bp = lt - > 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 ;
}
}
}
}
}
}
static void vgroup_duplicate ( Object * ob )
{
bDeformGroup * dg , * cdg ;
2010-11-01 07:19:41 +00:00
char name [ sizeof ( dg - > name ) ] ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
MDeformWeight * org , * cpy ;
2010-05-04 12:31:24 +00:00
MDeformVert * dvert , * * dvert_array = NULL ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
int i , idg , icdg , dvert_tot = 0 ;
dg = BLI_findlink ( & ob - > defbase , ( ob - > actdef - 1 ) ) ;
if ( ! dg )
return ;
2010-11-01 07:19:41 +00:00
if ( ! strstr ( dg - > name , " _copy " ) ) {
BLI_snprintf ( name , sizeof ( name ) , " %s_copy " , dg - > name ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
else {
2010-11-01 07:19:41 +00:00
BLI_snprintf ( name , sizeof ( name ) , " %s " , dg - > name ) ;
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
2010-01-26 13:50:17 +00:00
cdg = defgroup_duplicate ( dg ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
strcpy ( cdg - > name , name ) ;
2010-01-26 13:50:17 +00:00
defgroup_unique_name ( cdg , ob ) ;
2010-11-01 07:19:41 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
BLI_addtail ( & ob - > defbase , cdg ) ;
idg = ( ob - > actdef - 1 ) ;
ob - > actdef = BLI_countlist ( & ob - > defbase ) ;
icdg = ( ob - > actdef - 1 ) ;
2010-05-04 12:31:24 +00:00
ED_vgroup_give_parray ( ob - > data , & dvert_array , & dvert_tot ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( ! dvert_array )
return ;
for ( i = 0 ; i < dvert_tot ; i + + ) {
2010-05-04 12:31:24 +00:00
dvert = dvert_array [ i ] ;
2010-01-26 17:07:47 +00:00
org = defvert_find_index ( dvert , idg ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( org ) {
float weight = org - > weight ;
2010-01-26 17:07:47 +00:00
/* defvert_verify_index re-allocs org so need to store the weight first */
cpy = defvert_verify_index ( dvert , icdg ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
cpy - > weight = weight ;
}
}
2010-05-04 12:31:24 +00:00
MEM_freeN ( dvert_array ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
2009-10-20 10:19:48 +00:00
static void vgroup_normalize ( Object * ob )
{
bDeformGroup * dg ;
MDeformWeight * dw ;
2010-05-04 12:31:24 +00:00
MDeformVert * dvert , * * dvert_array = NULL ;
2009-10-20 10:19:48 +00:00
int i , def_nr , dvert_tot = 0 ;
2010-05-04 12:31:24 +00:00
ED_vgroup_give_parray ( ob - > data , & dvert_array , & dvert_tot ) ;
2009-10-20 10:19:48 +00:00
dg = BLI_findlink ( & ob - > defbase , ( ob - > actdef - 1 ) ) ;
if ( dg ) {
2009-10-27 09:38:15 +00:00
float weight_max = 0.0f ;
2009-10-20 10:19:48 +00:00
def_nr = ob - > actdef - 1 ;
for ( i = 0 ; i < dvert_tot ; i + + ) {
2010-05-04 12:31:24 +00:00
dvert = dvert_array [ i ] ;
2010-01-26 17:07:47 +00:00
dw = defvert_find_index ( dvert , def_nr ) ;
2009-10-20 10:19:48 +00:00
if ( dw ) {
weight_max = MAX2 ( dw - > weight , weight_max ) ;
}
}
if ( weight_max > 0.0f ) {
for ( i = 0 ; i < dvert_tot ; i + + ) {
2010-05-04 12:31:24 +00:00
dvert = dvert_array [ i ] ;
2010-01-26 17:07:47 +00:00
dw = defvert_find_index ( dvert , def_nr ) ;
2009-10-20 10:19:48 +00:00
if ( dw ) {
dw - > weight / = weight_max ;
2009-10-27 09:38:15 +00:00
2009-10-20 10:19:48 +00:00
/* incase of division errors with very low weights */
CLAMP ( dw - > weight , 0.0f , 1.0f ) ;
}
}
}
}
2010-05-04 12:31:24 +00:00
if ( dvert_array ) MEM_freeN ( dvert_array ) ;
2009-10-20 10:19:48 +00:00
}
2009-11-20 05:09:57 +00:00
static void vgroup_levels ( Object * ob , float offset , float gain )
{
bDeformGroup * dg ;
MDeformWeight * dw ;
2010-05-04 12:31:24 +00:00
MDeformVert * dvert , * * dvert_array = NULL ;
2009-11-20 05:09:57 +00:00
int i , def_nr , dvert_tot = 0 ;
2010-05-04 12:31:24 +00:00
ED_vgroup_give_parray ( ob - > data , & dvert_array , & dvert_tot ) ;
2009-11-20 05:09:57 +00:00
dg = BLI_findlink ( & ob - > defbase , ( ob - > actdef - 1 ) ) ;
if ( dg ) {
def_nr = ob - > actdef - 1 ;
for ( i = 0 ; i < dvert_tot ; i + + ) {
2010-05-04 12:31:24 +00:00
dvert = dvert_array [ i ] ;
2010-01-26 17:07:47 +00:00
dw = defvert_find_index ( dvert , def_nr ) ;
2009-11-20 05:09:57 +00:00
if ( dw ) {
dw - > weight = gain * ( dw - > weight + offset ) ;
CLAMP ( dw - > weight , 0.0f , 1.0f ) ;
}
}
}
2010-05-04 12:31:24 +00:00
if ( dvert_array ) MEM_freeN ( dvert_array ) ;
2009-11-20 05:09:57 +00:00
}
2009-10-20 10:19:48 +00:00
/* TODO - select between groups */
2009-10-20 13:59:26 +00:00
static void vgroup_normalize_all ( Object * ob , int lock_active )
2009-10-20 10:19:48 +00:00
{
2009-10-20 13:59:26 +00:00
MDeformWeight * dw , * dw_act ;
2010-05-04 12:31:24 +00:00
MDeformVert * dvert , * * dvert_array = NULL ;
2009-10-20 10:19:48 +00:00
int i , dvert_tot = 0 ;
float tot_weight ;
2010-05-04 12:31:24 +00:00
ED_vgroup_give_parray ( ob - > data , & dvert_array , & dvert_tot ) ;
2009-10-20 10:19:48 +00:00
if ( dvert_array ) {
2009-10-20 13:59:26 +00:00
if ( lock_active ) {
int def_nr = ob - > actdef - 1 ;
2009-10-20 10:19:48 +00:00
2009-10-20 13:59:26 +00:00
for ( i = 0 ; i < dvert_tot ; i + + ) {
float lock_iweight = 1.0f ;
int j ;
tot_weight = 0.0f ;
dw_act = NULL ;
2010-05-04 12:31:24 +00:00
dvert = dvert_array [ i ] ;
2009-10-20 13:59:26 +00:00
j = dvert - > totweight ;
while ( j - - ) {
dw = dvert - > dw + j ;
if ( dw - > def_nr = = def_nr ) {
dw_act = dw ;
lock_iweight = ( 1.0f - dw_act - > weight ) ;
}
else {
tot_weight + = dw - > weight ;
}
}
if ( tot_weight ) {
j = dvert - > totweight ;
while ( j - - ) {
dw = dvert - > dw + j ;
if ( dw = = dw_act ) {
if ( dvert - > totweight = = 1 ) {
dw_act - > weight = 1.0f ; /* no other weights, set to 1.0 */
}
} else {
if ( dw - > weight > 0.0f )
dw - > weight = ( dw - > weight / tot_weight ) * lock_iweight ;
}
/* incase of division errors with very low weights */
CLAMP ( dw - > weight , 0.0f , 1.0f ) ;
}
}
2009-10-20 10:19:48 +00:00
}
2009-10-20 13:59:26 +00:00
}
else {
for ( i = 0 ; i < dvert_tot ; i + + ) {
int j ;
tot_weight = 0.0f ;
2010-05-04 12:31:24 +00:00
dvert = dvert_array [ i ] ;
2009-10-20 10:19:48 +00:00
j = dvert - > totweight ;
while ( j - - ) {
dw = dvert - > dw + j ;
2009-10-20 13:59:26 +00:00
tot_weight + = dw - > weight ;
}
2009-10-20 10:19:48 +00:00
2009-10-20 13:59:26 +00:00
if ( tot_weight ) {
j = dvert - > totweight ;
while ( j - - ) {
dw = dvert - > dw + j ;
dw - > weight / = tot_weight ;
/* incase of division errors with very low weights */
CLAMP ( dw - > weight , 0.0f , 1.0f ) ;
}
2009-10-20 10:19:48 +00:00
}
}
}
}
2010-05-04 12:31:24 +00:00
if ( dvert_array ) MEM_freeN ( dvert_array ) ;
2009-10-20 10:19:48 +00:00
}
2011-06-02 17:28:04 +00:00
/* Jason was here */
static void vgroup_invert_locks ( Object * ob )
{
bDeformGroup * dg = ob - > defbase . first ;
while ( dg ) {
dg - > flag = ! dg - > flag ;
dg = dg - > next ;
}
}
/* Jason was here */
static void vgroup_lock_all ( Object * ob )
{
bDeformGroup * dg = ob - > defbase . first ;
while ( dg ) {
dg - > flag = TRUE ;
dg = dg - > next ;
}
}
/* Jason was here */
static void vgroup_unlock_all ( Object * ob )
{
bDeformGroup * dg = ob - > defbase . first ;
while ( dg ) {
dg - > flag = FALSE ;
dg = dg - > next ;
}
}
2009-10-20 10:19:48 +00:00
static void vgroup_invert ( Object * ob , int auto_assign , int auto_remove )
{
bDeformGroup * dg ;
MDeformWeight * dw ;
2010-05-04 12:31:24 +00:00
MDeformVert * dvert , * * dvert_array = NULL ;
2009-10-20 10:19:48 +00:00
int i , def_nr , dvert_tot = 0 ;
2010-05-04 12:31:24 +00:00
ED_vgroup_give_parray ( ob - > data , & dvert_array , & dvert_tot ) ;
2009-10-20 10:19:48 +00:00
dg = BLI_findlink ( & ob - > defbase , ( ob - > actdef - 1 ) ) ;
if ( dg ) {
def_nr = ob - > actdef - 1 ;
for ( i = 0 ; i < dvert_tot ; i + + ) {
2010-05-04 12:31:24 +00:00
dvert = dvert_array [ i ] ;
2009-10-20 10:19:48 +00:00
if ( auto_assign ) {
2010-01-26 17:07:47 +00:00
dw = defvert_verify_index ( dvert , def_nr ) ;
2009-10-20 10:19:48 +00:00
} else {
2010-01-26 17:07:47 +00:00
dw = defvert_find_index ( dvert , def_nr ) ;
2009-10-20 10:19:48 +00:00
}
if ( dw ) {
dw - > weight = 1.0f - dw - > weight ;
if ( auto_remove & & dw - > weight < = 0.0f ) {
/* could have a faster function for this */
ED_vgroup_nr_vert_remove ( ob , def_nr , i ) ;
}
}
}
}
2010-05-04 12:31:24 +00:00
if ( dvert_array ) MEM_freeN ( dvert_array ) ;
2009-10-20 10:19:48 +00:00
}
2009-10-20 16:31:03 +00:00
static void vgroup_blend ( Object * ob )
{
bDeformGroup * dg ;
MDeformWeight * dw ;
MDeformVert * dvert_array = NULL , * dvert ;
int i , def_nr , dvert_tot = 0 ;
EditMesh * em = BKE_mesh_get_editmesh ( ( ( Mesh * ) ob - > data ) ) ;
// ED_vgroup_give_array(ob->data, &dvert_array, &dvert_tot);
if ( em = = NULL )
return ;
dg = BLI_findlink ( & ob - > defbase , ( ob - > actdef - 1 ) ) ;
if ( dg ) {
int sel1 , sel2 ;
int i1 , i2 ;
EditEdge * eed ;
EditVert * eve ;
float * vg_weights ;
float * vg_users ;
def_nr = ob - > actdef - 1 ;
i = 0 ;
for ( eve = em - > verts . first ; eve ; eve = eve - > next )
eve - > tmp . l = i + + ;
dvert_tot = i ;
vg_weights = MEM_callocN ( sizeof ( float ) * dvert_tot , " vgroup_blend_f " ) ;
vg_users = MEM_callocN ( sizeof ( int ) * dvert_tot , " vgroup_blend_i " ) ;
for ( eed = em - > edges . first ; eed ; eed = eed - > next ) {
sel1 = eed - > v1 - > f & SELECT ;
sel2 = eed - > v2 - > f & SELECT ;
if ( sel1 ! = sel2 ) {
/* i1 is always the selected one */
if ( sel1 = = TRUE & & sel2 = = FALSE ) {
i1 = eed - > v1 - > tmp . l ;
i2 = eed - > v2 - > tmp . l ;
eve = eed - > v2 ;
}
else {
i2 = eed - > v1 - > tmp . l ;
i1 = eed - > v2 - > tmp . l ;
eve = eed - > v1 ;
}
vg_users [ i1 ] + + ;
/* TODO, we may want object mode blending */
if ( em ) dvert = CustomData_em_get ( & em - > vdata , eve - > data , CD_MDEFORMVERT ) ;
else dvert = dvert_array + i2 ;
2010-01-26 17:07:47 +00:00
dw = defvert_find_index ( dvert , def_nr ) ;
2009-10-20 16:31:03 +00:00
if ( dw ) {
vg_weights [ i1 ] + = dw - > weight ;
}
}
}
i = 0 ;
for ( eve = em - > verts . first ; eve ; eve = eve - > next ) {
if ( eve - > f & SELECT & & vg_users [ i ] > 0 ) {
/* TODO, we may want object mode blending */
if ( em ) dvert = CustomData_em_get ( & em - > vdata , eve - > data , CD_MDEFORMVERT ) ;
else dvert = dvert_array + i ;
2010-01-26 17:07:47 +00:00
dw = defvert_verify_index ( dvert , def_nr ) ;
2009-10-20 16:31:03 +00:00
dw - > weight = vg_weights [ i ] / ( float ) vg_users [ i ] ;
}
i + + ;
}
MEM_freeN ( vg_weights ) ;
MEM_freeN ( vg_users ) ;
}
}
2009-10-20 10:19:48 +00:00
static void vgroup_clean ( Object * ob , float eul , int keep_single )
{
bDeformGroup * dg ;
MDeformWeight * dw ;
2010-05-04 12:31:24 +00:00
MDeformVert * dvert , * * dvert_array = NULL ;
2009-10-20 10:19:48 +00:00
int i , def_nr , dvert_tot = 0 ;
2010-05-04 12:31:24 +00:00
ED_vgroup_give_parray ( ob - > data , & dvert_array , & dvert_tot ) ;
2009-10-20 10:19:48 +00:00
/* only the active group */
dg = BLI_findlink ( & ob - > defbase , ( ob - > actdef - 1 ) ) ;
if ( dg ) {
def_nr = ob - > actdef - 1 ;
for ( i = 0 ; i < dvert_tot ; i + + ) {
2010-05-04 12:31:24 +00:00
dvert = dvert_array [ i ] ;
2009-10-20 10:19:48 +00:00
2010-01-26 17:07:47 +00:00
dw = defvert_find_index ( dvert , def_nr ) ;
2009-10-20 10:19:48 +00:00
if ( dw ) {
if ( dw - > weight < = eul )
if ( keep_single = = FALSE | | dvert - > totweight > 1 )
ED_vgroup_nr_vert_remove ( ob , def_nr , i ) ;
}
}
}
2010-05-04 12:31:24 +00:00
if ( dvert_array ) MEM_freeN ( dvert_array ) ;
2009-10-20 10:19:48 +00:00
}
static void vgroup_clean_all ( Object * ob , float eul , int keep_single )
{
MDeformWeight * dw ;
2010-05-04 12:31:24 +00:00
MDeformVert * dvert , * * dvert_array = NULL ;
2009-10-20 10:19:48 +00:00
int i , dvert_tot = 0 ;
2010-05-04 12:31:24 +00:00
ED_vgroup_give_parray ( ob - > data , & dvert_array , & dvert_tot ) ;
2009-10-20 10:19:48 +00:00
if ( dvert_array ) {
for ( i = 0 ; i < dvert_tot ; i + + ) {
int j ;
2010-05-04 12:31:24 +00:00
dvert = dvert_array [ i ] ;
2009-10-20 10:19:48 +00:00
j = dvert - > totweight ;
while ( j - - ) {
if ( keep_single & & dvert - > totweight = = 1 )
break ;
dw = dvert - > dw + j ;
if ( dw - > weight < = eul )
ED_vgroup_nr_vert_remove ( ob , dw - > def_nr , i ) ;
}
}
}
2010-05-04 12:31:24 +00:00
if ( dvert_array ) MEM_freeN ( dvert_array ) ;
2009-10-20 10:19:48 +00:00
}
2011-06-06 06:40:09 +00:00
static void dvert_mirror_op ( MDeformVert * dvert , MDeformVert * dvert_mirr ,
const char sel , const char sel_mirr ,
const int * flip_map ,
const short mirror_weights , const short flip_vgroups )
{
BLI_assert ( sel | | sel_mirr ) ;
if ( sel_mirr & & sel ) {
/* swap */
if ( mirror_weights )
SWAP ( MDeformVert , * dvert , * dvert_mirr ) ;
if ( flip_vgroups ) {
defvert_flip ( dvert , flip_map ) ;
defvert_flip ( dvert_mirr , flip_map ) ;
}
}
else {
/* dvert should always be the target */
if ( sel_mirr ) {
SWAP ( MDeformVert * , dvert , dvert_mirr ) ;
}
if ( mirror_weights )
defvert_copy ( dvert , dvert_mirr ) ;
if ( flip_vgroups ) {
defvert_flip ( dvert , flip_map ) ;
}
}
}
void ED_vgroup_mirror ( Object * ob , const short mirror_weights , const short flip_vgroups )
2010-01-15 17:28:00 +00:00
{
2011-06-06 06:40:09 +00:00
# define VGROUP_MIRR_OP dvert_mirror_op(dvert, dvert_mirr, sel, sel_mirr, flip_map, mirror_weights, flip_vgroups)
2010-01-15 17:28:00 +00:00
EditVert * eve , * eve_mirr ;
MDeformVert * dvert , * dvert_mirr ;
2011-06-06 06:40:09 +00:00
short sel , sel_mirr ;
2010-01-15 17:28:00 +00:00
int * flip_map ;
if ( mirror_weights = = 0 & & flip_vgroups = = 0 )
return ;
2011-06-06 06:40:09 +00:00
flip_map = defgroup_flip_map ( ob , 0 ) ;
2010-01-15 17:28:00 +00:00
/* only the active group */
if ( ob - > type = = OB_MESH ) {
Mesh * me = ob - > data ;
EditMesh * em = BKE_mesh_get_editmesh ( me ) ;
2011-06-06 06:40:09 +00:00
if ( ! CustomData_has_layer ( & em - > vdata , CD_MDEFORMVERT ) ) {
MEM_freeN ( flip_map ) ;
2010-01-15 17:28:00 +00:00
return ;
2011-06-06 06:40:09 +00:00
}
2010-01-15 17:28:00 +00:00
2011-06-06 06:40:09 +00:00
EM_cache_x_mirror_vert ( ob , em ) ;
2010-01-15 17:28:00 +00:00
/* Go through the list of editverts and assign them */
for ( eve = em - > verts . first ; eve ; eve = eve - > next ) {
if ( ( eve_mirr = eve - > tmp . v ) ) {
2011-06-06 06:40:09 +00:00
sel = eve - > f & SELECT ;
sel_mirr = eve_mirr - > f & SELECT ;
if ( ( sel | | sel_mirr ) & & ( eve ! = eve_mirr ) ) {
2010-01-15 17:28:00 +00:00
dvert = CustomData_em_get ( & em - > vdata , eve - > data , CD_MDEFORMVERT ) ;
dvert_mirr = CustomData_em_get ( & em - > vdata , eve_mirr - > data , CD_MDEFORMVERT ) ;
if ( dvert & & dvert_mirr ) {
2011-06-06 06:40:09 +00:00
VGROUP_MIRR_OP ;
2010-01-15 17:28:00 +00:00
}
}
eve - > tmp . v = eve_mirr - > tmp . v = NULL ;
}
}
BKE_mesh_end_editmesh ( me , em ) ;
}
2011-06-06 06:40:09 +00:00
else if ( ob - > type = = OB_LATTICE ) {
Lattice * lt = ob - > data ;
int i1 , i2 ;
int u , v , w ;
int pntsu_half ;
/* half but found up odd value */
if ( lt - > editlatt ) lt = lt - > editlatt - > latt ;
if ( lt - > pntsu = = 1 | | lt - > dvert = = NULL ) {
MEM_freeN ( flip_map ) ;
return ;
}
/* unlike editmesh we know that by only looping over the first hald of
* the ' u ' indicies it will cover all points except the middle which is
* ok in this case */
pntsu_half = lt - > pntsu / 2 ;
for ( w = 0 ; w < lt - > pntsw ; w + + ) {
for ( v = 0 ; v < lt - > pntsv ; v + + ) {
for ( u = 0 ; u < pntsu_half ; u + + ) {
int u_inv = ( lt - > pntsu - 1 ) - u ;
if ( u ! = u_inv ) {
BPoint * bp , * bp_mirr ;
i1 = LT_INDEX ( lt , u , v , w ) ;
i2 = LT_INDEX ( lt , u_inv , v , w ) ;
bp = & lt - > def [ i1 ] ;
bp_mirr = & lt - > def [ i2 ] ;
sel = bp - > f1 & SELECT ;
sel_mirr = bp_mirr - > f1 & SELECT ;
if ( sel | | sel_mirr ) {
dvert = & lt - > dvert [ i1 ] ;
dvert_mirr = & lt - > dvert [ i2 ] ;
VGROUP_MIRR_OP ;
}
}
}
}
}
}
MEM_freeN ( flip_map ) ;
# undef VGROUP_MIRR_OP
2010-01-15 17:28:00 +00:00
}
2010-02-02 21:43:26 +00:00
static void vgroup_remap_update_users ( Object * ob , int * map )
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
{
ExplodeModifierData * emd ;
ModifierData * md ;
ParticleSystem * psys ;
ClothModifierData * clmd ;
ClothSimSettings * clsim ;
int a ;
/* these cases don't use names to refer to vertex groups, so when
* they get deleted the numbers get out of sync , this corrects that */
2010-02-02 21:43:26 +00:00
if ( ob - > soft )
ob - > soft - > vertgroup = map [ ob - > soft - > vertgroup ] ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
for ( md = ob - > modifiers . first ; md ; md = md - > next ) {
if ( md - > type = = eModifierType_Explode ) {
emd = ( ExplodeModifierData * ) md ;
2010-02-02 21:43:26 +00:00
emd - > vgroup = map [ emd - > vgroup ] ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
else if ( md - > type = = eModifierType_Cloth ) {
clmd = ( ClothModifierData * ) md ;
clsim = clmd - > sim_parms ;
if ( clsim ) {
2010-02-02 21:43:26 +00:00
clsim - > vgroup_mass = map [ clsim - > vgroup_mass ] ;
clsim - > vgroup_bend = map [ clsim - > vgroup_bend ] ;
clsim - > vgroup_struct = map [ clsim - > vgroup_struct ] ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
}
}
for ( psys = ob - > particlesystem . first ; psys ; psys = psys - > next ) {
for ( a = 0 ; a < PSYS_TOT_VG ; a + + )
2010-02-02 21:43:26 +00:00
psys - > vgroup [ a ] = map [ psys - > vgroup [ a ] ] ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
}
2010-02-02 21:43:26 +00:00
static void vgroup_delete_update_users ( Object * ob , int id )
{
int i , tot = BLI_countlist ( & ob - > defbase ) + 1 ;
int * map = MEM_mallocN ( sizeof ( int ) * tot , " vgroup del " ) ;
map [ id ] = map [ 0 ] = 0 ;
for ( i = 1 ; i < id ; i + + ) map [ i ] = i ;
for ( i = id + 1 ; i < tot ; i + + ) map [ i ] = i - 1 ;
vgroup_remap_update_users ( ob , map ) ;
MEM_freeN ( map ) ;
}
2011-01-07 09:50:23 +00:00
static void vgroup_delete_object_mode ( Object * ob , bDeformGroup * dg )
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
{
2011-01-21 05:09:32 +00:00
MDeformVert * dvert_array = NULL ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
int i , e , dvert_tot = 0 ;
2011-01-21 05:09:32 +00:00
const int dg_index = BLI_findindex ( & ob - > defbase , dg ) ;
assert ( dg_index > - 1 ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
2009-10-20 10:19:48 +00:00
ED_vgroup_give_array ( ob - > data , & dvert_array , & dvert_tot ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( dvert_array ) {
2011-01-21 05:09:32 +00:00
MDeformVert * dvert ;
for ( i = 0 , dvert = dvert_array ; i < dvert_tot ; i + + , dvert + + ) {
ED_vgroup_vert_remove ( ob , dg , i ) ; /* ok if the dg isnt in this dvert, will continue silently */
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
2011-01-21 05:09:32 +00:00
for ( i = 0 , dvert = dvert_array ; i < dvert_tot ; i + + , dvert + + ) {
for ( e = 0 ; e < dvert - > totweight ; e + + ) {
if ( dvert - > dw [ e ] . def_nr > dg_index ) {
dvert - > dw [ e ] . def_nr - - ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
}
}
}
2011-01-21 05:09:32 +00:00
vgroup_delete_update_users ( ob , dg_index + 1 ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* Remove the group */
BLI_freelinkN ( & ob - > defbase , dg ) ;
2011-01-21 05:09:32 +00:00
/* Update the active deform index if necessary */
if ( ob - > actdef > dg_index )
ob - > actdef - - ;
if ( ob - > actdef < 1 & & ob - > defbase . first )
ob - > actdef = 1 ;
2009-01-07 19:23:22 +00:00
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* only in editmode */
2009-01-07 19:23:22 +00:00
/* removes from active defgroup, if allverts==0 only selected vertices */
2011-01-21 05:09:32 +00:00
static void vgroup_active_remove_verts ( Object * ob , const int allverts , bDeformGroup * dg )
2009-01-07 19:23:22 +00:00
{
EditVert * eve ;
MDeformVert * dvert ;
MDeformWeight * newdw ;
2011-01-21 05:09:32 +00:00
bDeformGroup * eg ;
2009-01-07 19:23:22 +00:00
int i ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( ob - > type = = OB_MESH ) {
2009-01-07 19:23:22 +00:00
Mesh * me = ob - > data ;
2009-04-11 08:26:51 +00:00
EditMesh * em = BKE_mesh_get_editmesh ( me ) ;
2009-03-30 07:28:37 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
for ( eve = em - > verts . first ; eve ; eve = eve - > next ) {
2009-03-30 07:28:37 +00:00
dvert = CustomData_em_get ( & em - > vdata , eve - > data , CD_MDEFORMVERT ) ;
2009-01-07 19:23:22 +00:00
2010-01-15 17:28:00 +00:00
if ( dvert & & dvert - > dw & & ( ( eve - > f & SELECT ) | | allverts ) ) {
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
for ( i = 0 ; i < dvert - > totweight ; i + + ) {
2009-01-07 19:23:22 +00:00
/* Find group */
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
eg = BLI_findlink ( & ob - > defbase , dvert - > dw [ i ] . def_nr ) ;
if ( eg = = dg ) {
2009-01-07 19:23:22 +00:00
dvert - > totweight - - ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( dvert - > totweight ) {
newdw = MEM_mallocN ( sizeof ( MDeformWeight ) * ( dvert - > totweight ) , " deformWeight " ) ;
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( dvert - > dw ) {
memcpy ( newdw , dvert - > dw , sizeof ( MDeformWeight ) * i ) ;
memcpy ( newdw + i , dvert - > dw + i + 1 , sizeof ( MDeformWeight ) * ( dvert - > totweight - i ) ) ;
MEM_freeN ( dvert - > dw ) ;
2009-01-07 19:23:22 +00:00
}
dvert - > dw = newdw ;
}
else {
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
MEM_freeN ( dvert - > dw ) ;
2009-01-07 19:23:22 +00:00
dvert - > dw = NULL ;
break ;
}
}
}
}
}
2009-04-11 08:26:51 +00:00
BKE_mesh_end_editmesh ( me , em ) ;
2009-01-07 19:23:22 +00:00
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
else if ( ob - > type = = OB_LATTICE ) {
Lattice * lt = vgroup_edit_lattice ( ob ) ;
2009-01-07 19:23:22 +00:00
2009-01-13 15:18:41 +00:00
if ( lt - > dvert ) {
2009-01-07 19:23:22 +00:00
BPoint * bp ;
2009-01-13 15:18:41 +00:00
int a , tot = lt - > pntsu * lt - > pntsv * lt - > pntsw ;
2009-01-07 19:23:22 +00:00
2009-01-13 15:18:41 +00:00
for ( a = 0 , bp = lt - > def ; a < tot ; a + + , bp + + ) {
2009-01-07 19:23:22 +00:00
if ( allverts | | ( bp - > f1 & SELECT ) )
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
ED_vgroup_vert_remove ( ob , dg , a ) ;
2009-01-07 19:23:22 +00:00
}
}
2009-01-13 15:18:41 +00:00
}
2009-01-07 19:23:22 +00:00
}
2011-01-21 05:09:32 +00:00
static void vgroup_delete_edit_mode ( Object * ob , bDeformGroup * dg )
2009-01-07 19:23:22 +00:00
{
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
int i ;
2011-01-21 05:09:32 +00:00
const int dg_index = BLI_findindex ( & ob - > defbase , dg ) ;
2009-01-07 19:23:22 +00:00
2011-01-21 05:09:32 +00:00
assert ( dg_index > - 1 ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* Make sure that no verts are using this group */
2011-01-21 05:09:32 +00:00
vgroup_active_remove_verts ( ob , TRUE , dg ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* Make sure that any verts with higher indices are adjusted accordingly */
if ( ob - > type = = OB_MESH ) {
Mesh * me = ob - > data ;
EditMesh * em = BKE_mesh_get_editmesh ( me ) ;
EditVert * eve ;
MDeformVert * dvert ;
for ( eve = em - > verts . first ; eve ; eve = eve - > next ) {
dvert = CustomData_em_get ( & em - > vdata , eve - > data , CD_MDEFORMVERT ) ;
if ( dvert )
for ( i = 0 ; i < dvert - > totweight ; i + + )
2011-01-21 05:09:32 +00:00
if ( dvert - > dw [ i ] . def_nr > dg_index )
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
dvert - > dw [ i ] . def_nr - - ;
}
BKE_mesh_end_editmesh ( me , em ) ;
2009-01-07 19:23:22 +00:00
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
else if ( ob - > type = = OB_LATTICE ) {
Lattice * lt = vgroup_edit_lattice ( ob ) ;
BPoint * bp ;
MDeformVert * dvert = lt - > dvert ;
int a , tot ;
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( dvert ) {
tot = lt - > pntsu * lt - > pntsv * lt - > pntsw ;
for ( a = 0 , bp = lt - > def ; a < tot ; a + + , bp + + , dvert + + ) {
for ( i = 0 ; i < dvert - > totweight ; i + + ) {
2011-01-21 05:09:32 +00:00
if ( dvert - > dw [ i ] . def_nr > dg_index )
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
dvert - > dw [ i ] . def_nr - - ;
}
}
}
}
2009-01-07 19:23:22 +00:00
2011-01-21 05:09:32 +00:00
vgroup_delete_update_users ( ob , dg_index + 1 ) ;
/* Remove the group */
BLI_freelinkN ( & ob - > defbase , dg ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* Update the active deform index if necessary */
2011-01-21 05:09:32 +00:00
if ( ob - > actdef > dg_index )
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
ob - > actdef - - ;
2011-01-21 05:09:32 +00:00
if ( ob - > actdef < 1 & & ob - > defbase . first )
ob - > actdef = 1 ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* remove all dverts */
2011-01-21 05:09:32 +00:00
if ( ob - > defbase . first = = NULL ) {
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( ob - > type = = OB_MESH ) {
Mesh * me = ob - > data ;
CustomData_free_layer_active ( & me - > vdata , CD_MDEFORMVERT , me - > totvert ) ;
me - > dvert = NULL ;
}
else if ( ob - > type = = OB_LATTICE ) {
Lattice * lt = vgroup_edit_lattice ( ob ) ;
if ( lt - > dvert ) {
MEM_freeN ( lt - > dvert ) ;
lt - > dvert = NULL ;
}
2009-01-07 19:23:22 +00:00
}
}
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
static int vgroup_object_in_edit_mode ( Object * ob )
2009-01-07 19:23:22 +00:00
{
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( ob - > type = = OB_MESH )
return ( ( ( Mesh * ) ob - > data ) - > edit_mesh ! = NULL ) ;
else if ( ob - > type = = OB_LATTICE )
return ( ( ( Lattice * ) ob - > data ) - > editlatt ! = NULL ) ;
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
return 0 ;
}
static void vgroup_delete ( Object * ob )
{
2011-01-07 09:50:23 +00:00
bDeformGroup * dg = BLI_findlink ( & ob - > defbase , ob - > actdef - 1 ) ;
if ( ! dg )
return ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( vgroup_object_in_edit_mode ( ob ) )
2011-01-07 09:50:23 +00:00
vgroup_delete_edit_mode ( ob , dg ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
else
2011-01-07 09:50:23 +00:00
vgroup_delete_object_mode ( ob , dg ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
static void vgroup_delete_all ( Object * ob )
{
/* Remove all DVerts */
if ( ob - > type = = OB_MESH ) {
Mesh * me = ob - > data ;
CustomData_free_layer_active ( & me - > vdata , CD_MDEFORMVERT , me - > totvert ) ;
me - > dvert = NULL ;
}
else if ( ob - > type = = OB_LATTICE ) {
Lattice * lt = vgroup_edit_lattice ( ob ) ;
if ( lt - > dvert ) {
MEM_freeN ( lt - > dvert ) ;
lt - > dvert = NULL ;
}
}
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* Remove all DefGroups */
BLI_freelistN ( & ob - > defbase ) ;
2009-01-07 19:23:22 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* Fix counters/indices */
ob - > actdef = 0 ;
}
/* only in editmode */
static void vgroup_assign_verts ( Object * ob , float weight )
{
EditVert * eve ;
bDeformGroup * dg , * eg ;
MDeformWeight * newdw ;
MDeformVert * dvert ;
int i , done ;
dg = BLI_findlink ( & ob - > defbase , ob - > actdef - 1 ) ;
2009-10-19 17:11:42 +00:00
if ( ! dg )
return ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( ob - > type = = OB_MESH ) {
Mesh * me = ob - > data ;
EditMesh * em = BKE_mesh_get_editmesh ( me ) ;
if ( ! CustomData_has_layer ( & em - > vdata , CD_MDEFORMVERT ) )
2010-08-23 22:16:45 +00:00
EM_add_data_layer ( em , & em - > vdata , CD_MDEFORMVERT , NULL ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* Go through the list of editverts and assign them */
for ( eve = em - > verts . first ; eve ; eve = eve - > next ) {
dvert = CustomData_em_get ( & em - > vdata , eve - > data , CD_MDEFORMVERT ) ;
2010-01-15 17:28:00 +00:00
if ( dvert & & ( eve - > f & SELECT ) ) {
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* See if this vert already has a reference to this group */
/* If so: Change its weight */
done = 0 ;
for ( i = 0 ; i < dvert - > totweight ; i + + ) {
eg = BLI_findlink ( & ob - > defbase , dvert - > dw [ i ] . def_nr ) ;
/* Find the actual group */
if ( eg = = dg ) {
dvert - > dw [ i ] . weight = weight ;
done = 1 ;
break ;
}
2010-03-22 09:30:00 +00:00
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* If not: Add the group and set its weight */
if ( ! done ) {
newdw = MEM_callocN ( sizeof ( MDeformWeight ) * ( dvert - > totweight + 1 ) , " deformWeight " ) ;
if ( dvert - > dw ) {
memcpy ( newdw , dvert - > dw , sizeof ( MDeformWeight ) * dvert - > totweight ) ;
MEM_freeN ( dvert - > dw ) ;
}
dvert - > dw = newdw ;
dvert - > dw [ dvert - > totweight ] . weight = weight ;
dvert - > dw [ dvert - > totweight ] . def_nr = ob - > actdef - 1 ;
dvert - > totweight + + ;
}
}
}
BKE_mesh_end_editmesh ( me , em ) ;
}
else if ( ob - > type = = OB_LATTICE ) {
Lattice * lt = vgroup_edit_lattice ( ob ) ;
BPoint * bp ;
int a , tot ;
if ( lt - > dvert = = NULL )
ED_vgroup_data_create ( & lt - > id ) ;
tot = lt - > pntsu * lt - > pntsv * lt - > pntsw ;
for ( a = 0 , bp = lt - > def ; a < tot ; a + + , bp + + ) {
if ( bp - > f1 & SELECT )
ED_vgroup_nr_vert_add ( ob , ob - > actdef - 1 , a , weight , WEIGHT_REPLACE ) ;
}
2009-01-07 19:23:22 +00:00
}
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* only in editmode */
/* removes from all defgroup, if allverts==0 only selected vertices */
static void vgroup_remove_verts ( Object * ob , int allverts )
2009-01-07 19:23:22 +00:00
{
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* To prevent code redundancy, we just use vgroup_active_remove_verts, but that
* only operates on the active vgroup . So we iterate through all groups , by changing
* active group index
*/
2011-01-21 05:09:32 +00:00
bDeformGroup * dg ;
for ( dg = ob - > defbase . first ; dg ; dg = dg - > next ) {
vgroup_active_remove_verts ( ob , allverts , dg ) ;
}
2009-01-07 19:23:22 +00:00
}
2009-07-01 22:25:49 +00:00
/********************** vertex group operators *********************/
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
static int vertex_group_poll ( bContext * C )
2009-07-01 22:25:49 +00:00
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
ID * data = ( ob ) ? ob - > data : NULL ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
return ( ob & & ! ob - > id . lib & & ELEM ( ob - > type , OB_MESH , OB_LATTICE ) & & data & & ! data - > lib ) ;
}
static int vertex_group_poll_edit ( bContext * C )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
ID * data = ( ob ) ? ob - > data : NULL ;
if ( ! ( ob & & ! ob - > id . lib & & data & & ! data - > lib ) )
return 0 ;
return vgroup_object_in_edit_mode ( ob ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
}
2009-07-01 22:25:49 +00:00
2010-10-15 01:36:14 +00:00
static int vertex_group_add_exec ( bContext * C , wmOperator * UNUSED ( op ) )
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
2009-07-01 22:25:49 +00:00
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
ED_vgroup_add ( ob ) ;
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
WM_event_add_notifier ( C , NC_GEOM | ND_DATA , ob - > data ) ;
WM_event_add_notifier ( C , NC_OBJECT | ND_DRAW , ob ) ;
2009-07-01 22:25:49 +00:00
return OPERATOR_FINISHED ;
}
void OBJECT_OT_vertex_group_add ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Add Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_add " ;
/* api callbacks */
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
ot - > poll = vertex_group_poll ;
2009-07-01 22:25:49 +00:00
ot - > exec = vertex_group_add_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
static int vertex_group_remove_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( RNA_boolean_get ( op - > ptr , " all " ) )
vgroup_delete_all ( ob ) ;
else
vgroup_delete ( ob ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
WM_event_add_notifier ( C , NC_GEOM | ND_DATA , ob - > data ) ;
WM_event_add_notifier ( C , NC_OBJECT | ND_DRAW , ob ) ;
2009-07-01 22:25:49 +00:00
return OPERATOR_FINISHED ;
}
void OBJECT_OT_vertex_group_remove ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Remove Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_remove " ;
/* api callbacks */
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
ot - > poll = vertex_group_poll ;
2009-07-01 22:25:49 +00:00
ot - > exec = vertex_group_remove_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* properties */
RNA_def_boolean ( ot - > srna , " all " , 0 , " All " , " Remove from all vertex groups. " ) ;
2009-07-01 22:25:49 +00:00
}
static int vertex_group_assign_exec ( bContext * C , wmOperator * op )
{
ToolSettings * ts = CTX_data_tool_settings ( C ) ;
Object * ob = CTX_data_edit_object ( C ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
if ( RNA_boolean_get ( op - > ptr , " new " ) )
ED_vgroup_add ( ob ) ;
vgroup_assign_verts ( ob , ts - > vgroup_weight ) ;
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
WM_event_add_notifier ( C , NC_GEOM | ND_DATA , ob - > data ) ;
2009-07-01 22:25:49 +00:00
return OPERATOR_FINISHED ;
}
void OBJECT_OT_vertex_group_assign ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Assign Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_assign " ;
/* api callbacks */
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
ot - > poll = vertex_group_poll_edit ;
2009-07-01 22:25:49 +00:00
ot - > exec = vertex_group_assign_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* properties */
RNA_def_boolean ( ot - > srna , " new " , 0 , " New " , " Assign vertex to new vertex group. " ) ;
2009-07-01 22:25:49 +00:00
}
static int vertex_group_remove_from_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_edit_object ( C ) ;
2010-04-05 11:22:49 +00:00
if ( RNA_boolean_get ( op - > ptr , " all " ) )
vgroup_remove_verts ( ob , 0 ) ;
2011-01-21 05:09:32 +00:00
else {
bDeformGroup * dg = BLI_findlink ( & ob - > defbase , ob - > actdef - 1 ) ;
if ( dg = = NULL ) {
return OPERATOR_CANCELLED ;
}
vgroup_active_remove_verts ( ob , FALSE , dg ) ;
}
2010-04-05 11:22:49 +00:00
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
WM_event_add_notifier ( C , NC_GEOM | ND_DATA , ob - > data ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
2009-07-01 22:25:49 +00:00
return OPERATOR_FINISHED ;
}
void OBJECT_OT_vertex_group_remove_from ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Remove from Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_remove_from " ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
2009-07-01 22:25:49 +00:00
/* api callbacks */
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
ot - > poll = vertex_group_poll_edit ;
2009-07-01 22:25:49 +00:00
ot - > exec = vertex_group_remove_from_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* properties */
RNA_def_boolean ( ot - > srna , " all " , 0 , " All " , " Remove from all vertex groups. " ) ;
2009-07-01 22:25:49 +00:00
}
2010-10-15 01:36:14 +00:00
static int vertex_group_select_exec ( bContext * C , wmOperator * UNUSED ( op ) )
2009-07-01 22:25:49 +00:00
{
Object * ob = CTX_data_edit_object ( C ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
if ( ! ob | | ob - > id . lib )
2009-07-01 22:25:49 +00:00
return OPERATOR_CANCELLED ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
vgroup_select_verts ( ob , 1 ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
WM_event_add_notifier ( C , NC_GEOM | ND_SELECT , ob - > data ) ;
2009-07-01 22:25:49 +00:00
return OPERATOR_FINISHED ;
}
void OBJECT_OT_vertex_group_select ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Select Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_select " ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
2009-07-01 22:25:49 +00:00
/* api callbacks */
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
ot - > poll = vertex_group_poll_edit ;
2009-07-01 22:25:49 +00:00
ot - > exec = vertex_group_select_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
2010-10-15 01:36:14 +00:00
static int vertex_group_deselect_exec ( bContext * C , wmOperator * UNUSED ( op ) )
2009-07-01 22:25:49 +00:00
{
Object * ob = CTX_data_edit_object ( C ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
vgroup_select_verts ( ob , 0 ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
WM_event_add_notifier ( C , NC_GEOM | ND_SELECT , ob - > data ) ;
2009-07-01 22:25:49 +00:00
return OPERATOR_FINISHED ;
}
void OBJECT_OT_vertex_group_deselect ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Deselect Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_deselect " ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
2009-07-01 22:25:49 +00:00
/* api callbacks */
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
ot - > poll = vertex_group_poll_edit ;
2009-07-01 22:25:49 +00:00
ot - > exec = vertex_group_deselect_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
2010-10-15 01:36:14 +00:00
static int vertex_group_copy_exec ( bContext * C , wmOperator * UNUSED ( op ) )
2009-07-01 22:25:49 +00:00
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
vgroup_duplicate ( ob ) ;
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
WM_event_add_notifier ( C , NC_OBJECT | ND_DRAW , ob ) ;
WM_event_add_notifier ( C , NC_GEOM | ND_DATA , ob - > data ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
2009-07-01 22:25:49 +00:00
return OPERATOR_FINISHED ;
}
void OBJECT_OT_vertex_group_copy ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Copy Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_copy " ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
2009-07-01 22:25:49 +00:00
/* api callbacks */
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
ot - > poll = vertex_group_poll ;
2009-07-01 22:25:49 +00:00
ot - > exec = vertex_group_copy_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
2009-11-20 05:09:57 +00:00
static int vertex_group_levels_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
float offset = RNA_float_get ( op - > ptr , " offset " ) ;
float gain = RNA_float_get ( op - > ptr , " gain " ) ;
vgroup_levels ( ob , offset , gain ) ;
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2009-11-20 05:09:57 +00:00
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_levels ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Vertex Group Levels " ;
ot - > idname = " OBJECT_OT_vertex_group_levels " ;
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_levels_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
RNA_def_float ( ot - > srna , " offset " , 0.f , - 1.0 , 1.0 , " Offset " , " Value to add to weights. " , - 1.0f , 1.f ) ;
RNA_def_float ( ot - > srna , " gain " , 1.f , 0.f , FLT_MAX , " Gain " , " Value to multiply weights by. " , 0.0f , 10.f ) ;
}
2009-10-20 10:19:48 +00:00
2010-10-15 01:36:14 +00:00
static int vertex_group_normalize_exec ( bContext * C , wmOperator * UNUSED ( op ) )
2009-10-20 10:19:48 +00:00
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
2009-10-20 13:59:26 +00:00
vgroup_normalize ( ob ) ;
2009-10-20 10:19:48 +00:00
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2009-10-20 10:19:48 +00:00
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_normalize ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Normalize Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_normalize " ;
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_normalize_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2009-10-20 13:59:26 +00:00
}
static int vertex_group_normalize_all_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
int lock_active = RNA_boolean_get ( op - > ptr , " lock_active " ) ;
vgroup_normalize_all ( ob , lock_active ) ;
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2009-10-20 13:59:26 +00:00
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_normalize_all ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Normalize All Vertex Groups " ;
ot - > idname = " OBJECT_OT_vertex_group_normalize_all " ;
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_normalize_all_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
2009-10-20 10:19:48 +00:00
2009-10-20 13:59:26 +00:00
RNA_def_boolean ( ot - > srna , " lock_active " , TRUE , " Lock Active " , " Keep the values of the active group while normalizing others. " ) ;
2009-10-20 10:19:48 +00:00
}
2011-06-02 17:28:04 +00:00
/* Jason was here */
static int vertex_group_invert_locks_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
vgroup_invert_locks ( ob ) ;
return OPERATOR_FINISHED ;
}
/* Jason was here */
void OBJECT_OT_vertex_group_invert_locks ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Invert All Vertex Group Locks " ;
ot - > idname = " OBJECT_OT_vertex_group_invert_locks " ;
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_invert_locks_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
/* Jason was here */
static int vertex_group_lock_all_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
vgroup_lock_all ( ob ) ;
return OPERATOR_FINISHED ;
}
/* Jason was here */
void OBJECT_OT_vertex_group_lock_all ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Turn on all Vertex Group Locks " ;
ot - > idname = " OBJECT_OT_vertex_group_lock_all " ;
2009-10-20 10:19:48 +00:00
2011-06-02 17:28:04 +00:00
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_lock_all_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
/* Jason was here */
static int vertex_group_unlock_all_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
vgroup_unlock_all ( ob ) ;
return OPERATOR_FINISHED ;
}
/* Jason was here */
void OBJECT_OT_vertex_group_unlock_all ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Turn off all Vertex Group Locks " ;
ot - > idname = " OBJECT_OT_vertex_group_unlock_all " ;
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_unlock_all_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
2009-10-20 10:19:48 +00:00
static int vertex_group_invert_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
int auto_assign = RNA_boolean_get ( op - > ptr , " auto_assign " ) ;
int auto_remove = RNA_boolean_get ( op - > ptr , " auto_remove " ) ;
vgroup_invert ( ob , auto_assign , auto_remove ) ;
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2009-10-20 10:19:48 +00:00
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_invert ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Invert Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_invert " ;
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_invert_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
RNA_def_boolean ( ot - > srna , " auto_assign " , TRUE , " Add Weights " , " Add verts from groups that have zero weight before inverting. " ) ;
RNA_def_boolean ( ot - > srna , " auto_remove " , TRUE , " Remove Weights " , " Remove verts from groups that have zero weight after inverting. " ) ;
}
2009-10-20 16:31:03 +00:00
2010-10-15 01:36:14 +00:00
static int vertex_group_blend_exec ( bContext * C , wmOperator * UNUSED ( op ) )
2009-10-20 16:31:03 +00:00
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
vgroup_blend ( ob ) ;
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2009-10-20 16:31:03 +00:00
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_blend ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Blend Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_blend " ;
2009-11-19 23:39:19 +00:00
ot - > description = " " ;
2009-10-20 16:31:03 +00:00
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_blend_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
2009-10-20 10:19:48 +00:00
static int vertex_group_clean_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
float limit = RNA_float_get ( op - > ptr , " limit " ) ;
int all_groups = RNA_boolean_get ( op - > ptr , " all_groups " ) ;
int keep_single = RNA_boolean_get ( op - > ptr , " keep_single " ) ;
if ( all_groups ) vgroup_clean_all ( ob , limit , keep_single ) ;
else vgroup_clean ( ob , limit , keep_single ) ;
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2009-10-20 10:19:48 +00:00
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_clean ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Clean Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_clean " ;
2010-02-10 21:15:44 +00:00
ot - > description = " Remove Vertex Group assignments which aren't required " ;
2009-10-20 10:19:48 +00:00
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_clean_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
RNA_def_float ( ot - > srna , " limit " , 0.01f , 0.0f , 1.0 , " Limit " , " Remove weights under this limit. " , 0.001f , 0.99f ) ;
RNA_def_boolean ( ot - > srna , " all_groups " , FALSE , " All Groups " , " Clean all vertex groups. " ) ;
RNA_def_boolean ( ot - > srna , " keep_single " , FALSE , " Keep Single " , " Keep verts assigned to at least one group when cleaning. " ) ;
}
2010-01-15 17:28:00 +00:00
static int vertex_group_mirror_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
2010-01-25 23:12:02 +00:00
ED_vgroup_mirror ( ob , RNA_boolean_get ( op - > ptr , " mirror_weights " ) , RNA_boolean_get ( op - > ptr , " flip_group_names " ) ) ;
2010-01-15 17:28:00 +00:00
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2010-01-15 17:28:00 +00:00
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_mirror ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Mirror Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_mirror " ;
2010-12-09 06:08:19 +00:00
ot - > description = " Mirror all vertex groups, flip weights and/or names, editing only selected vertices, flipping when both sides are selected otherwise copy from unselected " ;
2010-01-15 17:28:00 +00:00
/* api callbacks */
ot - > poll = vertex_group_poll_edit ;
ot - > exec = vertex_group_mirror_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
/* properties */
RNA_def_boolean ( ot - > srna , " mirror_weights " , TRUE , " Mirror Weights " , " Mirror weights. " ) ;
2010-12-09 06:08:19 +00:00
RNA_def_boolean ( ot - > srna , " flip_group_names " , TRUE , " Flip Groups " , " Flip vertex group names. " ) ;
2010-01-15 17:28:00 +00:00
}
2010-10-15 01:36:14 +00:00
static int vertex_group_copy_to_linked_exec ( bContext * C , wmOperator * UNUSED ( op ) )
2009-07-01 22:25:49 +00:00
{
Scene * scene = CTX_data_scene ( C ) ;
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
Base * base ;
2009-07-01 22:25:49 +00:00
int retval = OPERATOR_CANCELLED ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
for ( base = scene - > base . first ; base ; base = base - > next ) {
if ( base - > object - > type = = ob - > type ) {
if ( base - > object ! = ob & & base - > object - > data = = ob - > data ) {
BLI_freelistN ( & base - > object - > defbase ) ;
BLI_duplicatelist ( & base - > object - > defbase , & ob - > defbase ) ;
base - > object - > actdef = ob - > actdef ;
2009-07-01 22:25:49 +00:00
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & base - > object - > id , OB_RECALC_DATA ) ;
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
WM_event_add_notifier ( C , NC_OBJECT | ND_DRAW , base - > object ) ;
WM_event_add_notifier ( C , NC_GEOM | ND_DATA , base - > object - > data ) ;
2009-07-01 22:25:49 +00:00
retval = OPERATOR_FINISHED ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
}
}
}
2009-07-01 22:25:49 +00:00
return retval ;
}
void OBJECT_OT_vertex_group_copy_to_linked ( wmOperatorType * ot )
{
/* identifiers */
2010-02-09 22:00:19 +00:00
ot - > name = " Copy Vertex Groups to Linked " ;
2009-07-01 22:25:49 +00:00
ot - > idname = " OBJECT_OT_vertex_group_copy_to_linked " ;
2010-02-10 21:15:44 +00:00
ot - > description = " Copy Vertex Groups to all users of the same Geometry data " ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
2009-07-01 22:25:49 +00:00
/* api callbacks */
2.5
Notifiers
---------
Various fixes for wrong use of notifiers, and some new notifiers
to make things a bit more clear and consistent, with two notable
changes:
* Geometry changes are now done with NC_GEOM, rather than
NC_OBJECT|ND_GEOM_, so an object does need to be available.
* Space data now use NC_SPACE|ND_SPACE_*, instead of data
notifiers or even NC_WINDOW in some cases. Note that NC_SPACE
should only be used for notifying about changes in space data,
we don't want to go back to allqueue(REDRAW..).
Depsgraph
---------
The dependency graph now has a different flush call:
DAG_object_flush_update(scene, ob, flag)
is replaced by:
DAG_id_flush_update(id, flag)
It still works basically the same, one difference is that it now
also accepts object data (e.g. Mesh), again to avoid requiring an
Object to be available. Other ID types will simply do nothing at
the moment.
Docs
----
I made some guidelines for how/when to do which kinds of updates
and notifiers. I can't specify totally exact how to make these
decisions, but these are basically the guidelines I use. So, new
and updated docs are here:
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/NotifiersUpdates
http://wiki.blender.org/index.php/BlenderDev/Blender2.5/DataNotifiers
2009-09-04 20:51:09 +00:00
ot - > poll = vertex_group_poll ;
2009-07-01 22:25:49 +00:00
ot - > exec = vertex_group_copy_to_linked_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
2009-01-07 19:23:22 +00:00
2011-06-07 18:04:03 +00:00
static int vertex_group_copy_to_selected_exec ( bContext * C , wmOperator * op )
2010-02-09 22:00:19 +00:00
{
Object * obact = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
2011-06-07 18:04:03 +00:00
int change = 0 ;
int fail = 0 ;
2010-02-09 22:00:19 +00:00
CTX_DATA_BEGIN ( C , Object * , ob , selected_editable_objects )
{
2011-06-07 18:04:03 +00:00
if ( obact ! = ob ) {
if ( ED_vgroup_copy_array ( ob , obact ) ) change + + ;
else fail + + ;
}
2010-02-09 22:00:19 +00:00
}
CTX_DATA_END ;
2011-06-07 18:04:03 +00:00
if ( ( change = = 0 & & fail = = 0 ) | | fail ) {
BKE_reportf ( op - > reports , RPT_ERROR , " Copy to VGroups to Selected warning done %d, failed %d, object data must have matching indicies " , change , fail ) ;
}
2010-02-09 22:00:19 +00:00
return OPERATOR_FINISHED ;
}
void OBJECT_OT_vertex_group_copy_to_selected ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Copy Vertex Group to Selected " ;
ot - > idname = " OBJECT_OT_vertex_group_copy_to_selected " ;
2011-01-18 01:58:19 +00:00
ot - > description = " Copy Vertex Groups to other selected objects with matching indices " ;
2010-02-09 22:00:19 +00:00
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_copy_to_selected_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
static EnumPropertyItem vgroup_items [ ] = {
{ 0 , NULL , 0 , NULL , NULL } } ;
static int set_active_group_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
int nr = RNA_enum_get ( op - > ptr , " group " ) ;
ob - > actdef = nr + 1 ;
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2009-12-17 06:06:30 +00:00
WM_event_add_notifier ( C , NC_GEOM | ND_DATA , ob ) ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
return OPERATOR_FINISHED ;
}
2011-05-26 13:38:16 +00:00
static EnumPropertyItem * vgroup_itemf ( bContext * C , PointerRNA * UNUSED ( ptr ) , PropertyRNA * UNUSED ( prop ) , int * free )
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
{
2009-10-14 19:19:43 +00:00
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
EnumPropertyItem tmp = { 0 , " " , 0 , " " , " " } ;
EnumPropertyItem * item = NULL ;
bDeformGroup * def ;
int a , totitem = 0 ;
2009-10-14 19:19:43 +00:00
if ( ! ob )
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
return vgroup_items ;
for ( a = 0 , def = ob - > defbase . first ; def ; def = def - > next , a + + ) {
tmp . value = a ;
2009-11-22 06:20:56 +00:00
tmp . icon = ICON_GROUP_VERTEX ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
tmp . identifier = def - > name ;
tmp . name = def - > name ;
RNA_enum_item_add ( & item , & totitem , & tmp ) ;
}
RNA_enum_item_end ( & item , & totitem ) ;
* free = 1 ;
return item ;
}
void OBJECT_OT_vertex_group_set_active ( wmOperatorType * ot )
{
PropertyRNA * prop ;
/* identifiers */
ot - > name = " Set Active Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_set_active " ;
2010-02-10 21:15:44 +00:00
ot - > description = " Set the active vertex group " ;
2.5: Object module
* Split object_edit.c into multiple files:
object_add.c, object_edit.c, object_hook.c, object_relations.c,
object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
* vertex group menu and set active
* apply location, rotation, scale, visual transform (location is new)
* make local
* make vertex parent
* move to layer
* convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
up here...
2009-09-09 11:52:56 +00:00
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = set_active_group_exec ;
ot - > invoke = WM_menu_invoke ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
/* properties */
prop = RNA_def_enum ( ot - > srna , " group " , vgroup_items , 0 , " Group " , " Vertex group to set as active. " ) ;
RNA_def_enum_funcs ( prop , vgroup_itemf ) ;
2010-01-15 22:40:33 +00:00
ot - > prop = prop ;
2009-11-25 09:25:58 +00:00
}
2010-05-04 12:31:24 +00:00
/*creates the name_array parameter for vgroup_do_remap, call this before fiddling
with the order of vgroups then call vgroup_do_remap after */
static char * vgroup_init_remap ( Object * ob )
2010-02-02 21:43:26 +00:00
{
2010-05-04 12:31:24 +00:00
bDeformGroup * def ;
int def_tot = BLI_countlist ( & ob - > defbase ) ;
char * name_array = MEM_mallocN ( MAX_VGROUP_NAME * sizeof ( char ) * def_tot , " sort vgroups " ) ;
char * name ;
2010-02-02 21:43:26 +00:00
2010-05-04 12:31:24 +00:00
name = name_array ;
for ( def = ob - > defbase . first ; def ; def = def - > next ) {
BLI_strncpy ( name , def - > name , MAX_VGROUP_NAME ) ;
name + = MAX_VGROUP_NAME ;
}
return name_array ;
2010-02-02 21:43:26 +00:00
}
2010-05-04 12:31:24 +00:00
static int vgroup_do_remap ( Object * ob , char * name_array , wmOperator * op )
2010-02-02 21:43:26 +00:00
{
2010-05-04 12:31:24 +00:00
MDeformVert * dvert = NULL ;
2010-02-02 21:43:26 +00:00
bDeformGroup * def ;
int def_tot = BLI_countlist ( & ob - > defbase ) ;
2010-05-04 12:31:24 +00:00
int * sort_map_update = MEM_mallocN ( MAX_VGROUP_NAME * sizeof ( int ) * def_tot + 1 , " sort vgroups " ) ; /* needs a dummy index at the start*/
2010-02-02 21:43:26 +00:00
int * sort_map = sort_map_update + 1 ;
2010-05-04 12:31:24 +00:00
char * name ;
2010-02-02 21:43:26 +00:00
int i ;
name = name_array ;
for ( def = ob - > defbase . first , i = 0 ; def ; def = def - > next , i + + ) {
sort_map [ i ] = BLI_findstringindex ( & ob - > defbase , name , offsetof ( bDeformGroup , name ) ) ;
2010-05-04 12:31:24 +00:00
name + = MAX_VGROUP_NAME ;
2010-02-02 21:43:26 +00:00
}
2010-02-17 22:26:50 +00:00
if ( ob - > mode = = OB_MODE_EDIT ) {
if ( ob - > type = = OB_MESH ) {
EditMesh * em = BKE_mesh_get_editmesh ( ob - > data ) ;
EditVert * eve ;
for ( eve = em - > verts . first ; eve ; eve = eve - > next ) {
dvert = CustomData_em_get ( & em - > vdata , eve - > data , CD_MDEFORMVERT ) ;
if ( dvert & & dvert - > totweight ) {
defvert_remap ( dvert , sort_map ) ;
}
}
}
else {
BKE_report ( op - > reports , RPT_ERROR , " Editmode lattice isnt supported yet. " ) ;
2011-03-22 11:19:02 +00:00
MEM_freeN ( sort_map_update ) ;
2010-02-17 22:26:50 +00:00
return OPERATOR_CANCELLED ;
}
}
else {
2010-05-04 12:31:24 +00:00
int dvert_tot = 0 ;
2010-02-17 22:26:50 +00:00
ED_vgroup_give_array ( ob - > data , & dvert , & dvert_tot ) ;
2010-05-04 12:31:24 +00:00
/*create as necassary*/
while ( dvert & & dvert_tot - - ) {
2010-02-17 22:26:50 +00:00
if ( dvert - > totweight )
defvert_remap ( dvert , sort_map ) ;
dvert + + ;
}
2010-02-02 21:43:26 +00:00
}
/* update users */
for ( i = 0 ; i < def_tot ; i + + )
sort_map [ i ] + + ;
sort_map_update [ 0 ] = 0 ;
vgroup_remap_update_users ( ob , sort_map_update ) ;
2010-02-17 22:26:50 +00:00
ob - > actdef = sort_map_update [ ob - > actdef ] ;
2010-09-20 13:10:53 +00:00
MEM_freeN ( sort_map_update ) ;
2010-02-17 22:26:50 +00:00
2010-05-04 12:31:24 +00:00
return OPERATOR_FINISHED ;
}
2010-02-02 21:43:26 +00:00
2010-05-04 12:31:24 +00:00
static int vgroup_sort ( void * def_a_ptr , void * def_b_ptr )
{
bDeformGroup * def_a = ( bDeformGroup * ) def_a_ptr ;
bDeformGroup * def_b = ( bDeformGroup * ) def_b_ptr ;
2010-02-02 21:43:26 +00:00
2010-09-25 21:09:58 +00:00
return BLI_natstrcmp ( def_a - > name , def_b - > name ) ;
2010-02-02 21:43:26 +00:00
}
2010-05-04 12:31:24 +00:00
static int vertex_group_sort_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
char * name_array ;
int ret ;
/*init remapping*/
name_array = vgroup_init_remap ( ob ) ;
/*sort vgroup names*/
BLI_sortlist ( & ob - > defbase , vgroup_sort ) ;
/*remap vgroup data to map to correct names*/
ret = vgroup_do_remap ( ob , name_array , op ) ;
if ( ret ! = OPERATOR_CANCELLED ) {
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2010-05-04 12:31:24 +00:00
WM_event_add_notifier ( C , NC_GEOM | ND_DATA , ob ) ;
}
if ( name_array ) MEM_freeN ( name_array ) ;
return ret ;
}
2010-02-02 21:43:26 +00:00
void OBJECT_OT_vertex_group_sort ( wmOperatorType * ot )
{
ot - > name = " Sort Vertex Groups " ;
ot - > idname = " OBJECT_OT_vertex_group_sort " ;
2010-02-10 21:15:44 +00:00
ot - > description = " Sorts vertex groups alphabetically " ;
2010-02-02 21:43:26 +00:00
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vertex_group_sort_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
2010-05-04 12:31:24 +00:00
static int vgroup_move_exec ( bContext * C , wmOperator * op )
{
Object * ob = CTX_data_pointer_get_type ( C , " object " , & RNA_Object ) . data ;
bDeformGroup * def ;
char * name_array ;
int dir = RNA_enum_get ( op - > ptr , " direction " ) , ret ;
def = BLI_findlink ( & ob - > defbase , ob - > actdef - 1 ) ;
if ( ! def ) {
return OPERATOR_CANCELLED ;
}
name_array = vgroup_init_remap ( ob ) ;
if ( dir = = 1 ) { /*up*/
void * prev = def - > prev ;
BLI_remlink ( & ob - > defbase , def ) ;
BLI_insertlinkbefore ( & ob - > defbase , prev , def ) ;
} else { /*down*/
void * next = def - > next ;
BLI_remlink ( & ob - > defbase , def ) ;
BLI_insertlinkafter ( & ob - > defbase , next , def ) ;
}
ret = vgroup_do_remap ( ob , name_array , op ) ;
if ( name_array ) MEM_freeN ( name_array ) ;
if ( ret ! = OPERATOR_CANCELLED ) {
2010-12-05 18:59:23 +00:00
DAG_id_tag_update ( & ob - > id , OB_RECALC_DATA ) ;
2010-05-04 12:31:24 +00:00
WM_event_add_notifier ( C , NC_GEOM | ND_DATA , ob ) ;
}
return ret ;
}
void OBJECT_OT_vertex_group_move ( wmOperatorType * ot )
{
static EnumPropertyItem vgroup_slot_move [ ] = {
{ 1 , " UP " , 0 , " Up " , " " } ,
{ - 1 , " DOWN " , 0 , " Down " , " " } ,
{ 0 , NULL , 0 , NULL , NULL }
} ;
/* identifiers */
ot - > name = " Move Vertex Group " ;
ot - > idname = " OBJECT_OT_vertex_group_move " ;
/* api callbacks */
ot - > poll = vertex_group_poll ;
ot - > exec = vgroup_move_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
RNA_def_enum ( ot - > srna , " direction " , vgroup_slot_move , 0 , " Direction " , " Direction to move, UP or DOWN " ) ;
}