Blender  V2.93
Functions
deform.c File Reference
#include <ctype.h>
#include <math.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_string.h"
#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "BKE_customdata.h"
#include "BKE_data_transfer.h"
#include "BKE_deform.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_object.h"
#include "BKE_object_deform.h"
#include "BLO_read_write.h"
#include "data_transfer_intern.h"

Go to the source code of this file.

Functions

bDeformGroupBKE_object_defgroup_new (Object *ob, const char *name)
 
void BKE_defgroup_copy_list (ListBase *outbase, const ListBase *inbase)
 
bDeformGroupBKE_defgroup_duplicate (const bDeformGroup *ingroup)
 
void BKE_defvert_copy_subset (MDeformVert *dvert_dst, const MDeformVert *dvert_src, const bool *vgroup_subset, const int vgroup_tot)
 
void BKE_defvert_mirror_subset (MDeformVert *dvert_dst, const MDeformVert *dvert_src, const bool *vgroup_subset, const int vgroup_tot, const int *flip_map, const int flip_map_len)
 
void BKE_defvert_copy (MDeformVert *dvert_dst, const MDeformVert *dvert_src)
 
void BKE_defvert_copy_index (MDeformVert *dvert_dst, const int defgroup_dst, const MDeformVert *dvert_src, const int defgroup_src)
 
void BKE_defvert_sync (MDeformVert *dvert_dst, const MDeformVert *dvert_src, const bool use_ensure)
 
void BKE_defvert_sync_mapped (MDeformVert *dvert_dst, const MDeformVert *dvert_src, const int *flip_map, const int flip_map_len, const bool use_ensure)
 
void BKE_defvert_remap (MDeformVert *dvert, const int *map, const int map_len)
 
void BKE_defvert_normalize_subset (MDeformVert *dvert, const bool *vgroup_subset, const int vgroup_tot)
 
void BKE_defvert_normalize (MDeformVert *dvert)
 
void BKE_defvert_normalize_lock_single (MDeformVert *dvert, const bool *vgroup_subset, const int vgroup_tot, const uint def_nr_lock)
 
void BKE_defvert_normalize_lock_map (MDeformVert *dvert, const bool *vgroup_subset, const int vgroup_tot, const bool *lock_flags, const int defbase_tot)
 
void BKE_defvert_flip (MDeformVert *dvert, const int *flip_map, const int flip_map_len)
 
void BKE_defvert_flip_merged (MDeformVert *dvert, const int *flip_map, const int flip_map_len)
 
bDeformGroupBKE_object_defgroup_find_name (const Object *ob, const char *name)
 
int BKE_object_defgroup_name_index (const Object *ob, const char *name)
 
int * BKE_object_defgroup_flip_map (const Object *ob, int *flip_map_len, const bool use_default)
 
int * BKE_object_defgroup_flip_map_single (const Object *ob, int *flip_map_len, const bool use_default, int defgroup)
 
int BKE_object_defgroup_flip_index (const Object *ob, int index, const bool use_default)
 
static bool defgroup_find_name_dupe (const char *name, bDeformGroup *dg, Object *ob)
 
static bool defgroup_unique_check (void *arg, const char *name)
 
void BKE_object_defgroup_unique_name (bDeformGroup *dg, Object *ob)
 
float BKE_defvert_find_weight (const struct MDeformVert *dvert, const int defgroup)
 
float BKE_defvert_array_find_weight_safe (const struct MDeformVert *dvert, const int index, const int defgroup)
 
MDeformWeightBKE_defvert_find_index (const MDeformVert *dvert, const int defgroup)
 
MDeformWeightBKE_defvert_ensure_index (MDeformVert *dvert, const int defgroup)
 
void BKE_defvert_add_index_notest (MDeformVert *dvert, int defgroup, const float weight)
 
void BKE_defvert_remove_group (MDeformVert *dvert, MDeformWeight *dw)
 
void BKE_defvert_clear (MDeformVert *dvert)
 
int BKE_defvert_find_shared (const MDeformVert *dvert_a, const MDeformVert *dvert_b)
 
