2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
#include <cctype>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
2004-09-14 19:03:11 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2004-09-14 19:03:11 +00:00
|
|
|
|
2023-03-13 10:42:51 +01:00
|
|
|
#include "DNA_gpencil_legacy_types.h"
|
2021-07-13 12:10:34 -04:00
|
|
|
#include "DNA_lattice_types.h"
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_meshdata_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_object_types.h"
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
#include "DNA_scene_types.h"
|
2004-09-14 19:03:11 +00:00
|
|
|
|
2012-09-05 04:16:09 +00:00
|
|
|
#include "BLI_listbase.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_vector.h"
|
2012-09-05 04:16:09 +00:00
|
|
|
#include "BLI_string.h"
|
2023-10-18 17:15:30 +02:00
|
|
|
#include "BLI_string_utils.hh"
|
2011-10-27 12:37:14 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2013-03-25 08:29:06 +00:00
|
|
|
|
2023-08-08 10:11:10 +02:00
|
|
|
#include "BKE_attribute.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_customdata.hh"
|
2015-01-12 12:03:28 +01:00
|
|
|
#include "BKE_data_transfer.h"
|
2013-02-22 04:09:04 +00:00
|
|
|
#include "BKE_deform.h" /* own include */
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh_mapping.hh"
|
2023-10-09 23:41:53 +02:00
|
|
|
#include "BKE_object.hh"
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
#include "BKE_object_deform.h"
|
|
|
|
|
|
2023-08-28 15:01:05 +02:00
|
|
|
#include "BLO_read_write.hh"
|
2020-08-28 13:58:39 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
#include "data_transfer_intern.h"
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
bDeformGroup *BKE_object_defgroup_new(Object *ob, const char *name)
|
2013-07-04 03:56:18 +00:00
|
|
|
{
|
|
|
|
|
bDeformGroup *defgroup;
|
|
|
|
|
|
|
|
|
|
BLI_assert(OB_TYPE_SUPPORT_VGROUP(ob->type));
|
|
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
defgroup = MEM_cnew<bDeformGroup>(__func__);
|
2013-07-04 03:56:18 +00:00
|
|
|
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(defgroup->name, name);
|
2013-07-04 03:56:18 +00:00
|
|
|
|
2021-07-13 12:10:34 -04:00
|
|
|
ListBase *defbase = BKE_object_defgroup_list_mutable(ob);
|
|
|
|
|
|
|
|
|
|
BLI_addtail(defbase, defgroup);
|
2020-03-06 12:50:56 +11:00
|
|
|
BKE_object_defgroup_unique_name(defgroup, ob);
|
2013-07-04 03:56:18 +00:00
|
|
|
|
2018-10-26 13:44:14 -03:00
|
|
|
BKE_object_batch_cache_dirty_tag(ob);
|
2017-05-03 18:55:40 +02:00
|
|
|
|
2013-07-04 03:56:18 +00:00
|
|
|
return defgroup;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defgroup_copy_list(ListBase *outbase, const ListBase *inbase)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(outbase);
|
2023-01-21 15:44:58 -06:00
|
|
|
LISTBASE_FOREACH (const bDeformGroup *, defgroup, inbase) {
|
|
|
|
|
bDeformGroup *defgroupn = BKE_defgroup_duplicate(defgroup);
|
2002-10-12 11:37:38 +00:00
|
|
|
BLI_addtail(outbase, defgroupn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
bDeformGroup *BKE_defgroup_duplicate(const bDeformGroup *ingroup)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2015-07-14 08:41:15 +10:00
|
|
|
if (!ingroup) {
|
|
|
|
|
BLI_assert(0);
|
2023-01-21 15:44:58 -06:00
|
|
|
return nullptr;
|
2015-07-14 08:41:15 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
bDeformGroup *outgroup = MEM_cnew<bDeformGroup>(__func__);
|
2011-11-30 07:39:54 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* For now, just copy everything over. */
|
2012-03-20 04:09:43 +00:00
|
|
|
memcpy(outgroup, ingroup, sizeof(bDeformGroup));
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
outgroup->next = outgroup->prev = nullptr;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
return outgroup;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_copy_subset(MDeformVert *dvert_dst,
|
|
|
|
|
const MDeformVert *dvert_src,
|
|
|
|
|
const bool *vgroup_subset,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int vgroup_num)
|
2013-06-23 15:37:08 +00:00
|
|
|
{
|
|
|
|
|
int defgroup;
|
2022-09-09 16:20:32 +10:00
|
|
|
for (defgroup = 0; defgroup < vgroup_num; defgroup++) {
|
2013-06-23 15:37:08 +00:00
|
|
|
if (vgroup_subset[defgroup]) {
|
2020-03-06 12:50:56 +11:00
|
|
|
BKE_defvert_copy_index(dvert_dst, defgroup, dvert_src, defgroup);
|
2016-02-09 00:18:45 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_mirror_subset(MDeformVert *dvert_dst,
|
|
|
|
|
const MDeformVert *dvert_src,
|
|
|
|
|
const bool *vgroup_subset,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int vgroup_num,
|
2020-03-06 12:50:56 +11:00
|
|
|
const int *flip_map,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int flip_map_num)
|
2016-02-09 00:18:45 +11:00
|
|
|
{
|
|
|
|
|
int defgroup;
|
2022-09-09 16:20:32 +10:00
|
|
|
for (defgroup = 0; defgroup < vgroup_num && defgroup < flip_map_num; defgroup++) {
|
2016-02-09 00:18:45 +11:00
|
|
|
if (vgroup_subset[defgroup] && (dvert_dst != dvert_src || flip_map[defgroup] != defgroup)) {
|
2020-03-06 12:50:56 +11:00
|
|
|
BKE_defvert_copy_index(dvert_dst, flip_map[defgroup], dvert_src, defgroup);
|
2013-06-23 15:37:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_copy(MDeformVert *dvert_dst, const MDeformVert *dvert_src)
|
2010-01-15 17:28:00 +00:00
|
|
|
{
|
2011-11-30 07:39:54 +00:00
|
|
|
if (dvert_dst->totweight == dvert_src->totweight) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (dvert_src->totweight) {
|
2011-11-30 07:39:54 +00:00
|
|
|
memcpy(dvert_dst->dw, dvert_src->dw, dvert_src->totweight * sizeof(MDeformWeight));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2010-01-15 17:28:00 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (dvert_dst->dw) {
|
2011-11-30 07:39:54 +00:00
|
|
|
MEM_freeN(dvert_dst->dw);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (dvert_src->totweight) {
|
2023-01-21 15:44:58 -06:00
|
|
|
dvert_dst->dw = static_cast<MDeformWeight *>(MEM_dupallocN(dvert_src->dw));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2023-01-21 15:44:58 -06:00
|
|
|
dvert_dst->dw = nullptr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-30 07:39:54 +00:00
|
|
|
dvert_dst->totweight = dvert_src->totweight;
|
2010-01-15 17:28:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_copy_index(MDeformVert *dvert_dst,
|
|
|
|
|
const int defgroup_dst,
|
|
|
|
|
const MDeformVert *dvert_src,
|
|
|
|
|
const int defgroup_src)
|
2011-11-30 07:11:29 +00:00
|
|
|
{
|
2022-05-13 18:31:29 +02:00
|
|
|
MDeformWeight *dw_dst;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-05-13 18:31:29 +02:00
|
|
|
const MDeformWeight *dw_src = BKE_defvert_find_index(dvert_src, defgroup_src);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-30 07:11:29 +00:00
|
|
|
if (dw_src) {
|
2020-03-06 13:00:01 +11:00
|
|
|
/* Source is valid, ensure destination is created. */
|
2020-03-06 12:50:56 +11:00
|
|
|
dw_dst = BKE_defvert_ensure_index(dvert_dst, defgroup_dst);
|
2012-03-20 04:09:43 +00:00
|
|
|
dw_dst->weight = dw_src->weight;
|
2011-11-30 07:11:29 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-01-21 15:44:58 -06:00
|
|
|
/* Source was nullptr, assign zero (could also remove). */
|
2020-03-06 12:50:56 +11:00
|
|
|
dw_dst = BKE_defvert_find_index(dvert_dst, defgroup_dst);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-30 07:11:29 +00:00
|
|
|
if (dw_dst) {
|
2012-03-20 04:09:43 +00:00
|
|
|
dw_dst->weight = 0.0f;
|
2011-11-30 07:11:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 13:00:01 +11:00
|
|
|
void BKE_defvert_sync(MDeformVert *dvert_dst, const MDeformVert *dvert_src, const bool use_ensure)
|
2010-01-26 17:07:47 +00:00
|
|
|
{
|
2011-11-30 07:39:54 +00:00
|
|
|
if (dvert_src->totweight && dvert_dst->totweight) {
|
2020-09-09 16:35:20 +02:00
|
|
|
MDeformWeight *dw_src = dvert_src->dw;
|
|
|
|
|
for (int i = 0; i < dvert_src->totweight; i++, dw_src++) {
|
2011-11-30 07:39:54 +00:00
|
|
|
MDeformWeight *dw_dst;
|
2020-03-06 13:00:01 +11:00
|
|
|
if (use_ensure) {
|
2020-03-06 12:50:56 +11:00
|
|
|
dw_dst = BKE_defvert_ensure_index(dvert_dst, dw_src->def_nr);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2020-03-06 12:50:56 +11:00
|
|
|
dw_dst = BKE_defvert_find_index(dvert_dst, dw_src->def_nr);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-30 07:39:54 +00:00
|
|
|
if (dw_dst) {
|
2012-03-20 04:09:43 +00:00
|
|
|
dw_dst->weight = dw_src->weight;
|
2010-01-26 17:07:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_sync_mapped(MDeformVert *dvert_dst,
|
|
|
|
|
const MDeformVert *dvert_src,
|
|
|
|
|
const int *flip_map,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int flip_map_num,
|
2020-03-06 13:00:01 +11:00
|
|
|
const bool use_ensure)
|
2010-01-26 17:07:47 +00:00
|
|
|
{
|
2011-11-30 07:39:54 +00:00
|
|
|
if (dvert_src->totweight && dvert_dst->totweight) {
|
2020-09-09 16:35:20 +02:00
|
|
|
MDeformWeight *dw_src = dvert_src->dw;
|
|
|
|
|
for (int i = 0; i < dvert_src->totweight; i++, dw_src++) {
|
2022-09-09 16:20:32 +10:00
|
|
|
if (dw_src->def_nr < flip_map_num) {
|
2011-11-30 07:39:54 +00:00
|
|
|
MDeformWeight *dw_dst;
|
2020-03-06 13:00:01 +11:00
|
|
|
if (use_ensure) {
|
2020-03-06 12:50:56 +11:00
|
|
|
dw_dst = BKE_defvert_ensure_index(dvert_dst, flip_map[dw_src->def_nr]);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2020-03-06 12:50:56 +11:00
|
|
|
dw_dst = BKE_defvert_find_index(dvert_dst, flip_map[dw_src->def_nr]);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-30 07:39:54 +00:00
|
|
|
if (dw_dst) {
|
2012-03-20 04:09:43 +00:00
|
|
|
dw_dst->weight = dw_src->weight;
|
2011-10-27 07:54:32 +00:00
|
|
|
}
|
2010-01-26 17:07:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 11:27:09 +02:00
|
|
|
void BKE_defvert_remap(MDeformVert *dvert, const int *map, const int map_len)
|
2010-02-02 21:43:26 +00:00
|
|
|
{
|
2012-03-20 04:09:43 +00:00
|
|
|
MDeformWeight *dw = dvert->dw;
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = dvert->totweight; i != 0; i--, dw++) {
|
2011-12-09 08:20:27 +00:00
|
|
|
if (dw->def_nr < map_len) {
|
2020-02-11 12:35:10 +11:00
|
|
|
BLI_assert(map[dw->def_nr] >= 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-11 12:35:10 +11:00
|
|
|
dw->def_nr = map[dw->def_nr];
|
2011-12-09 08:20:27 +00:00
|
|
|
}
|
2010-02-02 21:43:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_normalize_subset(MDeformVert *dvert,
|
|
|
|
|
const bool *vgroup_subset,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int vgroup_num)
|
2013-06-23 15:37:08 +00:00
|
|
|
{
|
2013-10-10 06:33:23 +00:00
|
|
|
if (dvert->totweight == 0) {
|
|
|
|
|
/* nothing */
|
|
|
|
|
}
|
|
|
|
|
else if (dvert->totweight == 1) {
|
|
|
|
|
MDeformWeight *dw = dvert->dw;
|
2022-09-09 16:20:32 +10:00
|
|
|
if ((dw->def_nr < vgroup_num) && vgroup_subset[dw->def_nr]) {
|
2013-10-10 06:33:23 +00:00
|
|
|
dw->weight = 1.0f;
|
2013-06-23 15:37:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-10-10 06:33:23 +00:00
|
|
|
else {
|
2020-09-09 16:35:20 +02:00
|
|
|
MDeformWeight *dw = dvert->dw;
|
2013-10-10 06:33:23 +00:00
|
|
|
float tot_weight = 0.0f;
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = dvert->totweight; i != 0; i--, dw++) {
|
2022-09-09 16:20:32 +10:00
|
|
|
if ((dw->def_nr < vgroup_num) && vgroup_subset[dw->def_nr]) {
|
2013-10-10 06:33:23 +00:00
|
|
|
tot_weight += dw->weight;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-10-10 06:33:23 +00:00
|
|
|
if (tot_weight > 0.0f) {
|
|
|
|
|
float scalar = 1.0f / tot_weight;
|
2020-09-09 16:35:20 +02:00
|
|
|
dw = dvert->dw;
|
|
|
|
|
for (int i = dvert->totweight; i != 0; i--, dw++) {
|
2022-09-09 16:20:32 +10:00
|
|
|
if ((dw->def_nr < vgroup_num) && vgroup_subset[dw->def_nr]) {
|
2013-10-10 06:33:23 +00:00
|
|
|
dw->weight *= scalar;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-10-10 06:33:23 +00:00
|
|
|
/* in case of division errors with very low weights */
|
|
|
|
|
CLAMP(dw->weight, 0.0f, 1.0f);
|
|
|
|
|
}
|
2013-06-23 15:37:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_normalize(MDeformVert *dvert)
|
2010-01-25 23:12:02 +00:00
|
|
|
{
|
2013-10-10 06:33:23 +00:00
|
|
|
if (dvert->totweight == 0) {
|
2010-01-25 23:12:02 +00:00
|
|
|
/* nothing */
|
|
|
|
|
}
|
2012-03-20 04:09:43 +00:00
|
|
|
else if (dvert->totweight == 1) {
|
|
|
|
|
dvert->dw[0].weight = 1.0f;
|
2010-01-25 23:12:02 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
MDeformWeight *dw;
|
2022-09-25 17:04:52 +10:00
|
|
|
uint i;
|
2012-03-20 04:09:43 +00:00
|
|
|
float tot_weight = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-20 04:09:43 +00:00
|
|
|
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
|
2011-12-14 21:08:08 +00:00
|
|
|
tot_weight += dw->weight;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-12-14 21:08:08 +00:00
|
|
|
if (tot_weight > 0.0f) {
|
2012-03-20 04:09:43 +00:00
|
|
|
float scalar = 1.0f / tot_weight;
|
|
|
|
|
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
|
2011-12-14 21:08:08 +00:00
|
|
|
dw->weight *= scalar;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-09 00:41:09 +00:00
|
|
|
/* in case of division errors with very low weights */
|
2011-12-14 21:08:08 +00:00
|
|
|
CLAMP(dw->weight, 0.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_normalize_lock_single(MDeformVert *dvert,
|
|
|
|
|
const bool *vgroup_subset,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int vgroup_num,
|
2020-03-06 12:50:56 +11:00
|
|
|
const uint def_nr_lock)
|
2011-12-14 21:08:08 +00:00
|
|
|
{
|
2013-10-10 06:33:23 +00:00
|
|
|
if (dvert->totweight == 0) {
|
2011-12-14 21:08:08 +00:00
|
|
|
/* nothing */
|
|
|
|
|
}
|
2012-03-20 04:09:43 +00:00
|
|
|
else if (dvert->totweight == 1) {
|
2013-10-10 06:33:23 +00:00
|
|
|
MDeformWeight *dw = dvert->dw;
|
2022-09-09 16:20:32 +10:00
|
|
|
if ((dw->def_nr < vgroup_num) && vgroup_subset[dw->def_nr]) {
|
2020-01-14 15:13:19 +01:00
|
|
|
if (def_nr_lock != dw->def_nr) {
|
2013-10-10 06:33:23 +00:00
|
|
|
dw->weight = 1.0f;
|
|
|
|
|
}
|
2012-09-05 03:45:32 +00:00
|
|
|
}
|
2011-12-14 21:08:08 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-01-21 15:44:58 -06:00
|
|
|
MDeformWeight *dw_lock = nullptr;
|
2011-12-14 21:08:08 +00:00
|
|
|
MDeformWeight *dw;
|
2022-09-25 17:04:52 +10:00
|
|
|
uint i;
|
2012-03-20 04:09:43 +00:00
|
|
|
float tot_weight = 0.0f;
|
|
|
|
|
float lock_iweight = 1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-20 04:09:43 +00:00
|
|
|
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
|
2022-09-09 16:20:32 +10:00
|
|
|
if ((dw->def_nr < vgroup_num) && vgroup_subset[dw->def_nr]) {
|
2013-10-10 06:33:23 +00:00
|
|
|
if (dw->def_nr != def_nr_lock) {
|
|
|
|
|
tot_weight += dw->weight;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dw_lock = dw;
|
|
|
|
|
lock_iweight = (1.0f - dw_lock->weight);
|
|
|
|
|
CLAMP(lock_iweight, 0.0f, 1.0f);
|
|
|
|
|
}
|
2011-12-14 21:08:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-12-14 21:08:08 +00:00
|
|
|
if (tot_weight > 0.0f) {
|
2012-03-09 00:41:09 +00:00
|
|
|
/* paranoid, should be 1.0 but in case of float error clamp anyway */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-20 04:09:43 +00:00
|
|
|
float scalar = (1.0f / tot_weight) * lock_iweight;
|
|
|
|
|
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
|
2022-09-09 16:20:32 +10:00
|
|
|
if ((dw->def_nr < vgroup_num) && vgroup_subset[dw->def_nr]) {
|
2013-10-10 06:33:23 +00:00
|
|
|
if (dw != dw_lock) {
|
|
|
|
|
dw->weight *= scalar;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-10-10 06:33:23 +00:00
|
|
|
/* in case of division errors with very low weights */
|
|
|
|
|
CLAMP(dw->weight, 0.0f, 1.0f);
|
|
|
|
|
}
|
2011-12-14 21:08:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-01-25 23:12:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_normalize_lock_map(MDeformVert *dvert,
|
|
|
|
|
const bool *vgroup_subset,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int vgroup_num,
|
2020-03-06 12:50:56 +11:00
|
|
|
const bool *lock_flags,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int defbase_num)
|
2012-09-05 04:16:09 +00:00
|
|
|
{
|
2013-10-10 06:33:23 +00:00
|
|
|
if (dvert->totweight == 0) {
|
2012-09-05 04:16:09 +00:00
|
|
|
/* nothing */
|
|
|
|
|
}
|
|
|
|
|
else if (dvert->totweight == 1) {
|
2013-10-10 06:33:23 +00:00
|
|
|
MDeformWeight *dw = dvert->dw;
|
2022-09-09 16:20:32 +10:00
|
|
|
if ((dw->def_nr < vgroup_num) && vgroup_subset[dw->def_nr]) {
|
|
|
|
|
if ((dw->def_nr < defbase_num) && (lock_flags[dw->def_nr] == false)) {
|
2013-10-10 06:33:23 +00:00
|
|
|
dw->weight = 1.0f;
|
|
|
|
|
}
|
2012-09-05 04:16:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
MDeformWeight *dw;
|
2022-09-25 17:04:52 +10:00
|
|
|
uint i;
|
2012-09-05 04:16:09 +00:00
|
|
|
float tot_weight = 0.0f;
|
|
|
|
|
float lock_iweight = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-05 04:16:09 +00:00
|
|
|
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
|
2022-09-09 16:20:32 +10:00
|
|
|
if ((dw->def_nr < vgroup_num) && vgroup_subset[dw->def_nr]) {
|
|
|
|
|
if ((dw->def_nr < defbase_num) && (lock_flags[dw->def_nr] == false)) {
|
2013-10-10 06:33:23 +00:00
|
|
|
tot_weight += dw->weight;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* invert after */
|
|
|
|
|
lock_iweight += dw->weight;
|
|
|
|
|
}
|
2012-09-05 04:16:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-23 13:28:22 +00:00
|
|
|
lock_iweight = max_ff(0.0f, 1.0f - lock_iweight);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-05 04:16:09 +00:00
|
|
|
if (tot_weight > 0.0f) {
|
|
|
|
|
/* paranoid, should be 1.0 but in case of float error clamp anyway */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-05 04:16:09 +00:00
|
|
|
float scalar = (1.0f / tot_weight) * lock_iweight;
|
|
|
|
|
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
|
2022-09-09 16:20:32 +10:00
|
|
|
if ((dw->def_nr < vgroup_num) && vgroup_subset[dw->def_nr]) {
|
|
|
|
|
if ((dw->def_nr < defbase_num) && (lock_flags[dw->def_nr] == false)) {
|
2013-10-10 06:33:23 +00:00
|
|
|
dw->weight *= scalar;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-10-10 06:33:23 +00:00
|
|
|
/* in case of division errors with very low weights */
|
|
|
|
|
CLAMP(dw->weight, 0.0f, 1.0f);
|
|
|
|
|
}
|
2012-09-05 04:16:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
void BKE_defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_num)
|
2010-01-15 17:28:00 +00:00
|
|
|
{
|
|
|
|
|
MDeformWeight *dw;
|
|
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-12 19:18:02 +00:00
|
|
|
for (dw = dvert->dw, i = 0; i < dvert->totweight; dw++, i++) {
|
2022-09-09 16:20:32 +10:00
|
|
|
if (dw->def_nr < flip_map_num) {
|
2011-12-09 08:20:27 +00:00
|
|
|
if (flip_map[dw->def_nr] >= 0) {
|
2012-03-20 04:09:43 +00:00
|
|
|
dw->def_nr = flip_map[dw->def_nr];
|
2011-12-09 08:20:27 +00:00
|
|
|
}
|
2011-10-27 07:54:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-01-15 17:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
void BKE_defvert_flip_merged(MDeformVert *dvert, const int *flip_map, const int flip_map_num)
|
2012-03-19 21:09:16 +00:00
|
|
|
{
|
2012-03-20 03:48:32 +00:00
|
|
|
MDeformWeight *dw, *dw_cpy;
|
2012-03-19 21:09:16 +00:00
|
|
|
float weight;
|
|
|
|
|
int i, totweight = dvert->totweight;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-19 21:09:16 +00:00
|
|
|
/* copy weights */
|
2012-03-20 04:09:43 +00:00
|
|
|
for (dw = dvert->dw, i = 0; i < totweight; dw++, i++) {
|
2022-09-09 16:20:32 +10:00
|
|
|
if (dw->def_nr < flip_map_num) {
|
2012-03-19 21:09:16 +00:00
|
|
|
if (flip_map[dw->def_nr] >= 0) {
|
2023-01-21 15:44:58 -06:00
|
|
|
/* error checkers complain of this but we'll never get nullptr return */
|
2020-03-06 12:50:56 +11:00
|
|
|
dw_cpy = BKE_defvert_ensure_index(dvert, flip_map[dw->def_nr]);
|
2012-03-20 03:48:32 +00:00
|
|
|
dw = &dvert->dw[i]; /* in case array got realloced */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-19 21:09:16 +00:00
|
|
|
/* distribute weights: if only one of the vertex groups was
|
2012-05-16 23:37:23 +00:00
|
|
|
* assigned this will halve the weights, otherwise it gets
|
|
|
|
|
* evened out. this keeps it proportional to other groups */
|
2012-03-20 03:48:32 +00:00
|
|
|
weight = 0.5f * (dw_cpy->weight + dw->weight);
|
|
|
|
|
dw_cpy->weight = weight;
|
|
|
|
|
dw->weight = weight;
|
2012-03-19 21:09:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-15 17:28:00 +00:00
|
|
|
|
2023-08-12 07:37:37 +02:00
|
|
|
bool BKE_id_supports_vertex_groups(const ID *id)
|
2021-07-13 12:10:34 -04:00
|
|
|
{
|
2023-01-21 15:44:58 -06:00
|
|
|
if (id == nullptr) {
|
2021-07-13 12:10:34 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
2023-03-08 12:35:58 +01:00
|
|
|
return ELEM(GS(id->name), ID_ME, ID_LT, ID_GD_LEGACY);
|
2021-07-13 12:10:34 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-12 07:37:37 +02:00
|
|
|
bool BKE_object_supports_vertex_groups(const Object *ob)
|
|
|
|
|
{
|
|
|
|
|
const ID *id = static_cast<const ID *>(ob->data);
|
|
|
|
|
|
|
|
|
|
return BKE_id_supports_vertex_groups(id);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-13 12:10:34 -04:00
|
|
|
const ListBase *BKE_id_defgroup_list_get(const ID *id)
|
|
|
|
|
{
|
|
|
|
|
switch (GS(id->name)) {
|
|
|
|
|
case ID_ME: {
|
|
|
|
|
const Mesh *me = (const Mesh *)id;
|
|
|
|
|
return &me->vertex_group_names;
|
|
|
|
|
}
|
|
|
|
|
case ID_LT: {
|
|
|
|
|
const Lattice *lt = (const Lattice *)id;
|
|
|
|
|
return <->vertex_group_names;
|
|
|
|
|
}
|
2023-03-08 12:35:58 +01:00
|
|
|
case ID_GD_LEGACY: {
|
2021-07-13 12:10:34 -04:00
|
|
|
const bGPdata *gpd = (const bGPdata *)id;
|
|
|
|
|
return &gpd->vertex_group_names;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-21 15:44:58 -06:00
|
|
|
return nullptr;
|
2021-07-13 12:10:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const int *object_defgroup_active_index_get_p(const Object *ob)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(BKE_object_supports_vertex_groups(ob));
|
|
|
|
|
switch (ob->type) {
|
|
|
|
|
case OB_MESH: {
|
|
|
|
|
const Mesh *mesh = (const Mesh *)ob->data;
|
|
|
|
|
return &mesh->vertex_group_active_index;
|
|
|
|
|
}
|
|
|
|
|
case OB_LATTICE: {
|
|
|
|
|
const Lattice *lattice = (const Lattice *)ob->data;
|
|
|
|
|
return &lattice->vertex_group_active_index;
|
|
|
|
|
}
|
2023-03-08 12:35:58 +01:00
|
|
|
case OB_GPENCIL_LEGACY: {
|
2021-07-13 12:10:34 -04:00
|
|
|
const bGPdata *gpd = (const bGPdata *)ob->data;
|
|
|
|
|
return &gpd->vertex_group_active_index;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-21 15:44:58 -06:00
|
|
|
return nullptr;
|
2021-07-13 12:10:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ListBase *BKE_id_defgroup_list_get_mutable(ID *id)
|
|
|
|
|
{
|
|
|
|
|
/* Cast away const just for the accessor. */
|
|
|
|
|
return (ListBase *)BKE_id_defgroup_list_get(id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-13 16:08:34 +10:00
|
|
|
bDeformGroup *BKE_object_defgroup_find_name(const Object *ob, const char *name)
|
2005-01-12 23:57:33 +00:00
|
|
|
{
|
2023-01-21 15:44:58 -06:00
|
|
|
if (name == nullptr || name[0] == '\0') {
|
|
|
|
|
return nullptr;
|
2021-07-13 12:10:34 -04:00
|
|
|
}
|
|
|
|
|
const ListBase *defbase = BKE_object_defgroup_list(ob);
|
2023-01-21 15:44:58 -06:00
|
|
|
return static_cast<bDeformGroup *>(BLI_findstring(defbase, name, offsetof(bDeformGroup, name)));
|
2021-07-13 12:10:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int BKE_id_defgroup_name_index(const ID *id, const char *name)
|
|
|
|
|
{
|
2021-11-23 14:35:49 +01:00
|
|
|
int index;
|
2023-01-21 15:44:58 -06:00
|
|
|
if (!BKE_id_defgroup_name_find(id, name, &index, nullptr)) {
|
2021-07-13 12:10:34 -04:00
|
|
|
return -1;
|
|
|
|
|
}
|
2021-11-23 14:35:49 +01:00
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 10:26:06 +02:00
|
|
|
bool BKE_defgroup_listbase_name_find(const ListBase *defbase,
|
|
|
|
|
const char *name,
|
|
|
|
|
int *r_index,
|
|
|
|
|
bDeformGroup **r_group)
|
2021-11-23 14:35:49 +01:00
|
|
|
{
|
2023-01-21 15:44:58 -06:00
|
|
|
if (name == nullptr || name[0] == '\0') {
|
2021-11-23 14:35:49 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
int index;
|
|
|
|
|
LISTBASE_FOREACH_INDEX (bDeformGroup *, group, defbase, index) {
|
|
|
|
|
if (STREQ(name, group->name)) {
|
2023-01-21 15:44:58 -06:00
|
|
|
if (r_index != nullptr) {
|
2021-11-23 14:35:49 +01:00
|
|
|
*r_index = index;
|
|
|
|
|
}
|
2023-01-21 15:44:58 -06:00
|
|
|
if (r_group != nullptr) {
|
2021-11-23 14:35:49 +01:00
|
|
|
*r_group = group;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2021-07-13 12:10:34 -04:00
|
|
|
}
|
|
|
|
|
|
2023-09-27 10:26:06 +02:00
|
|
|
bool BKE_id_defgroup_name_find(const ID *id,
|
|
|
|
|
const char *name,
|
|
|
|
|
int *r_index,
|
|
|
|
|
bDeformGroup **r_group)
|
|
|
|
|
{
|
|
|
|
|
return BKE_defgroup_listbase_name_find(BKE_id_defgroup_list_get(id), name, r_index, r_group);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-13 12:10:34 -04:00
|
|
|
const ListBase *BKE_object_defgroup_list(const Object *ob)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(BKE_object_supports_vertex_groups(ob));
|
|
|
|
|
return BKE_id_defgroup_list_get((const ID *)ob->data);
|
2005-01-12 23:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-13 16:08:34 +10:00
|
|
|
int BKE_object_defgroup_name_index(const Object *ob, const char *name)
|
2007-08-17 11:23:48 +00:00
|
|
|
{
|
2021-07-13 12:10:34 -04:00
|
|
|
return BKE_id_defgroup_name_index((ID *)ob->data, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ListBase *BKE_object_defgroup_list_mutable(Object *ob)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(BKE_object_supports_vertex_groups(ob));
|
|
|
|
|
return BKE_id_defgroup_list_get_mutable((ID *)ob->data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int BKE_object_defgroup_count(const Object *ob)
|
|
|
|
|
{
|
|
|
|
|
return BLI_listbase_count(BKE_object_defgroup_list(ob));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int BKE_object_defgroup_active_index_get(const Object *ob)
|
|
|
|
|
{
|
|
|
|
|
return *object_defgroup_active_index_get_p(ob);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_object_defgroup_active_index_set(Object *ob, const int new_index)
|
|
|
|
|
{
|
|
|
|
|
/* Cast away const just for the accessor. */
|
|
|
|
|
int *index = (int *)object_defgroup_active_index_get_p(ob);
|
|
|
|
|
*index = new_index;
|
2007-08-17 11:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 15:55:51 +10:00
|
|
|
static int *object_defgroup_unlocked_flip_map_ex(const Object *ob,
|
|
|
|
|
const bool use_default,
|
2022-09-09 16:20:32 +10:00
|
|
|
const bool use_only_unlocked,
|
|
|
|
|
int *r_flip_map_num)
|
2010-01-15 17:28:00 +00:00
|
|
|
{
|
2021-07-13 12:10:34 -04:00
|
|
|
const ListBase *defbase = BKE_object_defgroup_list(ob);
|
2022-09-09 16:20:32 +10:00
|
|
|
const int defbase_num = BLI_listbase_count(defbase);
|
|
|
|
|
*r_flip_map_num = defbase_num;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
if (defbase_num == 0) {
|
2023-01-21 15:44:58 -06:00
|
|
|
return nullptr;
|
2010-01-15 17:28:00 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-07 12:30:43 +02:00
|
|
|
bDeformGroup *dg;
|
|
|
|
|
char name_flip[sizeof(dg->name)];
|
2022-09-09 15:55:51 +10:00
|
|
|
int i, flip_num;
|
2023-01-21 15:44:58 -06:00
|
|
|
int *map = static_cast<int *>(MEM_mallocN(defbase_num * sizeof(int), __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
for (i = 0; i < defbase_num; i++) {
|
2020-08-07 12:30:43 +02:00
|
|
|
map[i] = -1;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
for (dg = static_cast<bDeformGroup *>(defbase->first), i = 0; dg; dg = dg->next, i++) {
|
2020-08-07 12:30:43 +02:00
|
|
|
if (map[i] == -1) { /* may be calculated previously */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-07 12:30:43 +02:00
|
|
|
/* in case no valid value is found, use this */
|
|
|
|
|
if (use_default) {
|
|
|
|
|
map[i] = i;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-09 15:55:51 +10:00
|
|
|
if (use_only_unlocked && (dg->flag & DG_LOCK_WEIGHT)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-07 12:30:43 +02:00
|
|
|
BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
|
|
|
|
|
|
|
|
|
|
if (!STREQ(name_flip, dg->name)) {
|
|
|
|
|
flip_num = BKE_object_defgroup_name_index(ob, name_flip);
|
2022-09-09 15:55:51 +10:00
|
|
|
if (flip_num != -1) {
|
2020-08-07 12:30:43 +02:00
|
|
|
map[i] = flip_num;
|
|
|
|
|
map[flip_num] = i; /* save an extra lookup */
|
2010-01-15 17:28:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
return map;
|
2010-01-15 17:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
int *BKE_object_defgroup_flip_map(const Object *ob, const bool use_default, int *r_flip_map_num)
|
2022-09-09 15:55:51 +10:00
|
|
|
{
|
2022-09-09 16:20:32 +10:00
|
|
|
return object_defgroup_unlocked_flip_map_ex(ob, use_default, false, r_flip_map_num);
|
2022-09-09 15:55:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int *BKE_object_defgroup_flip_map_unlocked(const Object *ob,
|
2022-09-09 16:20:32 +10:00
|
|
|
const bool use_default,
|
|
|
|
|
int *r_flip_map_num)
|
2022-09-09 15:55:51 +10:00
|
|
|
{
|
2022-09-09 16:20:32 +10:00
|
|
|
return object_defgroup_unlocked_flip_map_ex(ob, use_default, true, r_flip_map_num);
|
2022-09-09 15:55:51 +10:00
|
|
|
}
|
|
|
|
|
|
2020-06-13 16:08:34 +10:00
|
|
|
int *BKE_object_defgroup_flip_map_single(const Object *ob,
|
2020-03-06 12:50:56 +11:00
|
|
|
const bool use_default,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int defgroup,
|
|
|
|
|
int *r_flip_map_num)
|
2011-11-01 08:11:55 +00:00
|
|
|
{
|
2021-07-13 12:10:34 -04:00
|
|
|
const ListBase *defbase = BKE_object_defgroup_list(ob);
|
2022-09-09 16:20:32 +10:00
|
|
|
const int defbase_num = BLI_listbase_count(defbase);
|
|
|
|
|
*r_flip_map_num = defbase_num;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
if (defbase_num == 0) {
|
2023-01-21 15:44:58 -06:00
|
|
|
return nullptr;
|
2011-11-01 08:11:55 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
char name_flip[sizeof(bDeformGroup::name)];
|
|
|
|
|
int i, flip_num, *map = static_cast<int *>(MEM_mallocN(defbase_num * sizeof(int), __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
for (i = 0; i < defbase_num; i++) {
|
2020-08-07 12:30:43 +02:00
|
|
|
map[i] = use_default ? i : -1;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
bDeformGroup *dg = static_cast<bDeformGroup *>(BLI_findlink(defbase, defgroup));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-07 12:30:43 +02:00
|
|
|
BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
|
|
|
|
|
if (!STREQ(name_flip, dg->name)) {
|
|
|
|
|
flip_num = BKE_object_defgroup_name_index(ob, name_flip);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-08-07 12:30:43 +02:00
|
|
|
if (flip_num != -1) {
|
|
|
|
|
map[defgroup] = flip_num;
|
|
|
|
|
map[flip_num] = defgroup;
|
|
|
|
|
}
|
2011-11-01 08:11:55 +00:00
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
|
|
|
|
|
return map;
|
2011-11-01 08:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-13 16:08:34 +10:00
|
|
|
int BKE_object_defgroup_flip_index(const Object *ob, int index, const bool use_default)
|
2010-01-26 17:07:47 +00:00
|
|
|
{
|
2021-07-13 12:10:34 -04:00
|
|
|
const ListBase *defbase = BKE_object_defgroup_list(ob);
|
2023-01-21 15:44:58 -06:00
|
|
|
bDeformGroup *dg = static_cast<bDeformGroup *>(BLI_findlink(defbase, index));
|
2010-01-26 17:07:47 +00:00
|
|
|
int flip_index = -1;
|
|
|
|
|
|
2011-11-30 07:39:54 +00:00
|
|
|
if (dg) {
|
2013-11-17 04:20:31 +11:00
|
|
|
char name_flip[sizeof(dg->name)];
|
2017-01-16 20:34:13 +01:00
|
|
|
BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
|
2010-01-26 17:07:47 +00:00
|
|
|
|
2013-11-17 04:20:31 +11:00
|
|
|
if (!STREQ(name_flip, dg->name)) {
|
2020-03-06 12:50:56 +11:00
|
|
|
flip_index = BKE_object_defgroup_name_index(ob, name_flip);
|
2013-11-17 04:20:31 +11:00
|
|
|
}
|
2010-01-26 17:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-20 04:09:43 +00:00
|
|
|
return (flip_index == -1 && use_default) ? index : flip_index;
|
2010-01-26 17:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-26 15:36:12 +02:00
|
|
|
struct DeformGroupUniqueNameData {
|
|
|
|
|
Object *ob;
|
|
|
|
|
bDeformGroup *dg;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *ob)
|
2007-04-27 11:16:35 +00:00
|
|
|
{
|
2023-09-26 15:36:12 +02:00
|
|
|
const ListBase *defbase = BKE_object_defgroup_list(ob);
|
2011-11-30 07:39:54 +00:00
|
|
|
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (bDeformGroup *, curdef, defbase) {
|
2012-03-20 04:09:43 +00:00
|
|
|
if (dg != curdef) {
|
2015-01-26 16:03:11 +01:00
|
|
|
if (STREQ(curdef->name, name)) {
|
2013-03-04 19:27:51 +00:00
|
|
|
return true;
|
2010-11-01 07:19:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-04 19:27:51 +00:00
|
|
|
return false;
|
2010-11-01 07:19:41 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-26 15:36:12 +02:00
|
|
|
static bool defgroup_unique_check(void *arg, const char *name)
|
2010-11-07 08:49:07 +00:00
|
|
|
{
|
2023-09-26 15:36:12 +02:00
|
|
|
DeformGroupUniqueNameData *data = static_cast<DeformGroupUniqueNameData *>(arg);
|
|
|
|
|
return defgroup_find_name_dupe(name, data->dg, data->ob);
|
2010-11-07 08:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_object_defgroup_unique_name(bDeformGroup *dg, Object *ob)
|
2010-11-07 08:49:07 +00:00
|
|
|
{
|
2023-09-26 15:36:12 +02:00
|
|
|
DeformGroupUniqueNameData data{ob, dg};
|
|
|
|
|
BLI_uniquename_cb(defgroup_unique_check, &data, DATA_("Group"), '.', dg->name, sizeof(dg->name));
|
2010-11-01 07:19:41 +00:00
|
|
|
}
|
2010-01-15 17:28:00 +00:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
float BKE_defvert_find_weight(const MDeformVert *dvert, const int defgroup)
|
2010-01-26 17:07:47 +00:00
|
|
|
{
|
2020-03-06 12:50:56 +11:00
|
|
|
MDeformWeight *dw = BKE_defvert_find_index(dvert, defgroup);
|
2010-01-28 12:16:35 +00:00
|
|
|
return dw ? dw->weight : 0.0f;
|
2010-01-26 17:07:47 +00:00
|
|
|
}
|
2010-01-15 17:28:00 +00:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
float BKE_defvert_array_find_weight_safe(const MDeformVert *dvert,
|
2020-03-06 12:50:56 +11:00
|
|
|
const int index,
|
|
|
|
|
const int defgroup)
|
2010-01-26 17:07:47 +00:00
|
|
|
{
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Invalid defgroup index means the vgroup selected is invalid,
|
|
|
|
|
* does not exist, in that case it is OK to return 1.0
|
2017-07-26 16:23:24 +02:00
|
|
|
* (i.e. maximum weight, as if no vgroup was selected).
|
2023-01-21 15:44:58 -06:00
|
|
|
* But in case of valid defgroup and nullptr dvert data pointer, it means that vgroup **is**
|
|
|
|
|
* valid, and just totally empty, so we shall return '0.0' value then! */
|
2017-07-26 16:23:24 +02:00
|
|
|
if (defgroup == -1) {
|
2010-01-30 03:47:13 +00:00
|
|
|
return 1.0f;
|
2017-07-26 16:23:24 +02:00
|
|
|
}
|
2023-01-21 15:44:58 -06:00
|
|
|
if (dvert == nullptr) {
|
2017-07-26 16:23:24 +02:00
|
|
|
return 0.0f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
return BKE_defvert_find_weight(dvert + index, defgroup);
|
2010-01-26 17:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
MDeformWeight *BKE_defvert_find_index(const MDeformVert *dvert, const int defgroup)
|
2008-07-04 19:56:31 +00:00
|
|
|
{
|
2020-07-10 18:02:51 +02:00
|
|
|
if (dvert && defgroup >= 0) {
|
|
|
|
|
MDeformWeight *dw = dvert->dw;
|
2022-09-25 17:04:52 +10:00
|
|
|
uint i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-10 18:02:51 +02:00
|
|
|
for (i = dvert->totweight; i != 0; i--, dw++) {
|
|
|
|
|
if (dw->def_nr == defgroup) {
|
|
|
|
|
return dw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-07-04 19:56:31 +00:00
|
|
|
}
|
2015-07-14 08:41:15 +10:00
|
|
|
else {
|
2020-07-10 18:02:51 +02:00
|
|
|
BLI_assert(0);
|
2015-07-14 08:41:15 +10:00
|
|
|
}
|
2020-07-10 18:02:51 +02:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
return nullptr;
|
2008-07-04 19:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
MDeformWeight *BKE_defvert_ensure_index(MDeformVert *dvert, const int defgroup)
|
2008-07-04 19:56:31 +00:00
|
|
|
{
|
2011-11-30 07:39:54 +00:00
|
|
|
MDeformWeight *dw_new;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-01-26 17:07:47 +00:00
|
|
|
/* do this check always, this function is used to check for it */
|
2015-07-14 08:41:15 +10:00
|
|
|
if (!dvert || defgroup < 0) {
|
|
|
|
|
BLI_assert(0);
|
2023-01-21 15:44:58 -06:00
|
|
|
return nullptr;
|
2015-07-14 08:41:15 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
dw_new = BKE_defvert_find_index(dvert, defgroup);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (dw_new) {
|
2011-11-30 07:39:54 +00:00
|
|
|
return dw_new;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
dw_new = static_cast<MDeformWeight *>(
|
|
|
|
|
MEM_mallocN(sizeof(MDeformWeight) * (dvert->totweight + 1), __func__));
|
2011-11-30 07:39:54 +00:00
|
|
|
if (dvert->dw) {
|
2020-07-10 18:02:51 +02:00
|
|
|
memcpy(dw_new, dvert->dw, sizeof(MDeformWeight) * dvert->totweight);
|
2011-11-30 07:39:54 +00:00
|
|
|
MEM_freeN(dvert->dw);
|
2010-01-26 17:07:47 +00:00
|
|
|
}
|
2012-03-20 04:09:43 +00:00
|
|
|
dvert->dw = dw_new;
|
2020-07-10 18:02:51 +02:00
|
|
|
dw_new += dvert->totweight;
|
2012-03-20 04:09:43 +00:00
|
|
|
dw_new->weight = 0.0f;
|
|
|
|
|
dw_new->def_nr = defgroup;
|
2010-01-26 17:07:47 +00:00
|
|
|
/* Group index */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-30 07:39:54 +00:00
|
|
|
dvert->totweight++;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-30 07:39:54 +00:00
|
|
|
return dw_new;
|
|
|
|
|
}
|
2010-01-26 17:07:47 +00:00
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
void BKE_defvert_add_index_notest(MDeformVert *dvert, const int defgroup, const float weight)
|
2011-11-30 07:39:54 +00:00
|
|
|
{
|
2021-12-07 17:19:15 +11:00
|
|
|
/* TODO: merge with #BKE_defvert_ensure_index! */
|
|
|
|
|
|
2011-11-30 07:39:54 +00:00
|
|
|
MDeformWeight *dw_new;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-12-08 03:47:45 +00:00
|
|
|
/* do this check always, this function is used to check for it */
|
2015-07-14 08:41:15 +10:00
|
|
|
if (!dvert || defgroup < 0) {
|
|
|
|
|
BLI_assert(0);
|
2011-12-08 03:47:45 +00:00
|
|
|
return;
|
2015-07-14 08:41:15 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
dw_new = static_cast<MDeformWeight *>(
|
|
|
|
|
MEM_callocN(sizeof(MDeformWeight) * (dvert->totweight + 1), __func__));
|
2012-03-20 04:27:14 +00:00
|
|
|
if (dvert->dw) {
|
2020-07-10 18:02:51 +02:00
|
|
|
memcpy(dw_new, dvert->dw, sizeof(MDeformWeight) * dvert->totweight);
|
2011-12-08 03:47:45 +00:00
|
|
|
MEM_freeN(dvert->dw);
|
2011-11-30 07:39:54 +00:00
|
|
|
}
|
2011-12-08 03:47:45 +00:00
|
|
|
dvert->dw = dw_new;
|
2020-07-10 18:02:51 +02:00
|
|
|
dw_new += dvert->totweight;
|
2011-12-08 03:47:45 +00:00
|
|
|
dw_new->weight = weight;
|
|
|
|
|
dw_new->def_nr = defgroup;
|
|
|
|
|
dvert->totweight++;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw)
|
2011-12-08 03:47:45 +00:00
|
|
|
{
|
2023-09-08 13:42:47 +10:00
|
|
|
if (UNLIKELY(!dvert || !dw)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-09-08 13:46:01 +10:00
|
|
|
/* Ensure `dw` is part of `dvert` (security check). */
|
2023-09-08 16:50:51 +10:00
|
|
|
if (UNLIKELY(uintptr_t(dw - dvert->dw) >= uintptr_t(dvert->totweight))) {
|
2023-09-08 14:56:07 +10:00
|
|
|
/* Assert as an invalid `dw` (while supported) isn't likely to do what the caller expected. */
|
|
|
|
|
BLI_assert_unreachable();
|
2023-09-08 13:42:47 +10:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-08 13:46:01 +10:00
|
|
|
const int i = dw - dvert->dw;
|
2023-09-08 13:42:47 +10:00
|
|
|
dvert->totweight--;
|
|
|
|
|
/* If there are still other deform weights attached to this vert then remove
|
|
|
|
|
* this deform weight, and reshuffle the others. */
|
|
|
|
|
if (dvert->totweight) {
|
|
|
|
|
BLI_assert(dvert->dw != nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
if (i != dvert->totweight) {
|
|
|
|
|
dvert->dw[i] = dvert->dw[dvert->totweight];
|
2011-11-30 07:39:54 +00:00
|
|
|
}
|
2023-09-08 13:42:47 +10:00
|
|
|
|
|
|
|
|
dvert->dw = static_cast<MDeformWeight *>(
|
|
|
|
|
MEM_reallocN(dvert->dw, sizeof(MDeformWeight) * dvert->totweight));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* If there are no other deform weights left then just remove this one. */
|
|
|
|
|
MEM_freeN(dvert->dw);
|
|
|
|
|
dvert->dw = nullptr;
|
2011-11-30 07:39:54 +00:00
|
|
|
}
|
2010-01-26 17:07:47 +00:00
|
|
|
}
|
2012-03-29 13:09:07 +00:00
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
void BKE_defvert_clear(MDeformVert *dvert)
|
2012-03-29 13:09:07 +00:00
|
|
|
{
|
2021-08-06 13:59:38 +10:00
|
|
|
MEM_SAFE_FREE(dvert->dw);
|
2012-03-29 13:09:07 +00:00
|
|
|
|
|
|
|
|
dvert->totweight = 0;
|
|
|
|
|
}
|
2012-10-30 11:40:36 +00:00
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
int BKE_defvert_find_shared(const MDeformVert *dvert_a, const MDeformVert *dvert_b)
|
2012-10-30 11:40:36 +00:00
|
|
|
{
|
|
|
|
|
if (dvert_a->totweight && dvert_b->totweight) {
|
|
|
|
|
MDeformWeight *dw = dvert_a->dw;
|
2022-09-26 10:56:05 +10:00
|
|
|
uint i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-30 11:40:36 +00:00
|
|
|
for (i = dvert_a->totweight; i != 0; i--, dw++) {
|
2020-03-06 12:50:56 +11:00
|
|
|
if (dw->weight > 0.0f && BKE_defvert_find_weight(dvert_b, dw->def_nr) > 0.0f) {
|
2012-10-30 11:40:36 +00:00
|
|
|
return dw->def_nr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-30 11:40:36 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-12-28 09:06:48 +00:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
bool BKE_defvert_is_weight_zero(const MDeformVert *dvert, const int defgroup_tot)
|
2013-02-22 04:09:04 +00:00
|
|
|
{
|
|
|
|
|
MDeformWeight *dw = dvert->dw;
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = dvert->totweight; i != 0; i--, dw++) {
|
2013-02-22 04:09:04 +00:00
|
|
|
if (dw->weight != 0.0f) {
|
|
|
|
|
/* check the group is in-range, happens on rare situations */
|
|
|
|
|
if (LIKELY(dw->def_nr < defgroup_tot)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
float BKE_defvert_total_selected_weight(const MDeformVert *dv,
|
2022-09-09 16:20:32 +10:00
|
|
|
int defbase_num,
|
2018-10-07 18:25:51 +03:00
|
|
|
const bool *defbase_sel)
|
2016-01-19 18:57:52 +03:00
|
|
|
{
|
|
|
|
|
float total = 0.0f;
|
|
|
|
|
const MDeformWeight *dw = dv->dw;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
if (defbase_sel == nullptr) {
|
2018-10-07 18:25:51 +03:00
|
|
|
return total;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = dv->totweight; i != 0; i--, dw++) {
|
2022-09-09 16:20:32 +10:00
|
|
|
if (dw->def_nr < defbase_num) {
|
2016-01-19 18:57:52 +03:00
|
|
|
if (defbase_sel[dw->def_nr]) {
|
|
|
|
|
total += dw->weight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-07 18:25:51 +03:00
|
|
|
return total;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
float BKE_defvert_multipaint_collective_weight(const MDeformVert *dv,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int defbase_num,
|
2018-10-07 18:25:51 +03:00
|
|
|
const bool *defbase_sel,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int defbase_sel_num,
|
|
|
|
|
const bool is_normalized)
|
2018-10-07 18:25:51 +03:00
|
|
|
{
|
2022-09-09 16:20:32 +10:00
|
|
|
float total = BKE_defvert_total_selected_weight(dv, defbase_num, defbase_sel);
|
2018-10-07 18:25:51 +03:00
|
|
|
|
|
|
|
|
/* in multipaint, get the average if auto normalize is inactive
|
|
|
|
|
* get the sum if it is active */
|
|
|
|
|
if (!is_normalized) {
|
2022-09-09 16:20:32 +10:00
|
|
|
total /= defbase_sel_num;
|
2016-01-19 18:57:52 +03:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-01-19 18:57:52 +03:00
|
|
|
return total;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 18:25:51 +03:00
|
|
|
float BKE_defvert_calc_lock_relative_weight(float weight,
|
|
|
|
|
float locked_weight,
|
|
|
|
|
float unlocked_weight)
|
|
|
|
|
{
|
|
|
|
|
/* First try normalizing unlocked weights. */
|
|
|
|
|
if (unlocked_weight > 0.0f) {
|
|
|
|
|
return weight / unlocked_weight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If no unlocked weight exists, take locked into account. */
|
|
|
|
|
if (locked_weight <= 0.0f) {
|
|
|
|
|
return weight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* handle division by zero */
|
2020-12-24 14:30:51 +03:00
|
|
|
if (locked_weight >= 1.0f - VERTEX_WEIGHT_LOCK_EPSILON) {
|
2018-10-07 18:25:51 +03:00
|
|
|
if (weight != 0.0f) {
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
|
|
|
|
|
/* resolve 0/0 to 0 */
|
|
|
|
|
return 0.0f;
|
2018-10-07 18:25:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* non-degenerate division */
|
|
|
|
|
return weight / (1.0f - locked_weight);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
float BKE_defvert_lock_relative_weight(const float weight,
|
2023-01-21 15:44:58 -06:00
|
|
|
const MDeformVert *dv,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int defbase_num,
|
2018-10-07 18:25:51 +03:00
|
|
|
const bool *defbase_locked,
|
|
|
|
|
const bool *defbase_unlocked)
|
|
|
|
|
{
|
2022-09-09 16:20:32 +10:00
|
|
|
float unlocked = BKE_defvert_total_selected_weight(dv, defbase_num, defbase_unlocked);
|
2018-10-07 18:25:51 +03:00
|
|
|
|
|
|
|
|
if (unlocked > 0.0f) {
|
|
|
|
|
return weight / unlocked;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
float locked = BKE_defvert_total_selected_weight(dv, defbase_num, defbase_locked);
|
2018-10-07 18:25:51 +03:00
|
|
|
|
|
|
|
|
return BKE_defvert_calc_lock_relative_weight(weight, locked, unlocked);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-28 09:06:48 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
2016-02-08 22:40:57 +11:00
|
|
|
/** \name Defvert Array functions
|
|
|
|
|
* \{ */
|
2012-12-28 09:06:48 +00:00
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totvert)
|
2012-12-28 09:06:48 +00:00
|
|
|
{
|
|
|
|
|
/* Assumes dst is already set up */
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!src || !dst) {
|
2012-12-28 09:06:48 +00:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-12-28 09:06:48 +00:00
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
memcpy(dst, src, totvert * sizeof(MDeformVert));
|
2012-12-28 09:06:48 +00:00
|
|
|
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = 0; i < totvert; i++) {
|
2012-12-28 09:06:48 +00:00
|
|
|
if (src[i].dw) {
|
2023-01-21 15:44:58 -06:00
|
|
|
dst[i].dw = static_cast<MDeformWeight *>(
|
|
|
|
|
MEM_mallocN(sizeof(MDeformWeight) * src[i].totweight, __func__));
|
2012-12-28 09:06:48 +00:00
|
|
|
memcpy(dst[i].dw, src[i].dw, sizeof(MDeformWeight) * src[i].totweight);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2012-12-28 09:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-11 04:43:49 +00:00
|
|
|
void BKE_defvert_array_free_elems(MDeformVert *dvert, int totvert)
|
2012-12-28 09:06:48 +00:00
|
|
|
{
|
|
|
|
|
/* Instead of freeing the verts directly,
|
|
|
|
|
* call this function to delete any special
|
|
|
|
|
* vert data */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!dvert) {
|
2012-12-28 09:06:48 +00:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 09:06:48 +00:00
|
|
|
/* Free any special data from the verts */
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = 0; i < totvert; i++) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (dvert[i].dw) {
|
2012-12-28 09:06:48 +00:00
|
|
|
MEM_freeN(dvert[i].dw);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-12-28 09:06:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-11 04:43:49 +00:00
|
|
|
void BKE_defvert_array_free(MDeformVert *dvert, int totvert)
|
|
|
|
|
{
|
|
|
|
|
/* Instead of freeing the verts directly,
|
|
|
|
|
* call this function to delete any special
|
|
|
|
|
* vert data */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!dvert) {
|
2013-02-11 04:43:49 +00:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-02-11 04:43:49 +00:00
|
|
|
|
|
|
|
|
/* Free any special data from the verts */
|
|
|
|
|
BKE_defvert_array_free_elems(dvert, totvert);
|
|
|
|
|
|
|
|
|
|
MEM_freeN(dvert);
|
|
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
|
2022-05-13 18:31:29 +02:00
|
|
|
void BKE_defvert_extract_vgroup_to_vertweights(const MDeformVert *dvert,
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
const int defgroup,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int verts_num,
|
2022-05-13 18:31:29 +02:00
|
|
|
const bool invert_vgroup,
|
|
|
|
|
float *r_weights)
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
{
|
|
|
|
|
if (dvert && defgroup != -1) {
|
2022-09-09 16:20:32 +10:00
|
|
|
int i = verts_num;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
while (i--) {
|
2020-03-06 12:50:56 +11:00
|
|
|
const float w = BKE_defvert_find_weight(&dvert[i], defgroup);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
r_weights[i] = invert_vgroup ? (1.0f - w) : w;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-09-09 16:20:32 +10:00
|
|
|
copy_vn_fl(r_weights, verts_num, invert_vgroup ? 1.0f : 0.0f);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 18:31:29 +02:00
|
|
|
void BKE_defvert_extract_vgroup_to_edgeweights(const MDeformVert *dvert,
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
const int defgroup,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int verts_num,
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
const blender::int2 *edges,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int edges_num,
|
2022-05-13 18:31:29 +02:00
|
|
|
const bool invert_vgroup,
|
|
|
|
|
float *r_weights)
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
{
|
2023-09-08 13:42:47 +10:00
|
|
|
if (UNLIKELY(!dvert || defgroup == -1)) {
|
|
|
|
|
copy_vn_fl(r_weights, edges_num, 0.0f);
|
|
|
|
|
return;
|
|
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
int i = edges_num;
|
|
|
|
|
float *tmp_weights = static_cast<float *>(
|
|
|
|
|
MEM_mallocN(sizeof(*tmp_weights) * size_t(verts_num), __func__));
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
BKE_defvert_extract_vgroup_to_vertweights(
|
|
|
|
|
dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
while (i--) {
|
|
|
|
|
const blender::int2 &edge = edges[i];
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
r_weights[i] = (tmp_weights[edge[0]] + tmp_weights[edge[1]]) * 0.5f;
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
2023-09-08 13:42:47 +10:00
|
|
|
|
|
|
|
|
MEM_freeN(tmp_weights);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-13 18:31:29 +02:00
|
|
|
void BKE_defvert_extract_vgroup_to_loopweights(const MDeformVert *dvert,
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
const int defgroup,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int verts_num,
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
const int *corner_verts,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int loops_num,
|
2022-05-13 18:31:29 +02:00
|
|
|
const bool invert_vgroup,
|
|
|
|
|
float *r_weights)
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
{
|
2023-09-08 13:42:47 +10:00
|
|
|
if (UNLIKELY(!dvert || defgroup == -1)) {
|
|
|
|
|
copy_vn_fl(r_weights, loops_num, 0.0f);
|
|
|
|
|
return;
|
|
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
int i = loops_num;
|
|
|
|
|
float *tmp_weights = static_cast<float *>(
|
|
|
|
|
MEM_mallocN(sizeof(*tmp_weights) * size_t(verts_num), __func__));
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
BKE_defvert_extract_vgroup_to_vertweights(
|
|
|
|
|
dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
while (i--) {
|
|
|
|
|
r_weights[i] = tmp_weights[corner_verts[i]];
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
2023-09-08 13:42:47 +10:00
|
|
|
|
|
|
|
|
MEM_freeN(tmp_weights);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
void BKE_defvert_extract_vgroup_to_faceweights(const MDeformVert *dvert,
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
const int defgroup,
|
2022-09-09 16:20:32 +10:00
|
|
|
const int verts_num,
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
const int *corner_verts,
|
2023-01-21 15:44:58 -06:00
|
|
|
const int /*loops_num*/,
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::OffsetIndices<int> faces,
|
2022-05-13 18:31:29 +02:00
|
|
|
const bool invert_vgroup,
|
|
|
|
|
float *r_weights)
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
{
|
2023-09-08 13:42:47 +10:00
|
|
|
if (UNLIKELY(!dvert || defgroup == -1)) {
|
|
|
|
|
copy_vn_fl(r_weights, faces.size(), 0.0f);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
int i = faces.size();
|
|
|
|
|
float *tmp_weights = static_cast<float *>(
|
|
|
|
|
MEM_mallocN(sizeof(*tmp_weights) * size_t(verts_num), __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
BKE_defvert_extract_vgroup_to_vertweights(
|
|
|
|
|
dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
while (i--) {
|
|
|
|
|
const blender::IndexRange face = faces[i];
|
|
|
|
|
const int *corner_vert = &corner_verts[face.start()];
|
|
|
|
|
int j = face.size();
|
|
|
|
|
float w = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-08 13:42:47 +10:00
|
|
|
for (; j--; corner_vert++) {
|
|
|
|
|
w += tmp_weights[*corner_vert];
|
|
|
|
|
}
|
|
|
|
|
r_weights[i] = w / float(face.size());
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
2023-09-08 13:42:47 +10:00
|
|
|
|
|
|
|
|
MEM_freeN(tmp_weights);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-08 22:40:57 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Data Transfer
|
|
|
|
|
* \{ */
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
|
2015-02-23 13:51:55 +11:00
|
|
|
static void vgroups_datatransfer_interp(const CustomDataTransferLayerMap *laymap,
|
|
|
|
|
void *dest,
|
|
|
|
|
const void **sources,
|
|
|
|
|
const float *weights,
|
|
|
|
|
const int count,
|
|
|
|
|
const float mix_factor)
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
{
|
|
|
|
|
MDeformVert **data_src = (MDeformVert **)sources;
|
|
|
|
|
MDeformVert *data_dst = (MDeformVert *)dest;
|
|
|
|
|
const int idx_src = laymap->data_src_n;
|
|
|
|
|
const int idx_dst = laymap->data_dst_n;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
const int mix_mode = laymap->mix_mode;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
int i, j;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
MDeformWeight *dw_src;
|
2020-03-06 12:50:56 +11:00
|
|
|
MDeformWeight *dw_dst = BKE_defvert_find_index(data_dst, idx_dst);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
float weight_src = 0.0f, weight_dst = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-10 11:33:53 +02:00
|
|
|
bool has_dw_sources = false;
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (sources) {
|
|
|
|
|
for (i = count; i--;) {
|
|
|
|
|
for (j = data_src[i]->totweight; j--;) {
|
|
|
|
|
if ((dw_src = &data_src[i]->dw[j])->def_nr == idx_src) {
|
|
|
|
|
weight_src += dw_src->weight * weights[i];
|
2021-06-10 11:33:53 +02:00
|
|
|
has_dw_sources = true;
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (dw_dst) {
|
|
|
|
|
weight_dst = dw_dst->weight;
|
|
|
|
|
}
|
|
|
|
|
else if (mix_mode == CDT_MIX_REPLACE_ABOVE_THRESHOLD) {
|
|
|
|
|
return; /* Do not affect destination. */
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
weight_src = data_transfer_interp_float_do(mix_mode, weight_dst, weight_src, mix_factor);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
CLAMP(weight_src, 0.0f, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-10 11:33:53 +02:00
|
|
|
/* Do not create a destination MDeformWeight data if we had no sources at all. */
|
|
|
|
|
if (!has_dw_sources) {
|
|
|
|
|
BLI_assert(weight_src == 0.0f);
|
|
|
|
|
if (dw_dst) {
|
|
|
|
|
dw_dst->weight = weight_src;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!dw_dst) {
|
2020-03-06 12:50:56 +11:00
|
|
|
BKE_defvert_add_index_notest(data_dst, idx_dst, weight_src);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dw_dst->weight = weight_src;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2022-05-13 18:31:29 +02:00
|
|
|
const MDeformVert *data_src,
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
MDeformVert *data_dst,
|
2023-01-21 15:44:58 -06:00
|
|
|
const CustomData * /*cd_src*/,
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
CustomData *cd_dst,
|
2023-01-21 15:44:58 -06:00
|
|
|
const bool /*use_dupref_dst*/,
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
const int tolayers,
|
2020-07-13 11:27:09 +02:00
|
|
|
const bool *use_layers_src,
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
const int num_layers_src)
|
|
|
|
|
{
|
|
|
|
|
int idx_src;
|
|
|
|
|
int idx_dst;
|
2021-07-13 12:10:34 -04:00
|
|
|
const ListBase *src_list = BKE_object_defgroup_list(ob_src);
|
|
|
|
|
ListBase *dst_defbase = BKE_object_defgroup_list_mutable(ob_dst);
|
|
|
|
|
|
2022-09-09 16:20:32 +10:00
|
|
|
const int tot_dst = BLI_listbase_count(dst_defbase);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-03 20:23:01 +10:00
|
|
|
const size_t elem_size = sizeof(MDeformVert);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
switch (tolayers) {
|
|
|
|
|
case DT_LAYERS_INDEX_DST:
|
|
|
|
|
idx_dst = tot_dst;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
/* Find last source actually used! */
|
|
|
|
|
idx_src = num_layers_src;
|
2019-04-22 09:39:35 +10:00
|
|
|
while (idx_src-- && !use_layers_src[idx_src]) {
|
2019-05-03 12:41:06 +10:00
|
|
|
/* pass */
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
idx_src++;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (idx_dst < idx_src) {
|
2019-02-08 10:12:31 +01:00
|
|
|
if (use_create) {
|
|
|
|
|
/* Create as much vgroups as necessary! */
|
|
|
|
|
for (; idx_dst < idx_src; idx_dst++) {
|
|
|
|
|
BKE_object_defgroup_add(ob_dst);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-02-08 10:12:31 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Otherwise, just try to map what we can with existing dst vgroups. */
|
|
|
|
|
idx_src = idx_dst;
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (use_delete && idx_dst > idx_src) {
|
|
|
|
|
while (idx_dst-- > idx_src) {
|
2023-01-21 15:44:58 -06:00
|
|
|
BKE_object_defgroup_remove(ob_dst, static_cast<bDeformGroup *>(dst_defbase->last));
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (r_map) {
|
|
|
|
|
/* At this stage, we **need** a valid CD_MDEFORMVERT layer on dest!
|
|
|
|
|
* Again, use_create is not relevant in this case */
|
|
|
|
|
if (!data_dst) {
|
2023-01-21 15:44:58 -06:00
|
|
|
data_dst = static_cast<MDeformVert *>(
|
2023-03-14 15:30:26 +01:00
|
|
|
CustomData_add_layer(cd_dst, CD_MDEFORMVERT, CD_SET_DEFAULT, num_elem_dst));
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
while (idx_src--) {
|
|
|
|
|
if (!use_layers_src[idx_src]) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
data_transfer_layersmapping_add_item(r_map,
|
|
|
|
|
CD_FAKE_MDEFORMVERT,
|
|
|
|
|
mix_mode,
|
|
|
|
|
mix_factor,
|
|
|
|
|
mix_weights,
|
|
|
|
|
data_src,
|
|
|
|
|
data_dst,
|
|
|
|
|
idx_src,
|
|
|
|
|
idx_src,
|
2015-10-16 21:28:22 +02:00
|
|
|
elem_size,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
vgroups_datatransfer_interp,
|
2023-01-21 15:44:58 -06:00
|
|
|
nullptr);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
break;
|
|
|
|
|
case DT_LAYERS_NAME_DST: {
|
|
|
|
|
bDeformGroup *dg_src, *dg_dst;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (use_delete) {
|
|
|
|
|
/* Remove all unused dst vgroups first, simpler in this case. */
|
2023-01-21 15:44:58 -06:00
|
|
|
for (dg_dst = static_cast<bDeformGroup *>(dst_defbase->first); dg_dst;) {
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
bDeformGroup *dg_dst_next = dg_dst->next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
if (BKE_object_defgroup_name_index(ob_src, dg_dst->name) == -1) {
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
BKE_object_defgroup_remove(ob_dst, dg_dst);
|
|
|
|
|
}
|
|
|
|
|
dg_dst = dg_dst_next;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
for (idx_src = 0, dg_src = static_cast<bDeformGroup *>(src_list->first);
|
|
|
|
|
idx_src < num_layers_src;
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
idx_src++, dg_src = dg_src->next)
|
|
|
|
|
{
|
|
|
|
|
if (!use_layers_src[idx_src]) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 12:50:56 +11:00
|
|
|
if ((idx_dst = BKE_object_defgroup_name_index(ob_dst, dg_src->name)) == -1) {
|
2019-02-08 10:12:31 +01:00
|
|
|
if (use_create) {
|
|
|
|
|
BKE_object_defgroup_add_name(ob_dst, dg_src->name);
|
2021-07-13 12:10:34 -04:00
|
|
|
idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
|
2019-02-08 10:12:31 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* If we are not allowed to create missing dst vgroups, just skip matching src one. */
|
|
|
|
|
continue;
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (r_map) {
|
|
|
|
|
/* At this stage, we **need** a valid CD_MDEFORMVERT layer on dest!
|
2019-04-18 07:21:26 +02:00
|
|
|
* use_create is not relevant in this case */
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (!data_dst) {
|
2023-03-14 15:30:26 +01:00
|
|
|
data_dst = static_cast<MDeformVert *>(
|
|
|
|
|
CustomData_add_layer(cd_dst, CD_MDEFORMVERT, CD_SET_DEFAULT, num_elem_dst));
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
data_transfer_layersmapping_add_item(r_map,
|
|
|
|
|
CD_FAKE_MDEFORMVERT,
|
|
|
|
|
mix_mode,
|
|
|
|
|
mix_factor,
|
|
|
|
|
mix_weights,
|
|
|
|
|
data_src,
|
|
|
|
|
data_dst,
|
|
|
|
|
idx_src,
|
|
|
|
|
idx_dst,
|
2015-10-16 21:28:22 +02:00
|
|
|
elem_size,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
vgroups_datatransfer_interp,
|
2023-01-21 15:44:58 -06:00
|
|
|
nullptr);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2023-01-13 14:50:59 -06:00
|
|
|
const CustomData *cd_src,
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
CustomData *cd_dst,
|
|
|
|
|
const bool use_dupref_dst,
|
|
|
|
|
const int fromlayers,
|
|
|
|
|
const int tolayers)
|
|
|
|
|
{
|
|
|
|
|
int idx_src, idx_dst;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-03 20:23:01 +10:00
|
|
|
const size_t elem_size = sizeof(MDeformVert);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE:
|
2019-04-27 12:07:07 +10:00
|
|
|
* VGroups are a bit hairy, since their layout is defined on object level (ob->defbase),
|
|
|
|
|
* while their actual data is a (mesh) CD layer.
|
2023-01-21 15:44:58 -06:00
|
|
|
* This implies we may have to handle data layout itself while having nullptr data itself,
|
|
|
|
|
* and even have to support nullptr data_src in transfer data code
|
2019-04-27 12:07:07 +10:00
|
|
|
* (we always create a data_dst, though).
|
2021-07-13 12:10:34 -04:00
|
|
|
*
|
2021-11-30 09:10:05 +11:00
|
|
|
* NOTE: Above comment is outdated, but this function was written when that was true.
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
*/
|
2021-07-13 12:10:34 -04:00
|
|
|
|
|
|
|
|
const ListBase *src_defbase = BKE_object_defgroup_list(ob_src);
|
|
|
|
|
if (BLI_listbase_is_empty(src_defbase)) {
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (use_delete) {
|
|
|
|
|
BKE_object_defgroup_remove_all(ob_dst);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
const MDeformVert *data_src = static_cast<const MDeformVert *>(
|
|
|
|
|
CustomData_get_layer(cd_src, CD_MDEFORMVERT));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-21 15:44:58 -06:00
|
|
|
MDeformVert *data_dst = static_cast<MDeformVert *>(
|
|
|
|
|
CustomData_get_layer_for_write(cd_dst, CD_MDEFORMVERT, num_elem_dst));
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (data_dst && use_dupref_dst && r_map) {
|
|
|
|
|
/* If dest is a derivedmesh, we do not want to overwrite cdlayers of org mesh! */
|
2023-01-21 15:44:58 -06:00
|
|
|
data_dst = static_cast<MDeformVert *>(
|
|
|
|
|
CustomData_get_layer_for_write(cd_dst, CD_MDEFORMVERT, num_elem_dst));
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (fromlayers == DT_LAYERS_ACTIVE_SRC || fromlayers >= 0) {
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: use_delete has not much meaning in this case, ignored. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (fromlayers >= 0) {
|
|
|
|
|
idx_src = fromlayers;
|
2021-07-13 12:10:34 -04:00
|
|
|
if (idx_src >= BLI_listbase_count(src_defbase)) {
|
2018-06-16 16:19:53 +02:00
|
|
|
/* This can happen when vgroups are removed from source object...
|
2019-02-11 10:51:25 +11:00
|
|
|
* Remapping would be really tricky here, we'd need to go over all objects in
|
|
|
|
|
* Main every time we delete a vgroup... for now, simpler and safer to abort. */
|
2018-06-16 16:19:53 +02:00
|
|
|
return false;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-16 16:19:53 +02:00
|
|
|
}
|
2021-07-13 12:10:34 -04:00
|
|
|
else if ((idx_src = BKE_object_defgroup_active_index_get(ob_src) - 1) == -1) {
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (tolayers >= 0) {
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: in this case we assume layer exists! */
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
idx_dst = tolayers;
|
2021-07-13 12:10:34 -04:00
|
|
|
const ListBase *dst_defbase = BKE_object_defgroup_list(ob_dst);
|
|
|
|
|
BLI_assert(idx_dst < BLI_listbase_count(dst_defbase));
|
|
|
|
|
UNUSED_VARS_NDEBUG(dst_defbase);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
else if (tolayers == DT_LAYERS_ACTIVE_DST) {
|
2021-07-13 12:10:34 -04:00
|
|
|
if ((idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1) == -1) {
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
bDeformGroup *dg_src;
|
|
|
|
|
if (!use_create) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-01-21 15:44:58 -06:00
|
|
|
dg_src = static_cast<bDeformGroup *>(BLI_findlink(src_defbase, idx_src));
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
BKE_object_defgroup_add_name(ob_dst, dg_src->name);
|
2021-07-13 12:10:34 -04:00
|
|
|
idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
else if (tolayers == DT_LAYERS_INDEX_DST) {
|
2021-07-13 12:10:34 -04:00
|
|
|
int num = BLI_listbase_count(src_defbase);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
idx_dst = idx_src;
|
|
|
|
|
if (num <= idx_dst) {
|
|
|
|
|
if (!use_create) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
/* Create as much vgroups as necessary! */
|
|
|
|
|
for (; num <= idx_dst; num++) {
|
|
|
|
|
BKE_object_defgroup_add(ob_dst);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
else if (tolayers == DT_LAYERS_NAME_DST) {
|
2023-01-21 15:44:58 -06:00
|
|
|
bDeformGroup *dg_src = static_cast<bDeformGroup *>(BLI_findlink(src_defbase, idx_src));
|
2020-03-06 12:50:56 +11:00
|
|
|
if ((idx_dst = BKE_object_defgroup_name_index(ob_dst, dg_src->name)) == -1) {
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (!use_create) {
|
|
|
|
|
return true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
BKE_object_defgroup_add_name(ob_dst, dg_src->name);
|
2021-07-13 12:10:34 -04:00
|
|
|
idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
else {
|
|
|
|
|
return false;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (r_map) {
|
|
|
|
|
/* At this stage, we **need** a valid CD_MDEFORMVERT layer on dest!
|
|
|
|
|
* use_create is not relevant in this case */
|
|
|
|
|
if (!data_dst) {
|
2023-01-21 15:44:58 -06:00
|
|
|
data_dst = static_cast<MDeformVert *>(
|
2023-03-14 15:30:26 +01:00
|
|
|
CustomData_add_layer(cd_dst, CD_MDEFORMVERT, CD_SET_DEFAULT, num_elem_dst));
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
data_transfer_layersmapping_add_item(r_map,
|
|
|
|
|
CD_FAKE_MDEFORMVERT,
|
|
|
|
|
mix_mode,
|
|
|
|
|
mix_factor,
|
|
|
|
|
mix_weights,
|
|
|
|
|
data_src,
|
|
|
|
|
data_dst,
|
|
|
|
|
idx_src,
|
|
|
|
|
idx_dst,
|
2015-10-16 21:28:22 +02:00
|
|
|
elem_size,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
vgroups_datatransfer_interp,
|
2023-01-21 15:44:58 -06:00
|
|
|
nullptr);
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
int num_src, num_sel_unused;
|
2023-01-21 15:44:58 -06:00
|
|
|
bool *use_layers_src = nullptr;
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
bool ret = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
switch (fromlayers) {
|
|
|
|
|
case DT_LAYERS_ALL_SRC:
|
|
|
|
|
use_layers_src = BKE_object_defgroup_subset_from_select_type(
|
|
|
|
|
ob_src, WT_VGROUP_ALL, &num_src, &num_sel_unused);
|
|
|
|
|
break;
|
|
|
|
|
case DT_LAYERS_VGROUP_SRC_BONE_SELECT:
|
|
|
|
|
use_layers_src = BKE_object_defgroup_subset_from_select_type(
|
|
|
|
|
ob_src, WT_VGROUP_BONE_SELECT, &num_src, &num_sel_unused);
|
|
|
|
|
break;
|
|
|
|
|
case DT_LAYERS_VGROUP_SRC_BONE_DEFORM:
|
|
|
|
|
use_layers_src = BKE_object_defgroup_subset_from_select_type(
|
|
|
|
|
ob_src, WT_VGROUP_BONE_DEFORM, &num_src, &num_sel_unused);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
if (use_layers_src) {
|
|
|
|
|
ret = data_transfer_layersmapping_vgroups_multisrc_to_dst(r_map,
|
|
|
|
|
mix_mode,
|
|
|
|
|
mix_factor,
|
|
|
|
|
mix_weights,
|
|
|
|
|
num_elem_dst,
|
|
|
|
|
use_create,
|
|
|
|
|
use_delete,
|
|
|
|
|
ob_src,
|
|
|
|
|
ob_dst,
|
|
|
|
|
data_src,
|
|
|
|
|
data_dst,
|
|
|
|
|
cd_src,
|
|
|
|
|
cd_dst,
|
|
|
|
|
use_dupref_dst,
|
|
|
|
|
tolayers,
|
|
|
|
|
use_layers_src,
|
|
|
|
|
num_src);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
MEM_SAFE_FREE(use_layers_src);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Transfer Data: add main core code and operators.
This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.
This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.
Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).
Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
usable one in weightpaint mode (it transfers from selected object to active one,
this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.
Again, heavily reviewed and enhanced by Campbell, thanks!
2015-01-09 19:11:40 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2016-02-08 22:40:57 +11:00
|
|
|
|
|
|
|
|
/** \} */
|
2018-06-29 14:56:38 +02:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Various utils & helpers.
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
void BKE_defvert_weight_to_rgb(float r_rgb[3], const float weight)
|
|
|
|
|
{
|
|
|
|
|
const float blend = ((weight / 2.0f) + 0.5f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-29 14:56:38 +02:00
|
|
|
if (weight <= 0.25f) { /* blue->cyan */
|
|
|
|
|
r_rgb[0] = 0.0f;
|
|
|
|
|
r_rgb[1] = blend * weight * 4.0f;
|
|
|
|
|
r_rgb[2] = blend;
|
|
|
|
|
}
|
|
|
|
|
else if (weight <= 0.50f) { /* cyan->green */
|
|
|
|
|
r_rgb[0] = 0.0f;
|
|
|
|
|
r_rgb[1] = blend;
|
|
|
|
|
r_rgb[2] = blend * (1.0f - ((weight - 0.25f) * 4.0f));
|
|
|
|
|
}
|
|
|
|
|
else if (weight <= 0.75f) { /* green->yellow */
|
|
|
|
|
r_rgb[0] = blend * ((weight - 0.50f) * 4.0f);
|
|
|
|
|
r_rgb[1] = blend;
|
|
|
|
|
r_rgb[2] = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
else if (weight <= 1.0f) { /* yellow->red */
|
|
|
|
|
r_rgb[0] = blend;
|
|
|
|
|
r_rgb[1] = blend * (1.0f - ((weight - 0.75f) * 4.0f));
|
|
|
|
|
r_rgb[2] = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* exceptional value, unclamped or nan,
|
|
|
|
|
* avoid uninitialized memory use */
|
|
|
|
|
r_rgb[0] = 1.0f;
|
|
|
|
|
r_rgb[1] = 0.0f;
|
|
|
|
|
r_rgb[2] = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
2020-08-28 13:58:39 +02:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name .blend file I/O
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2021-07-13 12:10:34 -04:00
|
|
|
void BKE_defbase_blend_write(BlendWriter *writer, const ListBase *defbase)
|
|
|
|
|
{
|
|
|
|
|
LISTBASE_FOREACH (bDeformGroup *, defgroup, defbase) {
|
|
|
|
|
BLO_write_struct(writer, bDeformGroup, defgroup);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-22 20:06:24 +02:00
|
|
|
void BKE_defvert_blend_write(BlendWriter *writer, int count, const MDeformVert *dvlist)
|
2020-08-28 13:58:39 +02:00
|
|
|
{
|
2023-01-21 15:44:58 -06:00
|
|
|
if (dvlist == nullptr) {
|
2020-08-28 13:58:39 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Write the dvert list */
|
|
|
|
|
BLO_write_struct_array(writer, MDeformVert, count, dvlist);
|
|
|
|
|
|
|
|
|
|
/* Write deformation data for each dvert */
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
if (dvlist[i].dw) {
|
|
|
|
|
BLO_write_struct_array(writer, MDeformWeight, dvlist[i].totweight, dvlist[i].dw);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_defvert_blend_read(BlendDataReader *reader, int count, MDeformVert *mdverts)
|
|
|
|
|
{
|
2023-01-21 15:44:58 -06:00
|
|
|
if (mdverts == nullptr) {
|
2020-08-28 13:58:39 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = count; i > 0; i--, mdverts++) {
|
2020-08-29 10:48:33 +10:00
|
|
|
/* Convert to vertex group allocation system. */
|
2020-08-28 13:58:39 +02:00
|
|
|
MDeformWeight *dw;
|
2023-01-21 15:44:58 -06:00
|
|
|
if (mdverts->dw &&
|
|
|
|
|
(dw = static_cast<MDeformWeight *>(BLO_read_get_new_data_address(reader, mdverts->dw))))
|
|
|
|
|
{
|
2020-08-29 10:48:33 +10:00
|
|
|
const size_t dw_len = sizeof(MDeformWeight) * mdverts->totweight;
|
2020-08-28 13:58:39 +02:00
|
|
|
void *dw_tmp = MEM_mallocN(dw_len, __func__);
|
|
|
|
|
memcpy(dw_tmp, dw, dw_len);
|
2023-01-21 15:44:58 -06:00
|
|
|
mdverts->dw = static_cast<MDeformWeight *>(dw_tmp);
|
2020-08-28 13:58:39 +02:00
|
|
|
MEM_freeN(dw);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-01-21 15:44:58 -06:00
|
|
|
mdverts->dw = nullptr;
|
2020-08-28 13:58:39 +02:00
|
|
|
mdverts->totweight = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
2023-09-27 10:26:06 +02:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Virtual array implementation for vertex groups.
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
namespace blender::bke {
|
|
|
|
|
|
|
|
|
|
class VArrayImpl_For_VertexWeights final : public VMutableArrayImpl<float> {
|
|
|
|
|
private:
|
|
|
|
|
MDeformVert *dverts_;
|
|
|
|
|
const int dvert_index_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
VArrayImpl_For_VertexWeights(MutableSpan<MDeformVert> dverts, const int dvert_index)
|
|
|
|
|
: VMutableArrayImpl<float>(dverts.size()), dverts_(dverts.data()), dvert_index_(dvert_index)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VArrayImpl_For_VertexWeights(Span<MDeformVert> dverts, const int dvert_index)
|
|
|
|
|
: VMutableArrayImpl<float>(dverts.size()),
|
|
|
|
|
dverts_(const_cast<MDeformVert *>(dverts.data())),
|
|
|
|
|
dvert_index_(dvert_index)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float get(const int64_t index) const override
|
|
|
|
|
{
|
|
|
|
|
if (dverts_ == nullptr) {
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
if (const MDeformWeight *weight = this->find_weight_at_index(index)) {
|
|
|
|
|
return weight->weight;
|
|
|
|
|
}
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set(const int64_t index, const float value) override
|
|
|
|
|
{
|
|
|
|
|
MDeformVert &dvert = dverts_[index];
|
|
|
|
|
if (value == 0.0f) {
|
|
|
|
|
if (MDeformWeight *weight = this->find_weight_at_index(index)) {
|
|
|
|
|
weight->weight = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
MDeformWeight *weight = BKE_defvert_ensure_index(&dvert, dvert_index_);
|
|
|
|
|
weight->weight = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_all(Span<float> src) override
|
|
|
|
|
{
|
|
|
|
|
threading::parallel_for(src.index_range(), 4096, [&](const IndexRange range) {
|
|
|
|
|
for (const int64_t i : range) {
|
|
|
|
|
this->set(i, src[i]);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void materialize(const IndexMask &mask, float *dst) const override
|
|
|
|
|
{
|
|
|
|
|
if (dverts_ == nullptr) {
|
|
|
|
|
mask.foreach_index([&](const int i) { dst[i] = 0.0f; });
|
|
|
|
|
}
|
|
|
|
|
threading::parallel_for(mask.index_range(), 4096, [&](const IndexRange range) {
|
|
|
|
|
mask.slice(range).foreach_index_optimized<int64_t>([&](const int64_t index) {
|
|
|
|
|
if (const MDeformWeight *weight = this->find_weight_at_index(index)) {
|
|
|
|
|
dst[index] = weight->weight;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dst[index] = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void materialize_to_uninitialized(const IndexMask &mask, float *dst) const override
|
|
|
|
|
{
|
|
|
|
|
this->materialize(mask, dst);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MDeformWeight *find_weight_at_index(const int64_t index)
|
|
|
|
|
{
|
|
|
|
|
for (MDeformWeight &weight : MutableSpan(dverts_[index].dw, dverts_[index].totweight)) {
|
|
|
|
|
if (weight.def_nr == dvert_index_) {
|
|
|
|
|
return &weight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
const MDeformWeight *find_weight_at_index(const int64_t index) const
|
|
|
|
|
{
|
|
|
|
|
for (const MDeformWeight &weight : Span(dverts_[index].dw, dverts_[index].totweight)) {
|
|
|
|
|
if (weight.def_nr == dvert_index_) {
|
|
|
|
|
return &weight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VArray<float> varray_for_deform_verts(Span<MDeformVert> dverts, const int defgroup_index)
|
|
|
|
|
{
|
|
|
|
|
return VArray<float>::For<VArrayImpl_For_VertexWeights>(dverts, defgroup_index);
|
|
|
|
|
}
|
|
|
|
|
VMutableArray<float> varray_for_mutable_deform_verts(MutableSpan<MDeformVert> dverts,
|
|
|
|
|
const int defgroup_index)
|
|
|
|
|
{
|
|
|
|
|
return VMutableArray<float>::For<VArrayImpl_For_VertexWeights>(dverts, defgroup_index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void remove_defgroup_index(MutableSpan<MDeformVert> dverts, const int defgroup_index)
|
|
|
|
|
{
|
|
|
|
|
threading::parallel_for(dverts.index_range(), 1024, [&](IndexRange range) {
|
|
|
|
|
for (MDeformVert &dvert : dverts.slice(range)) {
|
|
|
|
|
MDeformWeight *weight = BKE_defvert_find_index(&dvert, defgroup_index);
|
|
|
|
|
BKE_defvert_remove_group(&dvert, weight);
|
|
|
|
|
for (MDeformWeight &weight : MutableSpan(dvert.dw, dvert.totweight)) {
|
|
|
|
|
if (weight.def_nr > defgroup_index) {
|
|
|
|
|
weight.def_nr--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace blender::bke
|
|
|
|
|
|
|
|
|
|
/** \} */
|