bool BKE_defvert_is_weight_zero (const struct MDeformVert *dvert, const int defgroup_tot)
 
float BKE_defvert_total_selected_weight (const struct MDeformVert *dv, int defbase_tot, const bool *defbase_sel)
 
float BKE_defvert_multipaint_collective_weight (const struct MDeformVert *dv, int defbase_tot, const bool *defbase_sel, int defbase_tot_sel, bool is_normalized)
 
float BKE_defvert_calc_lock_relative_weight (float weight, float locked_weight, float unlocked_weight)
 
float BKE_defvert_lock_relative_weight (float weight, const struct MDeformVert *dv, int defbase_tot, const bool *defbase_locked, const bool *defbase_unlocked)
 
Defvert Array functions
void BKE_defvert_array_copy (MDeformVert *dst, const MDeformVert *src, int totvert)
 
void BKE_defvert_array_free_elems (MDeformVert *dvert, int totvert)
 
void BKE_defvert_array_free (MDeformVert *dvert, int totvert)
 
void BKE_defvert_extract_vgroup_to_vertweights (MDeformVert *dvert, const int defgroup, const int num_verts, float *r_weights, const bool invert_vgroup)
 
void BKE_defvert_extract_vgroup_to_edgeweights (MDeformVert *dvert, const int defgroup, const int num_verts, MEdge *edges, const int num_edges, float *r_weights, const bool invert_vgroup)
 
void BKE_defvert_extract_vgroup_to_loopweights (MDeformVert *dvert, const int defgroup, const int num_verts, MLoop *loops, const int num_loops, float *r_weights, const bool invert_vgroup)
 
void BKE_defvert_extract_vgroup_to_polyweights (MDeformVert *dvert, const int defgroup, const int num_verts, MLoop *loops, const int UNUSED(num_loops), MPoly *polys, const int num_polys, float *r_weights, const bool invert_vgroup)
 
Data Transfer
static void vgroups_datatransfer_interp (const CustomDataTransferLayerMap *laymap, void *dest, const void **sources, const float *weights, const int count, const float mix_factor)
 
static bool data_transfer_layersmapping_vgroups_multisrc_to_dst (ListBase *r_map, const int mix_mode, const float mix_factor, const float *mix_weights, const int num_elem_dst, const bool use_create, const bool use_delete, Object *ob_src, Object *ob_dst, MDeformVert *data_src, MDeformVert *data_dst, CustomData *UNUSED(cd_src), CustomData *cd_dst, const bool UNUSED(use_dupref_dst), const int tolayers, const bool *use_layers_src, const int num_layers_src)
 
bool data_transfer_layersmapping_vgroups (ListBase *r_map, const int mix_mode, const float mix_factor, const float *mix_weights, const int num_elem_dst, const bool use_create, const bool use_delete, Object *ob_src, Object *ob_dst, CustomData *cd_src, CustomData *cd_dst, const bool use_dupref_dst, const int fromlayers, const int tolayers)
 
Various utils & helpers.
void BKE_defvert_weight_to_rgb (float r_rgb[3], const float weight)
 
.blend file I/O
void BKE_defvert_blend_write (BlendWriter *writer, int count, MDeformVert *dvlist)
 
void BKE_defvert_blend_read (BlendDataReader *reader, int count, MDeformVert *mdverts)
 

Function Documentation

◆ BKE_defgroup_copy_list()

void BKE_defgroup_copy_list ( ListBase outbase,
const ListBase inbase 
)

◆ BKE_defgroup_duplicate()

bDeformGroup* BKE_defgroup_duplicate ( const bDeformGroup ingroup)

Definition at line 87 of file deform.c.

References BLI_assert, MEM_callocN, bDeformGroup::next, NULL, and bDeformGroup::prev.

Referenced by BKE_defgroup_copy_list().

◆ BKE_defvert_add_index_notest()

void BKE_defvert_add_index_notest ( MDeformVert dvert,
int  defgroup,
const float  weight 
)

Adds the given vertex to the specified vertex group, with given weight.

Warning
this does NOT check for existing, assume caller already knows its not there.

Definition at line 726 of file deform.c.

References BLI_assert, MDeformWeight::def_nr, MDeformVert::dw, MEM_callocN, MEM_freeN, MDeformVert::totweight, and MDeformWeight::weight.

Referenced by ED_vgroup_nr_vert_add(), gpencil_vertex_group_invert_exec(), subdivide_base(), vgroups_datatransfer_interp(), and weightvg_update_vg().

◆ BKE_defvert_array_copy()

void BKE_defvert_array_copy ( MDeformVert dst,
const MDeformVert src,
int  totvert 
)

Definition at line 941 of file deform.c.

References MDeformVert::dw, and MEM_mallocN.

◆ BKE_defvert_array_find_weight_safe()

float BKE_defvert_array_find_weight_safe ( const struct MDeformVert dvert,
const int  index,
const int  defgroup 
)

Take care with this the rationale is:

  • if the object has no vertex group. act like vertex group isn't set and return 1.0,
  • if the vertex group exists but the 'defgroup' isn't found on this vertex, still return 0.0

This is a bit confusing, just saves some checks from the caller.

Definition at line 645 of file deform.c.

References BKE_defvert_find_weight(), and NULL.

Referenced by modifyMesh(), shrinkwrap_calc_nearest_surface_point_cb_ex(), shrinkwrap_calc_nearest_vertex_cb_ex(), shrinkwrap_calc_normal_projection_cb_ex(), and SimpleDeformModifier_do().

◆ BKE_defvert_array_free()

void BKE_defvert_array_free ( MDeformVert dvert,
int  totvert 
)

◆ BKE_defvert_array_free_elems()

void BKE_defvert_array_free_elems ( MDeformVert dvert,
int  totvert 
)

◆ BKE_defvert_blend_read()

void BKE_defvert_blend_read ( BlendDataReader reader,
int  count,
MDeformVert mdverts 
)

◆ BKE_defvert_blend_write()

void BKE_defvert_blend_write ( BlendWriter writer,
int  count,
MDeformVert dvlist 
)

Definition at line 1525 of file deform.c.

References BLO_write_struct_array, count, and NULL.

Referenced by CustomData_blend_write(), greasepencil_blend_write(), and lattice_blend_write().

◆ BKE_defvert_calc_lock_relative_weight()

float BKE_defvert_calc_lock_relative_weight ( float  weight,
float  locked_weight,
float  unlocked_weight 
)

Computes the display weight for the lock relative weight paint mode.

Returns
weight divided by 1-locked_weight with division by zero check

Definition at line 887 of file deform.c.

References VERTEX_WEIGHT_LOCK_EPSILON.

Referenced by BKE_defvert_lock_relative_weight(), do_weight_paint_vertex_multi(), and do_weight_paint_vertex_single().

◆ BKE_defvert_clear()

void BKE_defvert_clear ( MDeformVert dvert)

Definition at line 785 of file deform.c.

References MDeformVert::dw, MEM_freeN, NULL, and MDeformVert::totweight.

Referenced by bpy_bmdeformvert_clear().

◆ BKE_defvert_copy()

void BKE_defvert_copy ( MDeformVert dvert_dst,
const MDeformVert dvert_src 
)

Definition at line 144 of file deform.c.

References MDeformVert::dw, MEM_dupallocN, MEM_freeN, NULL, and MDeformVert::totweight.

◆ BKE_defvert_copy_index()

void BKE_defvert_copy_index ( MDeformVert dvert_dst,
const int  defgroup_dst,
const MDeformVert dvert_src,
const int  defgroup_src 
)

Copy an index from one dvert to another.

  • do nothing if neither are set.
  • add destination weight if needed.

Definition at line 172 of file deform.c.

References BKE_defvert_ensure_index(), BKE_defvert_find_index(), and MDeformWeight::weight.

Referenced by BKE_defvert_copy_subset(), and BKE_defvert_mirror_subset().

◆ BKE_defvert_copy_subset()

void BKE_defvert_copy_subset ( MDeformVert dvert_dst,
const MDeformVert dvert_src,
const bool *  vgroup_subset,
const int  vgroup_tot 
)

Overwrite weights filtered by vgroup_subset.

  • do nothing if neither are set.
  • add destination weight if needed

Definition at line 111 of file deform.c.

References BKE_defvert_copy_index().

◆ BKE_defvert_ensure_index()

MDeformWeight* BKE_defvert_ensure_index ( MDeformVert dvert,
const int  defgroup 
)

◆ BKE_defvert_extract_vgroup_to_edgeweights()

void BKE_defvert_extract_vgroup_to_edgeweights ( MDeformVert dvert,
const int  defgroup,
const int  num_verts,
MEdge edges,
const int  num_edges,
float r_weights,
const bool  invert_vgroup 
)

The following three make basic interpolation, using temp vert_weights array to avoid looking up same weight several times.

Definition at line 1015 of file deform.c.

References BKE_defvert_extract_vgroup_to_vertweights(), copy_vn_fl(), MEM_freeN, MEM_mallocN, MEdge::v1, and MEdge::v2.

Referenced by BKE_object_data_transfer_ex().

◆ BKE_defvert_extract_vgroup_to_loopweights()

void BKE_defvert_extract_vgroup_to_loopweights ( MDeformVert dvert,
const int  defgroup,
const int  num_verts,
MLoop loops,
const int  num_loops,
float r_weights,
const bool  invert_vgroup 
)

◆ BKE_defvert_extract_vgroup_to_polyweights()

void BKE_defvert_extract_vgroup_to_polyweights ( MDeformVert dvert,
const int  defgroup,
const int  num_verts,
MLoop loops,
const int   UNUSEDnum_loops,
MPoly polys,
const int  num_polys,
float r_weights,
const bool  invert_vgroup 
)

◆ BKE_defvert_extract_vgroup_to_vertweights()

void BKE_defvert_extract_vgroup_to_vertweights ( MDeformVert dvert,
const int  defgroup,
const int  num_verts,
float r_weights,
const bool  invert_vgroup 
)

◆ BKE_defvert_find_index()

MDeformWeight* BKE_defvert_find_index ( const MDeformVert dvert,
const int  defgroup 
)

◆ BKE_defvert_find_shared()

int BKE_defvert_find_shared ( const MDeformVert dvert_a,
const MDeformVert dvert_b 
)
Returns
The first group index shared by both deform verts or -1 if none are found.

Definition at line 799 of file deform.c.

References BKE_defvert_find_weight(), MDeformWeight::def_nr, MDeformVert::dw, MDeformVert::totweight, and MDeformWeight::weight.

◆ BKE_defvert_find_weight()

float BKE_defvert_find_weight ( const struct MDeformVert dvert,
const int  defgroup 
)

◆ BKE_defvert_flip()

void BKE_defvert_flip ( MDeformVert dvert,
const int *  flip_map,
const int  flip_map_len 
)

◆ BKE_defvert_flip_merged()

void BKE_defvert_flip_merged ( MDeformVert dvert,
const int *  flip_map,
const int  flip_map_len 
)

◆ BKE_defvert_is_weight_zero()

bool BKE_defvert_is_weight_zero ( const struct MDeformVert dvert,
const int  defgroup_tot 
)

return true if has no weights

Definition at line 818 of file deform.c.

References MDeformWeight::def_nr, MDeformVert::dw, LIKELY, MDeformVert::totweight, and MDeformWeight::weight.

Referenced by evaluate_vertex_weight().

◆ BKE_defvert_lock_relative_weight()

float BKE_defvert_lock_relative_weight ( float  weight,
const struct MDeformVert dv,
int  defbase_tot,
const bool *  defbase_locked,
const bool *  defbase_unlocked 
)

Computes the display weight for the lock relative weight paint mode, using weight data.

Returns
weight divided by unlocked, or 1-locked_weight with division by zero check.

Definition at line 920 of file deform.c.

References BKE_defvert_calc_lock_relative_weight(), and BKE_defvert_total_selected_weight().

Referenced by do_weight_paint_vertex_multi(), do_weight_paint_vertex_single(), evaluate_vertex_weight(), weight_sample_invoke(), and wpaint_get_active_weight().

◆ BKE_defvert_mirror_subset()

void BKE_defvert_mirror_subset ( MDeformVert dvert_dst,
const MDeformVert dvert_src,
const bool *  vgroup_subset,
const int  vgroup_tot,
const int *  flip_map,
const int  flip_map_len 
)

Overwrite weights filtered by vgroup_subset and with mirroring specified by the flip map

  • do nothing if neither are set.
  • add destination weight if needed

Definition at line 129 of file deform.c.

References BKE_defvert_copy_index().

◆ BKE_defvert_multipaint_collective_weight()

float BKE_defvert_multipaint_collective_weight ( const struct MDeformVert dv,
int  defbase_tot,
const bool *  defbase_sel,
int  defbase_tot_sel,
bool  is_normalized 
)
Returns
The representative weight of a multipaint group, used for viewport colors and actual painting.

Result equal to sum of weights with auto normalize, and average otherwise. Value is not clamped, since painting relies on multiplication being always commutative with the collective weight function.

Definition at line 865 of file deform.c.

References BKE_defvert_total_selected_weight().

Referenced by do_weight_paint_vertex_multi(), evaluate_vertex_weight(), weight_sample_invoke(), and wpaint_get_active_weight().

◆ BKE_defvert_normalize()

void BKE_defvert_normalize ( MDeformVert dvert)

Definition at line 304 of file deform.c.

References CLAMP, MDeformVert::dw, MDeformVert::totweight, and MDeformWeight::weight.

◆ BKE_defvert_normalize_lock_map()

void BKE_defvert_normalize_lock_map ( MDeformVert dvert,
const bool *  vgroup_subset,
const int  vgroup_tot,
const bool *  lock_flags,
const int  defbase_tot 
)

Same as BKE_defvert_normalize() if no locked vgroup is a member of the subset

Definition at line 393 of file deform.c.

References CLAMP, MDeformWeight::def_nr, MDeformVert::dw, max_ff(), MDeformVert::totweight, and MDeformWeight::weight.

Referenced by vgroup_normalize_all().

◆ BKE_defvert_normalize_lock_single()

void BKE_defvert_normalize_lock_single ( MDeformVert dvert,
const bool *  vgroup_subset,
const int  vgroup_tot,
const uint  def_nr_lock 
)

Same as BKE_defvert_normalize() if the locked vgroup is not a member of the subset

Definition at line 336 of file deform.c.

References CLAMP, MDeformWeight::def_nr, MDeformVert::dw, NULL, MDeformVert::totweight, and MDeformWeight::weight.

Referenced by paint_weight_gradient_exec(), and vgroup_normalize_all().

◆ BKE_defvert_normalize_subset()

void BKE_defvert_normalize_subset ( MDeformVert dvert,
const bool *  vgroup_subset,
const int  vgroup_tot 
)

◆ BKE_defvert_remap()

void BKE_defvert_remap ( MDeformVert dvert,
const int *  map,
const int  map_len 
)

be sure all flip_map values are valid

Definition at line 252 of file deform.c.

References BLI_assert, MDeformWeight::def_nr, MDeformVert::dw, and MDeformVert::totweight.

Referenced by vgroup_do_remap().

◆ BKE_defvert_remove_group()

void BKE_defvert_remove_group ( MDeformVert dvert,
MDeformWeight dw 
)

◆ BKE_defvert_sync()

void BKE_defvert_sync ( MDeformVert dvert_dst,
const MDeformVert dvert_src,
const bool  use_ensure 
)

Only sync over matching weights, don't add or remove groups warning, loop within loop.

Definition at line 200 of file deform.c.

References BKE_defvert_ensure_index(), BKE_defvert_find_index(), MDeformWeight::def_nr, MDeformVert::dw, MDeformVert::totweight, and MDeformWeight::weight.

◆ BKE_defvert_sync_mapped()

void BKE_defvert_sync_mapped ( MDeformVert dvert_dst,
const MDeformVert dvert_src,
const int *  flip_map,
const int  flip_map_len,
const bool  use_ensure 
)

be sure all flip_map values are valid

Definition at line 223 of file deform.c.

References BKE_defvert_ensure_index(), BKE_defvert_find_index(), MDeformWeight::def_nr, MDeformVert::dw, MDeformVert::totweight, and MDeformWeight::weight.

◆ BKE_defvert_total_selected_weight()

float BKE_defvert_total_selected_weight ( const struct MDeformVert dv,
int  defbase_tot,
const bool *  defbase_sel 
)

◆ BKE_defvert_weight_to_rgb()

void BKE_defvert_weight_to_rgb ( float  r_rgb[3],
const float  weight 
)

Definition at line 1486 of file deform.c.

References blend().

Referenced by psys_cache_edit_paths_iter().

◆ BKE_object_defgroup_find_name()

bDeformGroup* BKE_object_defgroup_find_name ( const Object ob,
const char *  name 
)

Definition at line 487 of file deform.c.

References BLI_findstring(), Object::defbase, and NULL.

◆ BKE_object_defgroup_flip_index()

int BKE_object_defgroup_flip_index ( const Object ob,
int  index,
const bool  use_default 
)

◆ BKE_object_defgroup_flip_map()

int* BKE_object_defgroup_flip_map ( const Object ob,
int *  flip_map_len,
const bool  use_default 
)

◆ BKE_object_defgroup_flip_map_single()

int* BKE_object_defgroup_flip_map_single ( const Object ob,
int *  flip_map_len,
const bool  use_default,
int  defgroup 
)

◆ BKE_object_defgroup_name_index()

int BKE_object_defgroup_name_index ( const Object ob,
const char *  name 
)

◆ BKE_object_defgroup_new()

bDeformGroup* BKE_object_defgroup_new ( Object ob,
const char *  name 
)

◆ BKE_object_defgroup_unique_name()

void BKE_object_defgroup_unique_name ( bDeformGroup dg,
Object ob 
)

◆ data_transfer_layersmapping_vgroups()

bool data_transfer_layersmapping_vgroups ( ListBase r_map,
const int  mix_mode,
const float  mix_factor,
const float mix_weights,
const int  num_elem_dst,
const bool  use_create,
const bool  use_delete,
Object ob_src,
Object ob_dst,
CustomData cd_src,
CustomData cd_dst,
const bool  use_dupref_dst,
const int  fromlayers,
const int  tolayers 
)

◆ data_transfer_layersmapping_vgroups_multisrc_to_dst()

static bool data_transfer_layersmapping_vgroups_multisrc_to_dst ( ListBase r_map,
const int  mix_mode,
const float  mix_factor,
const float mix_weights,
const int  num_elem_dst,
const bool  use_create,
const bool  use_delete,
Object ob_src,
Object ob_dst,
MDeformVert data_src,
MDeformVert data_dst,
CustomData UNUSEDcd_src,
CustomData cd_dst,
const bool   UNUSEDuse_dupref_dst,
const int  tolayers,
const bool *  use_layers_src,
const int  num_layers_src 
)
static

◆ defgroup_find_name_dupe()

static bool defgroup_find_name_dupe ( const char *  name,
bDeformGroup dg,
Object ob 
)
static

Definition at line 596 of file deform.c.

References Object::defbase, ListBase::first, bDeformGroup::name, bDeformGroup::next, and STREQ.

Referenced by defgroup_unique_check().

◆ defgroup_unique_check()

static bool defgroup_unique_check ( void *  arg,
const char *  name 
)
static

Definition at line 611 of file deform.c.

References data, and defgroup_find_name_dupe().

Referenced by BKE_object_defgroup_unique_name().

◆ vgroups_datatransfer_interp()

static void vgroups_datatransfer_interp ( const CustomDataTransferLayerMap laymap,
void *  dest,
const void **  sources,
const float weights,
const int  count,
const float  mix_factor 
)
static