Blender  V2.93
data_transfer.c
Go to the documentation of this file.
1 
2 /*
3  * This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU General Public License
5  * as published by the Free Software Foundation; either version 2
6  * of the License, or (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software Foundation,
15  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  *
17  * The Original Code is Copyright (C) 2014 by Blender Foundation.
18  * All rights reserved.
19  */
20 
25 #include "CLG_log.h"
26 
27 #include "MEM_guardedalloc.h"
28 
29 #include "DNA_customdata_types.h"
30 #include "DNA_mesh_types.h"
31 #include "DNA_meshdata_types.h"
32 #include "DNA_object_types.h"
33 #include "DNA_scene_types.h"
34 
35 #include "BLI_blenlib.h"
36 #include "BLI_math.h"
37 #include "BLI_utildefines.h"
38 
39 #include "BKE_customdata.h"
40 #include "BKE_data_transfer.h"
41 #include "BKE_deform.h"
42 #include "BKE_mesh.h"
43 #include "BKE_mesh_mapping.h"
44 #include "BKE_mesh_remap.h"
45 #include "BKE_mesh_runtime.h"
46 #include "BKE_mesh_wrapper.h"
47 #include "BKE_modifier.h"
48 #include "BKE_object.h"
49 #include "BKE_object_deform.h"
50 #include "BKE_report.h"
51 
52 #include "data_transfer_intern.h"
53 
54 static CLG_LogRef LOG = {"bke.data_transfer"};
55 
56 void BKE_object_data_transfer_dttypes_to_cdmask(const int dtdata_types,
57  CustomData_MeshMasks *r_data_masks)
58 {
59  for (int i = 0; i < DT_TYPE_MAX; i++) {
60  const int dtdata_type = 1 << i;
61  int cddata_type;
62 
63  if (!(dtdata_types & dtdata_type)) {
64  continue;
65  }
66 
67  cddata_type = BKE_object_data_transfer_dttype_to_cdtype(dtdata_type);
68  if (!(cddata_type & CD_FAKE)) {
69  if (DT_DATATYPE_IS_VERT(dtdata_type)) {
70  r_data_masks->vmask |= 1LL << cddata_type;
71  }
72  else if (DT_DATATYPE_IS_EDGE(dtdata_type)) {
73  r_data_masks->emask |= 1LL << cddata_type;
74  }
75  else if (DT_DATATYPE_IS_LOOP(dtdata_type)) {
76  r_data_masks->lmask |= 1LL << cddata_type;
77  }
78  else if (DT_DATATYPE_IS_POLY(dtdata_type)) {
79  r_data_masks->pmask |= 1LL << cddata_type;
80  }
81  }
82  else if (cddata_type == CD_FAKE_MDEFORMVERT) {
83  r_data_masks->vmask |= CD_MASK_MDEFORMVERT; /* Exception for vgroups :/ */
84  }
85  else if (cddata_type == CD_FAKE_UV) {
86  r_data_masks->lmask |= CD_MASK_MLOOPUV;
87  }
88  else if (cddata_type == CD_FAKE_LNOR) {
89  r_data_masks->vmask |= CD_MASK_NORMAL;
90  r_data_masks->pmask |= CD_MASK_NORMAL;
92  }
93  }
94 }
95 
101  bool *r_advanced_mixing,
102  bool *r_threshold)
103 {
104  bool ret = false;
105 
106  *r_advanced_mixing = false;
107  *r_threshold = false;
108 
109  for (int i = 0; (i < DT_TYPE_MAX) && !(ret && *r_advanced_mixing && *r_threshold); i++) {
110  const int dtdata_type = 1 << i;
111 
112  if (!(dtdata_types & dtdata_type)) {
113  continue;
114  }
115 
116  switch (dtdata_type) {
117  /* Vertex data */
118  case DT_TYPE_MDEFORMVERT:
119  *r_advanced_mixing = true;
120  *r_threshold = true;
121  ret = true;
122  break;
123  case DT_TYPE_SKIN:
124  *r_threshold = true;
125  ret = true;
126  break;
128  ret = true;
129  break;
130  /* Edge data */
131  case DT_TYPE_SHARP_EDGE:
132  *r_threshold = true;
133  ret = true;
134  break;
135  case DT_TYPE_SEAM:
136  *r_threshold = true;
137  ret = true;
138  break;
139  case DT_TYPE_CREASE:
140  ret = true;
141  break;
143  ret = true;
144  break;
146  *r_threshold = true;
147  ret = true;
148  break;
149  /* Loop/Poly data */
150  case DT_TYPE_UV:
151  ret = true;
152  break;
153  case DT_TYPE_VCOL:
154  *r_advanced_mixing = true;
155  *r_threshold = true;
156  ret = true;
157  break;
158  case DT_TYPE_LNOR:
159  *r_advanced_mixing = true;
160  ret = true;
161  break;
162  case DT_TYPE_SHARP_FACE:
163  *r_threshold = true;
164  ret = true;
165  break;
167  *r_threshold = true;
168  ret = true;
169  break;
170  }
171  }
172 
173  return ret;
174 }
175 
177 {
178  int i, ret = 0;
179 
180  for (i = 0; (i < DT_TYPE_MAX) && (ret ^ (ME_VERT | ME_EDGE | ME_LOOP | ME_POLY)); i++) {
181  const int dtdata_type = 1 << i;
182 
183  if (!(dtdata_types & dtdata_type)) {
184  continue;
185  }
186 
187  if (DT_DATATYPE_IS_VERT(dtdata_type)) {
188  ret |= ME_VERT;
189  }
190  if (DT_DATATYPE_IS_EDGE(dtdata_type)) {
191  ret |= ME_EDGE;
192  }
193  if (DT_DATATYPE_IS_LOOP(dtdata_type)) {
194  ret |= ME_LOOP;
195  }
196  if (DT_DATATYPE_IS_POLY(dtdata_type)) {
197  ret |= ME_POLY;
198  }
199  }
200 
201  return ret;
202 }
203 
205 {
206  switch (dtdata_type) {
207  case DT_TYPE_MDEFORMVERT:
208  return CD_FAKE_MDEFORMVERT;
209  case DT_TYPE_SHAPEKEY:
210  return CD_FAKE_SHAPEKEY;
211  case DT_TYPE_SKIN:
212  return CD_MVERT_SKIN;
214  return CD_FAKE_BWEIGHT;
215 
216  case DT_TYPE_SHARP_EDGE:
217  return CD_FAKE_SHARP;
218  case DT_TYPE_SEAM:
219  return CD_FAKE_SEAM;
220  case DT_TYPE_CREASE:
221  return CD_FAKE_CREASE;
223  return CD_FAKE_BWEIGHT;
225  return CD_FREESTYLE_EDGE;
226 
227  case DT_TYPE_UV:
228  return CD_FAKE_UV;
229  case DT_TYPE_SHARP_FACE:
230  return CD_FAKE_SHARP;
232  return CD_FREESTYLE_FACE;
233 
234  case DT_TYPE_VCOL:
235  return CD_MLOOPCOL;
236  case DT_TYPE_LNOR:
237  return CD_FAKE_LNOR;
238 
239  default:
240  BLI_assert(0);
241  }
242  return 0; /* Should never be reached! */
243 }
244 
246 {
247  switch (dtdata_type) {
248  case DT_TYPE_MDEFORMVERT:
250  case DT_TYPE_SHAPEKEY:
252  case DT_TYPE_UV:
253  return DT_MULTILAYER_INDEX_UV;
254  case DT_TYPE_VCOL:
256  default:
258  }
259 }
260 
261 /* ********** */
262 
263 /* Generic pre/post processing, only used by custom loop normals currently. */
264 
266  Mesh *me_dst,
267  const int dtdata_type,
268  const bool dirty_nors_dst)
269 {
270  if (dtdata_type == DT_TYPE_LNOR) {
271  /* Compute custom normals into regular loop normals, which will be used for the transfer. */
272  MVert *verts_dst = me_dst->mvert;
273  const int num_verts_dst = me_dst->totvert;
274  MEdge *edges_dst = me_dst->medge;
275  const int num_edges_dst = me_dst->totedge;
276  MPoly *polys_dst = me_dst->mpoly;
277  const int num_polys_dst = me_dst->totpoly;
278  MLoop *loops_dst = me_dst->mloop;
279  const int num_loops_dst = me_dst->totloop;
280  CustomData *pdata_dst = &me_dst->pdata;
281  CustomData *ldata_dst = &me_dst->ldata;
282 
283  const bool use_split_nors_dst = (me_dst->flag & ME_AUTOSMOOTH) != 0;
284  const float split_angle_dst = me_dst->smoothresh;
285 
286  /* This should be ensured by cddata_masks we pass to code generating/giving us me_src now. */
288  BLI_assert(CustomData_get_layer(&me_src->pdata, CD_NORMAL) != NULL);
289  (void)me_src;
290 
291  float(*poly_nors_dst)[3];
292  float(*loop_nors_dst)[3];
293  short(*custom_nors_dst)[2] = CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL);
294 
295  /* Cache poly nors into a temp CDLayer. */
296  poly_nors_dst = CustomData_get_layer(pdata_dst, CD_NORMAL);
297  const bool do_poly_nors_dst = (poly_nors_dst == NULL);
298  if (do_poly_nors_dst) {
299  poly_nors_dst = CustomData_add_layer(pdata_dst, CD_NORMAL, CD_CALLOC, NULL, num_polys_dst);
301  }
302  if (dirty_nors_dst || do_poly_nors_dst) {
303  BKE_mesh_calc_normals_poly(verts_dst,
304  NULL,
305  num_verts_dst,
306  loops_dst,
307  polys_dst,
308  num_loops_dst,
309  num_polys_dst,
310  poly_nors_dst,
311  true);
312  }
313  /* Cache loop nors into a temp CDLayer. */
314  loop_nors_dst = CustomData_get_layer(ldata_dst, CD_NORMAL);
315  const bool do_loop_nors_dst = (loop_nors_dst == NULL);
316  if (do_loop_nors_dst) {
317  loop_nors_dst = CustomData_add_layer(ldata_dst, CD_NORMAL, CD_CALLOC, NULL, num_loops_dst);
319  }
320  if (dirty_nors_dst || do_loop_nors_dst) {
321  BKE_mesh_normals_loop_split(verts_dst,
322  num_verts_dst,
323  edges_dst,
324  num_edges_dst,
325  loops_dst,
326  loop_nors_dst,
327  num_loops_dst,
328  polys_dst,
329  (const float(*)[3])poly_nors_dst,
330  num_polys_dst,
331  use_split_nors_dst,
332  split_angle_dst,
333  NULL,
334  custom_nors_dst,
335  NULL);
336  }
337  }
338 }
339 
341  Object *UNUSED(ob_dst),
342  Mesh *UNUSED(me_src),
343  Mesh *me_dst,
344  const int dtdata_type,
345  const bool changed)
346 {
347  if (dtdata_type == DT_TYPE_LNOR) {
348  if (!changed) {
349  return;
350  }
351 
352  /* Bake edited destination loop normals into custom normals again. */
353  MVert *verts_dst = me_dst->mvert;
354  const int num_verts_dst = me_dst->totvert;
355  MEdge *edges_dst = me_dst->medge;
356  const int num_edges_dst = me_dst->totedge;
357  MPoly *polys_dst = me_dst->mpoly;
358  const int num_polys_dst = me_dst->totpoly;
359  MLoop *loops_dst = me_dst->mloop;
360  const int num_loops_dst = me_dst->totloop;
361  CustomData *pdata_dst = &me_dst->pdata;
362  CustomData *ldata_dst = &me_dst->ldata;
363 
364  const float(*poly_nors_dst)[3] = CustomData_get_layer(pdata_dst, CD_NORMAL);
365  float(*loop_nors_dst)[3] = CustomData_get_layer(ldata_dst, CD_NORMAL);
366  short(*custom_nors_dst)[2] = CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL);
367 
368  BLI_assert(poly_nors_dst);
369 
370  if (!custom_nors_dst) {
371  custom_nors_dst = CustomData_add_layer(
372  ldata_dst, CD_CUSTOMLOOPNORMAL, CD_CALLOC, NULL, num_loops_dst);
373  }
374 
375  /* Note loop_nors_dst contains our custom normals as transferred from source... */
377  num_verts_dst,
378  edges_dst,
379  num_edges_dst,
380  loops_dst,
381  loop_nors_dst,
382  num_loops_dst,
383  polys_dst,
384  poly_nors_dst,
385  num_polys_dst,
386  custom_nors_dst);
387  }
388 }
389 
390 /* ********** */
391 
393 {
394  switch (cddata_type) {
395  case CD_FAKE_UV:
397  default:
398  break;
399  }
400  return NULL;
401 }
402 
403 float data_transfer_interp_float_do(const int mix_mode,
404  const float val_dst,
405  const float val_src,
406  const float mix_factor)
407 {
408  float val_ret;
409 
410  if (((mix_mode == CDT_MIX_REPLACE_ABOVE_THRESHOLD && (val_dst < mix_factor)) ||
411  (mix_mode == CDT_MIX_REPLACE_BELOW_THRESHOLD && (val_dst > mix_factor)))) {
412  return val_dst; /* Do not affect destination. */
413  }
414 
415  switch (mix_mode) {
418  return val_src;
419  case CDT_MIX_MIX:
420  val_ret = (val_dst + val_src) * 0.5f;
421  break;
422  case CDT_MIX_ADD:
423  val_ret = val_dst + val_src;
424  break;
425  case CDT_MIX_SUB:
426  val_ret = val_dst - val_src;
427  break;
428  case CDT_MIX_MUL:
429  val_ret = val_dst * val_src;
430  break;
431  case CDT_MIX_TRANSFER:
432  default:
433  val_ret = val_src;
434  break;
435  }
436  return interpf(val_ret, val_dst, mix_factor);
437 }
438 
440  void *dest,
441  const void **sources,
442  const float *weights,
443  const int count,
444  const float mix_factor)
445 {
446  const char **data_src = (const char **)sources;
447  char *data_dst = (char *)dest;
448 
449  const int mix_mode = laymap->mix_mode;
450  float val_src = 0.0f;
451  const float val_dst = (float)(*data_dst) / 255.0f;
452 
453  for (int i = count; i--;) {
454  val_src += ((float)(*data_src[i]) / 255.0f) * weights[i];
455  }
456 
457  val_src = data_transfer_interp_float_do(mix_mode, val_dst, val_src, mix_factor);
458 
459  CLAMP(val_src, 0.0f, 1.0f);
460 
461  *data_dst = (char)(val_src * 255.0f);
462 }
463 
464 /* Helpers to match sources and destinations data layers
465  * (also handles 'conversions' in CD_FAKE cases). */
466 
468  const int cddata_type,
469  const int mix_mode,
470  const float mix_factor,
471  const float *mix_weights,
472  const void *data_src,
473  void *data_dst,
474  const int data_src_n,
475  const int data_dst_n,
476  const size_t elem_size,
477  const size_t data_size,
478  const size_t data_offset,
479  const uint64_t data_flag,
481  void *interp_data)
482 {
483  CustomDataTransferLayerMap *item = MEM_mallocN(sizeof(*item), __func__);
484 
485  BLI_assert(data_dst != NULL);
486 
487  item->data_type = cddata_type;
488  item->mix_mode = mix_mode;
489  item->mix_factor = mix_factor;
490  item->mix_weights = mix_weights;
491 
492  item->data_src = data_src;
493  item->data_dst = data_dst;
494  item->data_src_n = data_src_n;
495  item->data_dst_n = data_dst_n;
496  item->elem_size = elem_size;
497 
498  item->data_size = data_size;
499  item->data_offset = data_offset;
500  item->data_flag = data_flag;
501 
502  item->interp = interp;
503  item->interp_data = interp_data;
504 
505  BLI_addtail(r_map, item);
506 }
507 
509  const int cddata_type,
510  const int mix_mode,
511  const float mix_factor,
512  const float *mix_weights,
513  void *data_src,
514  void *data_dst,
516  void *interp_data)
517 {
518  uint64_t data_flag = 0;
519 
520  if (cddata_type == CD_FREESTYLE_EDGE) {
521  data_flag = FREESTYLE_EDGE_MARK;
522  }
523  else if (cddata_type == CD_FREESTYLE_FACE) {
524  data_flag = FREESTYLE_FACE_MARK;
525  }
526 
528  cddata_type,
529  mix_mode,
530  mix_factor,
531  mix_weights,
532  data_src,
533  data_dst,
534  0,
535  0,
536  0,
537  0,
538  0,
539  data_flag,
540  interp,
541  interp_data);
542 }
543 
552  const int cddata_type,
553  const int mix_mode,
554  const float mix_factor,
555  const float *mix_weights,
556  const int num_elem_dst,
557  const bool use_create,
558  const bool use_delete,
559  CustomData *cd_src,
560  CustomData *cd_dst,
561  const bool use_dupref_dst,
562  const int tolayers,
563  const bool *use_layers_src,
564  const int num_layers_src,
566  void *interp_data)
567 {
568  void *data_src, *data_dst = NULL;
569  int idx_src = num_layers_src;
570  int idx_dst, tot_dst = CustomData_number_of_layers(cd_dst, cddata_type);
571  bool *data_dst_to_delete = NULL;
572 
573  if (!use_layers_src) {
574  /* No source at all, we can only delete all dest if requested... */
575  if (use_delete) {
576  idx_dst = tot_dst;
577  while (idx_dst--) {
578  CustomData_free_layer(cd_dst, cddata_type, num_elem_dst, idx_dst);
579  }
580  }
581  return true;
582  }
583 
584  switch (tolayers) {
585  case DT_LAYERS_INDEX_DST:
586  idx_dst = tot_dst;
587 
588  /* Find last source actually used! */
589  while (idx_src-- && !use_layers_src[idx_src]) {
590  /* pass */
591  }
592  idx_src++;
593 
594  if (idx_dst < idx_src) {
595  if (use_create) {
596  /* Create as much data layers as necessary! */
597  for (; idx_dst < idx_src; idx_dst++) {
598  CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
599  }
600  }
601  else {
602  /* Otherwise, just try to map what we can with existing dst data layers. */
603  idx_src = idx_dst;
604  }
605  }
606  else if (use_delete && idx_dst > idx_src) {
607  while (idx_dst-- > idx_src) {
608  CustomData_free_layer(cd_dst, cddata_type, num_elem_dst, idx_dst);
609  }
610  }
611  if (r_map) {
612  while (idx_src--) {
613  if (!use_layers_src[idx_src]) {
614  continue;
615  }
616  data_src = CustomData_get_layer_n(cd_src, cddata_type, idx_src);
617  /* If dest is a evaluated mesh (from modifier),
618  * we do not want to overwrite cdlayers of orig mesh! */
619  if (use_dupref_dst) {
621  cd_dst, cddata_type, idx_src, num_elem_dst);
622  }
623  else {
624  data_dst = CustomData_get_layer_n(cd_dst, cddata_type, idx_src);
625  }
627  cddata_type,
628  mix_mode,
629  mix_factor,
630  mix_weights,
631  data_src,
632  data_dst,
633  interp,
634  interp_data);
635  }
636  }
637  break;
638  case DT_LAYERS_NAME_DST:
639  if (use_delete) {
640  if (tot_dst) {
641  data_dst_to_delete = MEM_mallocN(sizeof(*data_dst_to_delete) * (size_t)tot_dst,
642  __func__);
643  memset(data_dst_to_delete, true, sizeof(*data_dst_to_delete) * (size_t)tot_dst);
644  }
645  }
646 
647  while (idx_src--) {
648  const char *name;
649 
650  if (!use_layers_src[idx_src]) {
651  continue;
652  }
653 
654  name = CustomData_get_layer_name(cd_src, cddata_type, idx_src);
655  data_src = CustomData_get_layer_n(cd_src, cddata_type, idx_src);
656 
657  if ((idx_dst = CustomData_get_named_layer(cd_dst, cddata_type, name)) == -1) {
658  if (use_create) {
659  CustomData_add_layer_named(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst, name);
660  idx_dst = CustomData_get_named_layer(cd_dst, cddata_type, name);
661  }
662  else {
663  /* If we are not allowed to create missing dst data layers,
664  * just skip matching src one. */
665  continue;
666  }
667  }
668  else if (data_dst_to_delete) {
669  data_dst_to_delete[idx_dst] = false;
670  }
671  if (r_map) {
672  /* If dest is a evaluated mesh (from modifier),
673  * we do not want to overwrite cdlayers of orig mesh! */
674  if (use_dupref_dst) {
676  cd_dst, cddata_type, idx_dst, num_elem_dst);
677  }
678  else {
679  data_dst = CustomData_get_layer_n(cd_dst, cddata_type, idx_dst);
680  }
682  cddata_type,
683  mix_mode,
684  mix_factor,
685  mix_weights,
686  data_src,
687  data_dst,
688  interp,
689  interp_data);
690  }
691  }
692 
693  if (data_dst_to_delete) {
694  /* Note:
695  * This won't affect newly created layers, if any, since tot_dst has not been updated!
696  * Also, looping backward ensures us we do not suffer
697  * from index shifting when deleting a layer. */
698  for (idx_dst = tot_dst; idx_dst--;) {
699  if (data_dst_to_delete[idx_dst]) {
700  CustomData_free_layer(cd_dst, cddata_type, num_elem_dst, idx_dst);
701  }
702  }
703 
704  MEM_freeN(data_dst_to_delete);
705  }
706  break;
707  default:
708  return false;
709  }
710 
711  return true;
712 }
713 
715  const int cddata_type,
716  const int mix_mode,
717  const float mix_factor,
718  const float *mix_weights,
719  const int num_elem_dst,
720  const bool use_create,
721  const bool use_delete,
722  CustomData *cd_src,
723  CustomData *cd_dst,
724  const bool use_dupref_dst,
725  const int fromlayers,
726  const int tolayers,
728  void *interp_data)
729 {
730  int idx_src, idx_dst;
731  void *data_src, *data_dst = NULL;
732 
733  if (CustomData_layertype_is_singleton(cddata_type)) {
734  if (!(data_src = CustomData_get_layer(cd_src, cddata_type))) {
735  if (use_delete) {
736  CustomData_free_layer(cd_dst, cddata_type, num_elem_dst, 0);
737  }
738  return true;
739  }
740 
741  data_dst = CustomData_get_layer(cd_dst, cddata_type);
742  if (!data_dst) {
743  if (!use_create) {
744  return true;
745  }
746  data_dst = CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
747  }
748  else if (use_dupref_dst && r_map) {
749  /* If dest is a evaluated mesh (from modifier),
750  * we do not want to overwrite cdlayers of orig mesh! */
751  data_dst = CustomData_duplicate_referenced_layer(cd_dst, cddata_type, num_elem_dst);
752  }
753 
754  if (r_map) {
756  cddata_type,
757  mix_mode,
758  mix_factor,
759  mix_weights,
760  data_src,
761  data_dst,
762  interp,
763  interp_data);
764  }
765  }
766  else if (fromlayers == DT_LAYERS_ACTIVE_SRC || fromlayers >= 0) {
767  /* Note: use_delete has not much meaning in this case, ignored. */
768 
769  if (fromlayers >= 0) { /* Real-layer index */
770  idx_src = fromlayers;
771  }
772  else {
773  if ((idx_src = CustomData_get_active_layer(cd_src, cddata_type)) == -1) {
774  return true;
775  }
776  }
777  data_src = CustomData_get_layer_n(cd_src, cddata_type, idx_src);
778  if (!data_src) {
779  return true;
780  }
781 
782  if (tolayers >= 0) { /* Real-layer index */
783  idx_dst = tolayers;
784  /* If dest is a evaluated mesh (from modifier),
785  * we do not want to overwrite cdlayers of orig mesh! */
786  if (use_dupref_dst && r_map) {
788  cd_dst, cddata_type, idx_dst, num_elem_dst);
789  }
790  else {
791  data_dst = CustomData_get_layer_n(cd_dst, cddata_type, idx_dst);
792  }
793  }
794  else if (tolayers == DT_LAYERS_ACTIVE_DST) {
795  if ((idx_dst = CustomData_get_active_layer(cd_dst, cddata_type)) == -1) {
796  if (!use_create) {
797  return true;
798  }
799  data_dst = CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
800  }
801  else {
802  /* If dest is a evaluated mesh (from modifier),
803  * we do not want to overwrite cdlayers of orig mesh! */
804  if (use_dupref_dst && r_map) {
806  cd_dst, cddata_type, idx_dst, num_elem_dst);
807  }
808  else {
809  data_dst = CustomData_get_layer_n(cd_dst, cddata_type, idx_dst);
810  }
811  }
812  }
813  else if (tolayers == DT_LAYERS_INDEX_DST) {
814  int num = CustomData_number_of_layers(cd_dst, cddata_type);
815  idx_dst = idx_src;
816  if (num <= idx_dst) {
817  if (!use_create) {
818  return true;
819  }
820  /* Create as much data layers as necessary! */
821  for (; num <= idx_dst; num++) {
822  CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
823  }
824  }
825  /* If dest is a evaluated mesh (from modifier),
826  * we do not want to overwrite cdlayers of orig mesh! */
827  if (use_dupref_dst && r_map) {
829  cd_dst, cddata_type, idx_dst, num_elem_dst);
830  }
831  else {
832  data_dst = CustomData_get_layer_n(cd_dst, cddata_type, idx_dst);
833  }
834  }
835  else if (tolayers == DT_LAYERS_NAME_DST) {
836  const char *name = CustomData_get_layer_name(cd_src, cddata_type, idx_src);
837  if ((idx_dst = CustomData_get_named_layer(cd_dst, cddata_type, name)) == -1) {
838  if (!use_create) {
839  return true;
840  }
841  CustomData_add_layer_named(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst, name);
842  idx_dst = CustomData_get_named_layer(cd_dst, cddata_type, name);
843  }
844  /* If dest is a evaluated mesh (from modifier),
845  * we do not want to overwrite cdlayers of orig mesh! */
846  if (use_dupref_dst && r_map) {
848  cd_dst, cddata_type, idx_dst, num_elem_dst);
849  }
850  else {
851  data_dst = CustomData_get_layer_n(cd_dst, cddata_type, idx_dst);
852  }
853  }
854  else {
855  return false;
856  }
857 
858  if (!data_dst) {
859  return false;
860  }
861 
862  if (r_map) {
864  cddata_type,
865  mix_mode,
866  mix_factor,
867  mix_weights,
868  data_src,
869  data_dst,
870  interp,
871  interp_data);
872  }
873  }
874  else if (fromlayers == DT_LAYERS_ALL_SRC) {
875  int num_src = CustomData_number_of_layers(cd_src, cddata_type);
876  bool *use_layers_src = num_src ?
877  MEM_mallocN(sizeof(*use_layers_src) * (size_t)num_src, __func__) :
878  NULL;
879  bool ret;
880 
881  if (use_layers_src) {
882  memset(use_layers_src, true, sizeof(*use_layers_src) * num_src);
883  }
884 
886  cddata_type,
887  mix_mode,
888  mix_factor,
889  mix_weights,
890  num_elem_dst,
891  use_create,
892  use_delete,
893  cd_src,
894  cd_dst,
895  use_dupref_dst,
896  tolayers,
897  use_layers_src,
898  num_src,
899  interp,
900  interp_data);
901 
902  if (use_layers_src) {
903  MEM_freeN(use_layers_src);
904  }
905  return ret;
906  }
907  else {
908  return false;
909  }
910 
911  return true;
912 }
913 
915  Object *ob_src,
916  Object *ob_dst,
917  Mesh *me_src,
918  Mesh *me_dst,
919  const int elem_type,
920  int cddata_type,
921  int mix_mode,
922  float mix_factor,
923  const float *mix_weights,
924  const int num_elem_dst,
925  const bool use_create,
926  const bool use_delete,
927  const int fromlayers,
928  const int tolayers,
929  SpaceTransform *space_transform)
930 {
931  CustomData *cd_src, *cd_dst;
932 
934  void *interp_data = NULL;
935 
936  if (elem_type == ME_VERT) {
937  if (!(cddata_type & CD_FAKE)) {
938  cd_src = &me_src->vdata;
939  cd_dst = &me_dst->vdata;
940 
942  cddata_type,
943  mix_mode,
944  mix_factor,
945  mix_weights,
946  num_elem_dst,
947  use_create,
948  use_delete,
949  cd_src,
950  cd_dst,
951  me_dst != ob_dst->data,
952  fromlayers,
953  tolayers,
954  interp,
955  interp_data)) {
956  /* We handle specific source selection cases here. */
957  return false;
958  }
959  return true;
960  }
961  if (cddata_type == CD_FAKE_BWEIGHT) {
962  const size_t elem_size = sizeof(*((MVert *)NULL));
963  const size_t data_size = sizeof(((MVert *)NULL)->bweight);
964  const size_t data_offset = offsetof(MVert, bweight);
965  const uint64_t data_flag = 0;
966 
967  if (!(me_src->cd_flag & ME_CDFLAG_VERT_BWEIGHT)) {
968  if (use_delete) {
969  me_dst->cd_flag &= ~ME_CDFLAG_VERT_BWEIGHT;
970  }
971  return true;
972  }
973  me_dst->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
974  if (r_map) {
976  cddata_type,
977  mix_mode,
978  mix_factor,
979  mix_weights,
980  me_src->mvert,
981  me_dst->mvert,
982  me_src->totvert,
983  me_dst->totvert,
984  elem_size,
985  data_size,
986  data_offset,
987  data_flag,
989  interp_data);
990  }
991  return true;
992  }
993  if (cddata_type == CD_FAKE_MDEFORMVERT) {
994  bool ret;
995 
996  cd_src = &me_src->vdata;
997  cd_dst = &me_dst->vdata;
998 
1000  mix_mode,
1001  mix_factor,
1002  mix_weights,
1003  num_elem_dst,
1004  use_create,
1005  use_delete,
1006  ob_src,
1007  ob_dst,
1008  cd_src,
1009  cd_dst,
1010  me_dst != ob_dst->data,
1011  fromlayers,
1012  tolayers);
1013 
1014  /* Mesh stores its dvert in a specific pointer too. :( */
1015  me_dst->dvert = CustomData_get_layer(&me_dst->vdata, CD_MDEFORMVERT);
1016  return ret;
1017  }
1018  if (cddata_type == CD_FAKE_SHAPEKEY) {
1019  /* TODO: leaving shapekeys aside for now, quite specific case,
1020  * since we can't access them from MVert :/ */
1021  return false;
1022  }
1023  }
1024  else if (elem_type == ME_EDGE) {
1025  if (!(cddata_type & CD_FAKE)) { /* Unused for edges, currently... */
1026  cd_src = &me_src->edata;
1027  cd_dst = &me_dst->edata;
1028 
1030  cddata_type,
1031  mix_mode,
1032  mix_factor,
1033  mix_weights,
1034  num_elem_dst,
1035  use_create,
1036  use_delete,
1037  cd_src,
1038  cd_dst,
1039  me_dst != ob_dst->data,
1040  fromlayers,
1041  tolayers,
1042  interp,
1043  interp_data)) {
1044  /* We handle specific source selection cases here. */
1045  return false;
1046  }
1047  return true;
1048  }
1049  if (cddata_type == CD_FAKE_CREASE) {
1050  const size_t elem_size = sizeof(*((MEdge *)NULL));
1051  const size_t data_size = sizeof(((MEdge *)NULL)->crease);
1052  const size_t data_offset = offsetof(MEdge, crease);
1053  const uint64_t data_flag = 0;
1054 
1055  if (!(me_src->cd_flag & ME_CDFLAG_EDGE_CREASE)) {
1056  if (use_delete) {
1057  me_dst->cd_flag &= ~ME_CDFLAG_EDGE_CREASE;
1058  }
1059  return true;
1060  }
1061  me_dst->cd_flag |= ME_CDFLAG_EDGE_CREASE;
1062  if (r_map) {
1064  cddata_type,
1065  mix_mode,
1066  mix_factor,
1067  mix_weights,
1068  me_src->medge,
1069  me_dst->medge,
1070  me_src->totedge,
1071  me_dst->totedge,
1072  elem_size,
1073  data_size,
1074  data_offset,
1075  data_flag,
1077  interp_data);
1078  }
1079  return true;
1080  }
1081  if (cddata_type == CD_FAKE_BWEIGHT) {
1082  const size_t elem_size = sizeof(*((MEdge *)NULL));
1083  const size_t data_size = sizeof(((MEdge *)NULL)->bweight);
1084  const size_t data_offset = offsetof(MEdge, bweight);
1085  const uint64_t data_flag = 0;
1086 
1087  if (!(me_src->cd_flag & ME_CDFLAG_EDGE_BWEIGHT)) {
1088  if (use_delete) {
1089  me_dst->cd_flag &= ~ME_CDFLAG_EDGE_BWEIGHT;
1090  }
1091  return true;
1092  }
1093  me_dst->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
1094  if (r_map) {
1096  cddata_type,
1097  mix_mode,
1098  mix_factor,
1099  mix_weights,
1100  me_src->medge,
1101  me_dst->medge,
1102  me_src->totedge,
1103  me_dst->totedge,
1104  elem_size,
1105  data_size,
1106  data_offset,
1107  data_flag,
1109  interp_data);
1110  }
1111  return true;
1112  }
1113  if (r_map && ELEM(cddata_type, CD_FAKE_SHARP, CD_FAKE_SEAM)) {
1114  const size_t elem_size = sizeof(*((MEdge *)NULL));
1115  const size_t data_size = sizeof(((MEdge *)NULL)->flag);
1116  const size_t data_offset = offsetof(MEdge, flag);
1117  const uint64_t data_flag = (cddata_type == CD_FAKE_SHARP) ? ME_SHARP : ME_SEAM;
1118 
1120  cddata_type,
1121  mix_mode,
1122  mix_factor,
1123  mix_weights,
1124  me_src->medge,
1125  me_dst->medge,
1126  me_src->totedge,
1127  me_dst->totedge,
1128  elem_size,
1129  data_size,
1130  data_offset,
1131  data_flag,
1132  NULL,
1133  interp_data);
1134  return true;
1135  }
1136 
1137  return false;
1138  }
1139  else if (elem_type == ME_LOOP) {
1140  if (cddata_type == CD_FAKE_UV) {
1141  cddata_type = CD_MLOOPUV;
1142  }
1143  else if (cddata_type == CD_FAKE_LNOR) {
1144  /* Pre-process should have generated it,
1145  * Post-process will convert it back to CD_CUSTOMLOOPNORMAL. */
1146  cddata_type = CD_NORMAL;
1147  interp_data = space_transform;
1149  }
1150 
1151  if (!(cddata_type & CD_FAKE)) {
1152  cd_src = &me_src->ldata;
1153  cd_dst = &me_dst->ldata;
1154 
1156  cddata_type,
1157  mix_mode,
1158  mix_factor,
1159  mix_weights,
1160  num_elem_dst,
1161  use_create,
1162  use_delete,
1163  cd_src,
1164  cd_dst,
1165  me_dst != ob_dst->data,
1166  fromlayers,
1167  tolayers,
1168  interp,
1169  interp_data)) {
1170  /* We handle specific source selection cases here. */
1171  return false;
1172  }
1173  return true;
1174  }
1175 
1176  return false;
1177  }
1178  else if (elem_type == ME_POLY) {
1179  if (cddata_type == CD_FAKE_UV) {
1180  cddata_type = CD_MLOOPUV;
1181  }
1182 
1183  if (!(cddata_type & CD_FAKE)) {
1184  cd_src = &me_src->pdata;
1185  cd_dst = &me_dst->pdata;
1186 
1188  cddata_type,
1189  mix_mode,
1190  mix_factor,
1191  mix_weights,
1192  num_elem_dst,
1193  use_create,
1194  use_delete,
1195  cd_src,
1196  cd_dst,
1197  me_dst != ob_dst->data,
1198  fromlayers,
1199  tolayers,
1200  interp,
1201  interp_data)) {
1202  /* We handle specific source selection cases here. */
1203  return false;
1204  }
1205  return true;
1206  }
1207  if (r_map && cddata_type == CD_FAKE_SHARP) {
1208  const size_t elem_size = sizeof(*((MPoly *)NULL));
1209  const size_t data_size = sizeof(((MPoly *)NULL)->flag);
1210  const size_t data_offset = offsetof(MPoly, flag);
1211  const uint64_t data_flag = ME_SMOOTH;
1212 
1214  cddata_type,
1215  mix_mode,
1216  mix_factor,
1217  mix_weights,
1218  me_src->mpoly,
1219  me_dst->mpoly,
1220  me_src->totpoly,
1221  me_dst->totpoly,
1222  elem_size,
1223  data_size,
1224  data_offset,
1225  data_flag,
1226  NULL,
1227  interp_data);
1228  return true;
1229  }
1230 
1231  return false;
1232  }
1233 
1234  return false;
1235 }
1236 
1244  Scene *scene,
1245  Object *ob_src,
1246  Object *ob_dst,
1247  const int data_types,
1248  const bool use_delete,
1249  const int fromlayers_select[DT_MULTILAYER_INDEX_MAX],
1250  const int tolayers_select[DT_MULTILAYER_INDEX_MAX])
1251 {
1252  Mesh *me_src;
1253  Mesh *me_dst;
1254 
1255  const bool use_create = true; /* We always create needed layers here. */
1256 
1257  CustomData_MeshMasks me_src_mask = CD_MASK_BAREMESH;
1258 
1259  BLI_assert((ob_src != ob_dst) && (ob_src->type == OB_MESH) && (ob_dst->type == OB_MESH));
1260 
1261  me_dst = ob_dst->data;
1262 
1263  /* Get source evaluated mesh.*/
1264  BKE_object_data_transfer_dttypes_to_cdmask(data_types, &me_src_mask);
1265  me_src = mesh_get_eval_final(depsgraph, scene, ob_src, &me_src_mask);
1266  if (!me_src) {
1267  return;
1268  }
1269 
1270  /* Check all possible data types. */
1271  for (int i = 0; i < DT_TYPE_MAX; i++) {
1272  const int dtdata_type = 1 << i;
1273  int cddata_type;
1274  int fromlayers, tolayers, fromto_idx;
1275 
1276  if (!(data_types & dtdata_type)) {
1277  continue;
1278  }
1279 
1280  cddata_type = BKE_object_data_transfer_dttype_to_cdtype(dtdata_type);
1281 
1282  fromto_idx = BKE_object_data_transfer_dttype_to_srcdst_index(dtdata_type);
1283  if (fromto_idx != DT_MULTILAYER_INDEX_INVALID) {
1284  fromlayers = fromlayers_select[fromto_idx];
1285  tolayers = tolayers_select[fromto_idx];
1286  }
1287  else {
1288  fromlayers = tolayers = 0;
1289  }
1290 
1291  if (DT_DATATYPE_IS_VERT(dtdata_type)) {
1292  const int num_elem_dst = me_dst->totvert;
1293 
1295  ob_src,
1296  ob_dst,
1297  me_src,
1298  me_dst,
1299  ME_VERT,
1300  cddata_type,
1301  0,
1302  0.0f,
1303  NULL,
1304  num_elem_dst,
1305  use_create,
1306  use_delete,
1307  fromlayers,
1308  tolayers,
1309  NULL);
1310  }
1311  if (DT_DATATYPE_IS_EDGE(dtdata_type)) {
1312  const int num_elem_dst = me_dst->totedge;
1313 
1315  ob_src,
1316  ob_dst,
1317  me_src,
1318  me_dst,
1319  ME_EDGE,
1320  cddata_type,
1321  0,
1322  0.0f,
1323  NULL,
1324  num_elem_dst,
1325  use_create,
1326  use_delete,
1327  fromlayers,
1328  tolayers,
1329  NULL);
1330  }
1331  if (DT_DATATYPE_IS_LOOP(dtdata_type)) {
1332  const int num_elem_dst = me_dst->totloop;
1333 
1335  ob_src,
1336  ob_dst,
1337  me_src,
1338  me_dst,
1339  ME_LOOP,
1340  cddata_type,
1341  0,
1342  0.0f,
1343  NULL,
1344  num_elem_dst,
1345  use_create,
1346  use_delete,
1347  fromlayers,
1348  tolayers,
1349  NULL);
1350  }
1351  if (DT_DATATYPE_IS_POLY(dtdata_type)) {
1352  const int num_elem_dst = me_dst->totpoly;
1353 
1355  ob_src,
1356  ob_dst,
1357  me_src,
1358  me_dst,
1359  ME_POLY,
1360  cddata_type,
1361  0,
1362  0.0f,
1363  NULL,
1364  num_elem_dst,
1365  use_create,
1366  use_delete,
1367  fromlayers,
1368  tolayers,
1369  NULL);
1370  }
1371  }
1372 }
1373 
1375  Scene *scene,
1376  Object *ob_src,
1377  Object *ob_dst,
1378  Mesh *me_dst,
1379  const int data_types,
1380  bool use_create,
1381  const int map_vert_mode,
1382  const int map_edge_mode,
1383  const int map_loop_mode,
1384  const int map_poly_mode,
1385  SpaceTransform *space_transform,
1386  const bool auto_transform,
1387  const float max_distance,
1388  const float ray_radius,
1389  const float islands_handling_precision,
1390  const int fromlayers_select[DT_MULTILAYER_INDEX_MAX],
1391  const int tolayers_select[DT_MULTILAYER_INDEX_MAX],
1392  const int mix_mode,
1393  const float mix_factor,
1394  const char *vgroup_name,
1395  const bool invert_vgroup,
1396  ReportList *reports)
1397 {
1398 #define VDATA 0
1399 #define EDATA 1
1400 #define LDATA 2
1401 #define PDATA 3
1402 #define DATAMAX 4
1403 
1404  SpaceTransform auto_space_transform;
1405 
1406  Mesh *me_src;
1407  /* Assumed always true if not using an evaluated mesh as destination. */
1408  bool dirty_nors_dst = true;
1409 
1410  MDeformVert *mdef = NULL;
1411  int vg_idx = -1;
1412  float *weights[DATAMAX] = {NULL};
1413 
1414  MeshPairRemap geom_map[DATAMAX] = {{0}};
1415  bool geom_map_init[DATAMAX] = {0};
1416  ListBase lay_map = {NULL};
1417  bool changed = false;
1418  bool is_modifier = false;
1419 
1420  const bool use_delete = false; /* We never delete data layers from destination here. */
1421 
1422  CustomData_MeshMasks me_src_mask = CD_MASK_BAREMESH;
1423 
1424  BLI_assert((ob_src != ob_dst) && (ob_src->type == OB_MESH) && (ob_dst->type == OB_MESH));
1425 
1426  if (me_dst) {
1427  dirty_nors_dst = (me_dst->runtime.cd_dirty_vert & CD_NORMAL) != 0;
1428  /* Never create needed custom layers on passed destination mesh
1429  * (assumed to *not* be ob_dst->data, aka modifier case). */
1430  use_create = false;
1431  is_modifier = true;
1432  }
1433  else {
1434  me_dst = ob_dst->data;
1435  }
1436 
1437  if (vgroup_name) {
1438  mdef = CustomData_get_layer(&me_dst->vdata, CD_MDEFORMVERT);
1439  if (mdef) {
1440  vg_idx = BKE_object_defgroup_name_index(ob_dst, vgroup_name);
1441  }
1442  }
1443 
1444  /* Get source evaluated mesh.*/
1445  BKE_object_data_transfer_dttypes_to_cdmask(data_types, &me_src_mask);
1447  map_vert_mode, map_edge_mode, map_loop_mode, map_poly_mode, &me_src_mask);
1448  if (is_modifier) {
1450 
1451  if (me_src == NULL ||
1452  !CustomData_MeshMasks_are_matching(&ob_src->runtime.last_data_mask, &me_src_mask)) {
1453  CLOG_WARN(&LOG, "Data Transfer: source mesh data is not ready - dependency cycle?");
1454  return changed;
1455  }
1456  }
1457  else {
1458  me_src = mesh_get_eval_final(depsgraph, scene, ob_src, &me_src_mask);
1459  }
1460  if (!me_src) {
1461  return changed;
1462  }
1464 
1465  if (auto_transform) {
1466  if (space_transform == NULL) {
1467  space_transform = &auto_space_transform;
1468  }
1469 
1471  me_dst->mvert, me_dst->totvert, me_src, space_transform);
1472  }
1473 
1474  /* Check all possible data types.
1475  * Note item mappings and dest mix weights are cached. */
1476  for (int i = 0; i < DT_TYPE_MAX; i++) {
1477  const int dtdata_type = 1 << i;
1478  int cddata_type;
1479  int fromlayers, tolayers, fromto_idx;
1480 
1481  if (!(data_types & dtdata_type)) {
1482  continue;
1483  }
1484 
1485  data_transfer_dtdata_type_preprocess(me_src, me_dst, dtdata_type, dirty_nors_dst);
1486 
1487  cddata_type = BKE_object_data_transfer_dttype_to_cdtype(dtdata_type);
1488 
1489  fromto_idx = BKE_object_data_transfer_dttype_to_srcdst_index(dtdata_type);
1490  if (fromto_idx != DT_MULTILAYER_INDEX_INVALID) {
1491  fromlayers = fromlayers_select[fromto_idx];
1492  tolayers = tolayers_select[fromto_idx];
1493  }
1494  else {
1495  fromlayers = tolayers = 0;
1496  }
1497 
1498  if (DT_DATATYPE_IS_VERT(dtdata_type)) {
1499  MVert *verts_dst = me_dst->mvert;
1500  const int num_verts_dst = me_dst->totvert;
1501 
1502  if (!geom_map_init[VDATA]) {
1503  const int num_verts_src = me_src->totvert;
1504 
1505  if ((map_vert_mode == MREMAP_MODE_TOPOLOGY) && (num_verts_dst != num_verts_src)) {
1506  BKE_report(reports,
1507  RPT_ERROR,
1508  "Source and destination meshes do not have the same amount of vertices, "
1509  "'Topology' mapping cannot be used in this case");
1510  continue;
1511  }
1512  if ((map_vert_mode & MREMAP_USE_EDGE) && (me_src->totedge == 0)) {
1513  BKE_report(reports,
1514  RPT_ERROR,
1515  "Source mesh doesn't have any edges, "
1516  "None of the 'Edge' mappings can be used in this case");
1517  continue;
1518  }
1519  if ((map_vert_mode & MREMAP_USE_POLY) && (me_src->totpoly == 0)) {
1520  BKE_report(reports,
1521  RPT_ERROR,
1522  "Source mesh doesn't have any faces, "
1523  "None of the 'Face' mappings can be used in this case");
1524  continue;
1525  }
1526  if (ELEM(0, num_verts_dst, num_verts_src)) {
1527  BKE_report(reports,
1528  RPT_ERROR,
1529  "Source or destination meshes do not have any vertices, cannot transfer "
1530  "vertex data");
1531  continue;
1532  }
1533 
1535  space_transform,
1536  max_distance,
1537  ray_radius,
1538  verts_dst,
1539  num_verts_dst,
1540  dirty_nors_dst,
1541  me_src,
1542  &geom_map[VDATA]);
1543  geom_map_init[VDATA] = true;
1544  }
1545 
1546  if (mdef && vg_idx != -1 && !weights[VDATA]) {
1547  weights[VDATA] = MEM_mallocN(sizeof(*(weights[VDATA])) * (size_t)num_verts_dst, __func__);
1549  mdef, vg_idx, num_verts_dst, weights[VDATA], invert_vgroup);
1550  }
1551 
1553  ob_src,
1554  ob_dst,
1555  me_src,
1556  me_dst,
1557  ME_VERT,
1558  cddata_type,
1559  mix_mode,
1560  mix_factor,
1561  weights[VDATA],
1562  num_verts_dst,
1563  use_create,
1564  use_delete,
1565  fromlayers,
1566  tolayers,
1567  space_transform)) {
1568  CustomDataTransferLayerMap *lay_mapit;
1569 
1570  changed |= (lay_map.first != NULL);
1571 
1572  for (lay_mapit = lay_map.first; lay_mapit; lay_mapit = lay_mapit->next) {
1573  CustomData_data_transfer(&geom_map[VDATA], lay_mapit);
1574  }
1575 
1576  BLI_freelistN(&lay_map);
1577  }
1578  }
1579  if (DT_DATATYPE_IS_EDGE(dtdata_type)) {
1580  MVert *verts_dst = me_dst->mvert;
1581  const int num_verts_dst = me_dst->totvert;
1582  MEdge *edges_dst = me_dst->medge;
1583  const int num_edges_dst = me_dst->totedge;
1584 
1585  if (!geom_map_init[EDATA]) {
1586  const int num_edges_src = me_src->totedge;
1587 
1588  if ((map_edge_mode == MREMAP_MODE_TOPOLOGY) && (num_edges_dst != num_edges_src)) {
1589  BKE_report(reports,
1590  RPT_ERROR,
1591  "Source and destination meshes do not have the same amount of edges, "
1592  "'Topology' mapping cannot be used in this case");
1593  continue;
1594  }
1595  if ((map_edge_mode & MREMAP_USE_POLY) && (me_src->totpoly == 0)) {
1596  BKE_report(reports,
1597  RPT_ERROR,
1598  "Source mesh doesn't have any faces, "
1599  "None of the 'Face' mappings can be used in this case");
1600  continue;
1601  }
1602  if (ELEM(0, num_edges_dst, num_edges_src)) {
1603  BKE_report(
1604  reports,
1605  RPT_ERROR,
1606  "Source or destination meshes do not have any edges, cannot transfer edge data");
1607  continue;
1608  }
1609 
1611  space_transform,
1612  max_distance,
1613  ray_radius,
1614  verts_dst,
1615  num_verts_dst,
1616  edges_dst,
1617  num_edges_dst,
1618  dirty_nors_dst,
1619  me_src,
1620  &geom_map[EDATA]);
1621  geom_map_init[EDATA] = true;
1622  }
1623 
1624  if (mdef && vg_idx != -1 && !weights[EDATA]) {
1625  weights[EDATA] = MEM_mallocN(sizeof(*weights[EDATA]) * (size_t)num_edges_dst, __func__);
1627  mdef, vg_idx, num_verts_dst, edges_dst, num_edges_dst, weights[EDATA], invert_vgroup);
1628  }
1629 
1631  ob_src,
1632  ob_dst,
1633  me_src,
1634  me_dst,
1635  ME_EDGE,
1636  cddata_type,
1637  mix_mode,
1638  mix_factor,
1639  weights[EDATA],
1640  num_edges_dst,
1641  use_create,
1642  use_delete,
1643  fromlayers,
1644  tolayers,
1645  space_transform)) {
1646  CustomDataTransferLayerMap *lay_mapit;
1647 
1648  changed |= (lay_map.first != NULL);
1649 
1650  for (lay_mapit = lay_map.first; lay_mapit; lay_mapit = lay_mapit->next) {
1651  CustomData_data_transfer(&geom_map[EDATA], lay_mapit);
1652  }
1653 
1654  BLI_freelistN(&lay_map);
1655  }
1656  }
1657  if (DT_DATATYPE_IS_LOOP(dtdata_type)) {
1658  MVert *verts_dst = me_dst->mvert;
1659  const int num_verts_dst = me_dst->totvert;
1660  MEdge *edges_dst = me_dst->medge;
1661  const int num_edges_dst = me_dst->totedge;
1662  MPoly *polys_dst = me_dst->mpoly;
1663  const int num_polys_dst = me_dst->totpoly;
1664  MLoop *loops_dst = me_dst->mloop;
1665  const int num_loops_dst = me_dst->totloop;
1666  CustomData *pdata_dst = &me_dst->pdata;
1667  CustomData *ldata_dst = &me_dst->ldata;
1668 
1669  MeshRemapIslandsCalc island_callback = data_transfer_get_loop_islands_generator(cddata_type);
1670 
1671  if (!geom_map_init[LDATA]) {
1672  const int num_loops_src = me_src->totloop;
1673 
1674  if ((map_loop_mode == MREMAP_MODE_TOPOLOGY) && (num_loops_dst != num_loops_src)) {
1675  BKE_report(reports,
1676  RPT_ERROR,
1677  "Source and destination meshes do not have the same amount of face corners, "
1678  "'Topology' mapping cannot be used in this case");
1679  continue;
1680  }
1681  if ((map_loop_mode & MREMAP_USE_EDGE) && (me_src->totedge == 0)) {
1682  BKE_report(reports,
1683  RPT_ERROR,
1684  "Source mesh doesn't have any edges, "
1685  "None of the 'Edge' mappings can be used in this case");
1686  continue;
1687  }
1688  if (ELEM(0, num_loops_dst, num_loops_src)) {
1689  BKE_report(
1690  reports,
1691  RPT_ERROR,
1692  "Source or destination meshes do not have any faces, cannot transfer corner data");
1693  continue;
1694  }
1695 
1697  space_transform,
1698  max_distance,
1699  ray_radius,
1700  verts_dst,
1701  num_verts_dst,
1702  edges_dst,
1703  num_edges_dst,
1704  loops_dst,
1705  num_loops_dst,
1706  polys_dst,
1707  num_polys_dst,
1708  ldata_dst,
1709  pdata_dst,
1710  (me_dst->flag & ME_AUTOSMOOTH) != 0,
1711  me_dst->smoothresh,
1712  dirty_nors_dst,
1713  me_src,
1714  island_callback,
1715  islands_handling_precision,
1716  &geom_map[LDATA]);
1717  geom_map_init[LDATA] = true;
1718  }
1719 
1720  if (mdef && vg_idx != -1 && !weights[LDATA]) {
1721  weights[LDATA] = MEM_mallocN(sizeof(*weights[LDATA]) * (size_t)num_loops_dst, __func__);
1723  mdef, vg_idx, num_verts_dst, loops_dst, num_loops_dst, weights[LDATA], invert_vgroup);
1724  }
1725 
1727  ob_src,
1728  ob_dst,
1729  me_src,
1730  me_dst,
1731  ME_LOOP,
1732  cddata_type,
1733  mix_mode,
1734  mix_factor,
1735  weights[LDATA],
1736  num_loops_dst,
1737  use_create,
1738  use_delete,
1739  fromlayers,
1740  tolayers,
1741  space_transform)) {
1742  CustomDataTransferLayerMap *lay_mapit;
1743 
1744  changed |= (lay_map.first != NULL);
1745 
1746  for (lay_mapit = lay_map.first; lay_mapit; lay_mapit = lay_mapit->next) {
1747  CustomData_data_transfer(&geom_map[LDATA], lay_mapit);
1748  }
1749 
1750  BLI_freelistN(&lay_map);
1751  }
1752  }
1753  if (DT_DATATYPE_IS_POLY(dtdata_type)) {
1754  MVert *verts_dst = me_dst->mvert;
1755  const int num_verts_dst = me_dst->totvert;
1756  MPoly *polys_dst = me_dst->mpoly;
1757  const int num_polys_dst = me_dst->totpoly;
1758  MLoop *loops_dst = me_dst->mloop;
1759  const int num_loops_dst = me_dst->totloop;
1760  CustomData *pdata_dst = &me_dst->pdata;
1761 
1762  if (!geom_map_init[PDATA]) {
1763  const int num_polys_src = me_src->totpoly;
1764 
1765  if ((map_poly_mode == MREMAP_MODE_TOPOLOGY) && (num_polys_dst != num_polys_src)) {
1766  BKE_report(reports,
1767  RPT_ERROR,
1768  "Source and destination meshes do not have the same amount of faces, "
1769  "'Topology' mapping cannot be used in this case");
1770  continue;
1771  }
1772  if ((map_poly_mode & MREMAP_USE_EDGE) && (me_src->totedge == 0)) {
1773  BKE_report(reports,
1774  RPT_ERROR,
1775  "Source mesh doesn't have any edges, "
1776  "None of the 'Edge' mappings can be used in this case");
1777  continue;
1778  }
1779  if (ELEM(0, num_polys_dst, num_polys_src)) {
1780  BKE_report(
1781  reports,
1782  RPT_ERROR,
1783  "Source or destination meshes do not have any faces, cannot transfer face data");
1784  continue;
1785  }
1786 
1788  space_transform,
1789  max_distance,
1790  ray_radius,
1791  verts_dst,
1792  num_verts_dst,
1793  loops_dst,
1794  num_loops_dst,
1795  polys_dst,
1796  num_polys_dst,
1797  pdata_dst,
1798  dirty_nors_dst,
1799  me_src,
1800  &geom_map[PDATA]);
1801  geom_map_init[PDATA] = true;
1802  }
1803 
1804  if (mdef && vg_idx != -1 && !weights[PDATA]) {
1805  weights[PDATA] = MEM_mallocN(sizeof(*weights[PDATA]) * (size_t)num_polys_dst, __func__);
1807  vg_idx,
1808  num_verts_dst,
1809  loops_dst,
1810  num_loops_dst,
1811  polys_dst,
1812  num_polys_dst,
1813  weights[PDATA],
1814  invert_vgroup);
1815  }
1816 
1818  ob_src,
1819  ob_dst,
1820  me_src,
1821  me_dst,
1822  ME_POLY,
1823  cddata_type,
1824  mix_mode,
1825  mix_factor,
1826  weights[PDATA],
1827  num_polys_dst,
1828  use_create,
1829  use_delete,
1830  fromlayers,
1831  tolayers,
1832  space_transform)) {
1833  CustomDataTransferLayerMap *lay_mapit;
1834 
1835  changed |= (lay_map.first != NULL);
1836 
1837  for (lay_mapit = lay_map.first; lay_mapit; lay_mapit = lay_mapit->next) {
1838  CustomData_data_transfer(&geom_map[PDATA], lay_mapit);
1839  }
1840 
1841  BLI_freelistN(&lay_map);
1842  }
1843  }
1844 
1845  data_transfer_dtdata_type_postprocess(ob_src, ob_dst, me_src, me_dst, dtdata_type, changed);
1846  }
1847 
1848  for (int i = 0; i < DATAMAX; i++) {
1849  BKE_mesh_remap_free(&geom_map[i]);
1850  MEM_SAFE_FREE(weights[i]);
1851  }
1852 
1853  return changed;
1854 
1855 #undef VDATA
1856 #undef EDATA
1857 #undef LDATA
1858 #undef PDATA
1859 #undef DATAMAX
1860 }
1861 
1863  Scene *scene,
1864  Object *ob_src,
1865  Object *ob_dst,
1866  const int data_types,
1867  const bool use_create,
1868  const int map_vert_mode,
1869  const int map_edge_mode,
1870  const int map_loop_mode,
1871  const int map_poly_mode,
1872  SpaceTransform *space_transform,
1873  const bool auto_transform,
1874  const float max_distance,
1875  const float ray_radius,
1876  const float islands_handling_precision,
1877  const int fromlayers_select[DT_MULTILAYER_INDEX_MAX],
1878  const int tolayers_select[DT_MULTILAYER_INDEX_MAX],
1879  const int mix_mode,
1880  const float mix_factor,
1881  const char *vgroup_name,
1882  const bool invert_vgroup,
1883  ReportList *reports)
1884 {
1886  scene,
1887  ob_src,
1888  ob_dst,
1889  NULL,
1890  data_types,
1891  use_create,
1892  map_vert_mode,
1893  map_edge_mode,
1894  map_loop_mode,
1895  map_poly_mode,
1896  space_transform,
1897  auto_transform,
1898  max_distance,
1899  ray_radius,
1900  islands_handling_precision,
1901  fromlayers_select,
1902  tolayers_select,
1903  mix_mode,
1904  mix_factor,
1905  vgroup_name,
1906  invert_vgroup,
1907  reports);
1908 }
typedef float(TangentPoint)[2]
CustomData interface, see also DNA_customdata_types.h.
const char * CustomData_get_layer_name(const struct CustomData *data, int type, int n)
int CustomData_number_of_layers(const struct CustomData *data, int type)
bool CustomData_free_layer(struct CustomData *data, int type, int totelem, int index)
Definition: customdata.c:2655
@ CD_CALLOC
@ CDT_MIX_SUB
@ CDT_MIX_REPLACE_BELOW_THRESHOLD
@ CDT_MIX_REPLACE_ABOVE_THRESHOLD
@ CDT_MIX_ADD
@ CDT_MIX_MUL
@ CDT_MIX_TRANSFER
@ CDT_MIX_MIX
bool CustomData_layertype_is_singleton(int type)
Definition: customdata.c:4292
void * CustomData_duplicate_referenced_layer_n(struct CustomData *data, const int type, const int n, const int totelem)
Definition: customdata.c:2796
void CustomData_data_transfer(const struct MeshPairRemap *me_remap, const CustomDataTransferLayerMap *laymap)
bool CustomData_MeshMasks_are_matching(const CustomData_MeshMasks *mask_ref, const CustomData_MeshMasks *mask_required)
Definition: customdata.c:87
void * CustomData_add_layer_named(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem, const char *name)
Definition: customdata.c:2637
const CustomData_MeshMasks CD_MASK_BAREMESH
Definition: customdata.c:1919
int CustomData_get_active_layer(const struct CustomData *data, int type)
void(* cd_datatransfer_interp)(const struct CustomDataTransferLayerMap *laymap, void *dest, const void **sources, const float *weights, const int count, const float mix_factor)
void * CustomData_duplicate_referenced_layer(struct CustomData *data, const int type, const int totelem)
Definition: customdata.c:2788
void * CustomData_get_layer_n(const struct CustomData *data, int type, int n)
@ ME_VERT
@ ME_POLY
@ ME_LOOP
@ ME_EDGE
void * CustomData_get_layer(const struct CustomData *data, int type)
int CustomData_get_named_layer(const struct CustomData *data, int type, const char *name)
Definition: customdata.c:2365
@ CD_FAKE_UV
@ CD_FAKE_LNOR
@ CD_FAKE_CREASE
@ CD_FAKE
@ CD_FAKE_SHARP
@ CD_FAKE_BWEIGHT
@ CD_FAKE_MDEFORMVERT
@ CD_FAKE_SHAPEKEY
@ CD_FAKE_SEAM
void * CustomData_add_layer(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem)
Definition: customdata.c:2620
void CustomData_set_layer_flag(struct CustomData *data, int type, int flag)
Definition: customdata.c:2475
@ DT_LAYERS_ALL_SRC
@ DT_LAYERS_ACTIVE_SRC
@ DT_LAYERS_ACTIVE_DST
@ DT_LAYERS_INDEX_DST
@ DT_LAYERS_NAME_DST
#define DT_DATATYPE_IS_POLY(_dt)
#define DT_TYPE_MAX
#define DT_DATATYPE_IS_LOOP(_dt)
#define DT_DATATYPE_IS_EDGE(_dt)
@ DT_TYPE_SKIN
@ DT_TYPE_UV
@ DT_TYPE_BWEIGHT_VERT
@ DT_TYPE_FREESTYLE_FACE
@ DT_TYPE_SHAPEKEY
@ DT_TYPE_CREASE
@ DT_TYPE_SEAM
@ DT_TYPE_LNOR
@ DT_TYPE_VCOL
@ DT_TYPE_SHARP_FACE
@ DT_TYPE_MDEFORMVERT
@ DT_TYPE_BWEIGHT_EDGE
@ DT_TYPE_FREESTYLE_EDGE
@ DT_TYPE_SHARP_EDGE
@ DT_MULTILAYER_INDEX_MAX
@ DT_MULTILAYER_INDEX_MDEFORMVERT
@ DT_MULTILAYER_INDEX_INVALID
@ DT_MULTILAYER_INDEX_SHAPEKEY
@ DT_MULTILAYER_INDEX_UV
@ DT_MULTILAYER_INDEX_VCOL
#define DT_DATATYPE_IS_VERT(_dt)
support for deformation groups and hooks.
void BKE_defvert_extract_vgroup_to_loopweights(struct MDeformVert *dvert, const int defgroup, const int num_verts, struct MLoop *loops, const int num_loops, float *r_weights, const bool invert_vgroup)
Definition: deform.c:1043
void BKE_defvert_extract_vgroup_to_polyweights(struct MDeformVert *dvert, const int defgroup, const int num_verts, struct MLoop *loops, const int num_loops, struct MPoly *polys, const int num_polys, float *r_weights, const bool invert_vgroup)
void BKE_defvert_extract_vgroup_to_edgeweights(struct MDeformVert *dvert, const int defgroup, const int num_verts, struct MEdge *edges, const int num_edges, float *r_weights, const bool invert_vgroup)
Definition: deform.c:1015
void BKE_defvert_extract_vgroup_to_vertweights(struct MDeformVert *dvert, const int defgroup, const int num_verts, float *r_weights, const bool invert_vgroup)
Definition: deform.c:992
int BKE_object_defgroup_name_index(const struct Object *ob, const char *name)
void BKE_mesh_normals_loop_custom_set(const struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges, struct MLoop *mloops, float(*r_custom_loopnors)[3], const int numLoops, struct MPoly *mpolys, const float(*polynors)[3], const int numPolys, short(*r_clnors_data)[2])
void BKE_mesh_normals_loop_split(const struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges, struct MLoop *mloops, float(*r_loopnors)[3], const int numLoops, struct MPoly *mpolys, const float(*polynors)[3], const int numPolys, const bool use_split_normals, const float split_angle, MLoopNorSpaceArray *r_lnors_spacearr, short(*clnors_data)[2], int *r_loop_to_poly)
void BKE_mesh_calc_normals_poly(struct MVert *mverts, float(*r_vertnors)[3], int numVerts, const struct MLoop *mloop, const struct MPoly *mpolys, int numLoops, int numPolys, float(*r_polyNors)[3], const bool only_face_normals)
bool(* MeshRemapIslandsCalc)(struct MVert *verts, const int totvert, struct MEdge *edges, const int totedge, struct MPoly *polys, const int totpoly, struct MLoop *loops, const int totloop, struct MeshIslandStore *r_island_store)
bool BKE_mesh_calc_islands_loop_poly_edgeseam(struct MVert *verts, const int totvert, struct MEdge *edges, const int totedge, struct MPoly *polys, const int totpoly, struct MLoop *loops, const int totloop, MeshIslandStore *r_island_store)
void BKE_mesh_remap_calc_source_cddata_masks_from_map_modes(const int vert_mode, const int edge_mode, const int loop_mode, const int poly_mode, struct CustomData_MeshMasks *cddata_mask)
void BKE_mesh_remap_calc_edges_from_mesh(const int mode, const struct SpaceTransform *space_transform, const float max_dist, const float ray_radius, const struct MVert *verts_dst, const int numverts_dst, const struct MEdge *edges_dst, const int numedges_dst, const bool dirty_nors_dst, struct Mesh *me_src, MeshPairRemap *r_map)
void BKE_mesh_remap_calc_polys_from_mesh(const int mode, const struct SpaceTransform *space_transform, const float max_dist, const float ray_radius, struct MVert *verts_dst, const int numverts_dst, struct MLoop *loops_dst, const int numloops_dst, struct MPoly *polys_dst, const int numpolys_dst, struct CustomData *pdata_dst, const bool dirty_nors_dst, struct Mesh *me_src, struct MeshPairRemap *r_map)
void BKE_mesh_remap_free(MeshPairRemap *map)
Definition: mesh_remap.c:365
void BKE_mesh_remap_calc_loops_from_mesh(const int mode, const struct SpaceTransform *space_transform, const float max_dist, const float ray_radius, struct MVert *verts_dst, const int numverts_dst, struct MEdge *edges_dst, const int numedges_dst, struct MLoop *loops_dst, const int numloops_dst, struct MPoly *polys_dst, const int numpolys_dst, struct CustomData *ldata_dst, struct CustomData *pdata_dst, const bool use_split_nors_dst, const float split_angle_dst, const bool dirty_nors_dst, struct Mesh *me_src, MeshRemapIslandsCalc gen_islands_src, const float islands_precision_src, struct MeshPairRemap *r_map)
void BKE_mesh_remap_calc_verts_from_mesh(const int mode, const struct SpaceTransform *space_transform, const float max_dist, const float ray_radius, const struct MVert *verts_dst, const int numverts_dst, const bool dirty_nors_dst, struct Mesh *me_src, MeshPairRemap *r_map)
@ MREMAP_MODE_TOPOLOGY
@ MREMAP_USE_POLY
@ MREMAP_USE_EDGE
void BKE_mesh_remap_find_best_match_from_mesh(const struct MVert *verts_dst, const int numverts_dst, struct Mesh *me_src, struct SpaceTransform *r_space_transform)
struct Mesh * mesh_get_eval_final(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, const struct CustomData_MeshMasks *dataMask)
void BKE_mesh_wrapper_ensure_mdata(struct Mesh *me)
Definition: mesh_wrapper.c:98
struct Mesh * BKE_modifier_get_evaluated_mesh_from_evaluated_object(struct Object *ob_eval, const bool get_cage_mesh)
General operations, lookup, etc. for blender objects.
Functions for dealing with objects and deform verts, used by painting and tools.
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
#define BLI_assert(a)
Definition: BLI_assert.h:58
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
MINLINE float interpf(float a, float b, float t)
#define UNUSED(x)
#define ELEM(...)
#define CLOG_WARN(clg_ref,...)
Definition: CLG_log.h:203
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
#define CD_MASK_NORMAL
#define CD_MASK_MDEFORMVERT
@ CD_MVERT_SKIN
@ CD_CUSTOMLOOPNORMAL
@ CD_MDEFORMVERT
@ CD_MLOOPCOL
@ CD_FREESTYLE_EDGE
@ CD_FREESTYLE_FACE
@ CD_MLOOPUV
#define CD_MASK_CUSTOMLOOPNORMAL
#define CD_MASK_MLOOPUV
@ CD_FLAG_TEMPORARY
@ ME_CDFLAG_EDGE_CREASE
@ ME_CDFLAG_VERT_BWEIGHT
@ ME_CDFLAG_EDGE_BWEIGHT
@ ME_AUTOSMOOTH
@ FREESTYLE_EDGE_MARK
@ ME_SEAM
@ ME_SHARP
@ FREESTYLE_FACE_MARK
@ ME_SMOOTH
Object is a sort of wrapper for general info.
@ OB_MESH
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
Group RGB to Bright Vector Camera CLAMP
void customdata_data_transfer_interp_normal_normals(const CustomDataTransferLayerMap *laymap, void *data_dst, const void **sources, const float *weights, const int count, const float mix_factor)
Definition: customdata.c:4924
void data_transfer_layersmapping_add_item(ListBase *r_map, const int cddata_type, const int mix_mode, const float mix_factor, const float *mix_weights, const void *data_src, void *data_dst, const int data_src_n, const int data_dst_n, const size_t elem_size, const size_t data_size, const size_t data_offset, const uint64_t data_flag, cd_datatransfer_interp interp, void *interp_data)
static MeshRemapIslandsCalc data_transfer_get_loop_islands_generator(const int cddata_type)
static bool data_transfer_layersmapping_generate(ListBase *r_map, Object *ob_src, Object *ob_dst, Mesh *me_src, Mesh *me_dst, const int elem_type, int cddata_type, int mix_mode, float mix_factor, const float *mix_weights, const int num_elem_dst, const bool use_create, const bool use_delete, const int fromlayers, const int tolayers, SpaceTransform *space_transform)
int BKE_object_data_transfer_dttype_to_srcdst_index(const int dtdata_type)
int BKE_object_data_transfer_get_dttypes_item_types(const int dtdata_types)
static bool data_transfer_layersmapping_cdlayers(ListBase *r_map, const int cddata_type, 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, CustomData *cd_src, CustomData *cd_dst, const bool use_dupref_dst, const int fromlayers, const int tolayers, cd_datatransfer_interp interp, void *interp_data)
static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map, const int cddata_type, 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, CustomData *cd_src, CustomData *cd_dst, const bool use_dupref_dst, const int tolayers, const bool *use_layers_src, const int num_layers_src, cd_datatransfer_interp interp, void *interp_data)
static void data_transfer_layersmapping_add_item_cd(ListBase *r_map, const int cddata_type, const int mix_mode, const float mix_factor, const float *mix_weights, void *data_src, void *data_dst, cd_datatransfer_interp interp, void *interp_data)
bool BKE_object_data_transfer_get_dttypes_capacity(const int dtdata_types, bool *r_advanced_mixing, bool *r_threshold)
#define DATAMAX
#define EDATA
static void data_transfer_dtdata_type_postprocess(Object *UNUSED(ob_src), Object *UNUSED(ob_dst), Mesh *UNUSED(me_src), Mesh *me_dst, const int dtdata_type, const bool changed)
bool BKE_object_data_transfer_mesh(struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, Object *ob_dst, const int data_types, const bool use_create, const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode, SpaceTransform *space_transform, const bool auto_transform, const float max_distance, const float ray_radius, const float islands_handling_precision, const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX], const int mix_mode, const float mix_factor, const char *vgroup_name, const bool invert_vgroup, ReportList *reports)
int BKE_object_data_transfer_dttype_to_cdtype(const int dtdata_type)
float data_transfer_interp_float_do(const int mix_mode, const float val_dst, const float val_src, const float mix_factor)
#define VDATA
void BKE_object_data_transfer_dttypes_to_cdmask(const int dtdata_types, CustomData_MeshMasks *r_data_masks)
Definition: data_transfer.c:56
static CLG_LogRef LOG
Definition: data_transfer.c:54
static void data_transfer_dtdata_type_preprocess(Mesh *me_src, Mesh *me_dst, const int dtdata_type, const bool dirty_nors_dst)
#define LDATA
static void data_transfer_interp_char(const CustomDataTransferLayerMap *laymap, void *dest, const void **sources, const float *weights, const int count, const float mix_factor)
void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, Object *ob_dst, const int data_types, const bool use_delete, const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX])
#define PDATA
bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, Object *ob_dst, Mesh *me_dst, const int data_types, bool use_create, const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode, SpaceTransform *space_transform, const bool auto_transform, const float max_distance, const float ray_radius, const float islands_handling_precision, const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX], const int mix_mode, const float mix_factor, const char *vgroup_name, const bool invert_vgroup, ReportList *reports)
bool data_transfer_layersmapping_vgroups(struct 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, struct Object *ob_src, struct Object *ob_dst, struct CustomData *cd_src, struct CustomData *cd_dst, const bool use_dupref_dst, const int fromlayers, const int tolayers)
Definition: deform.c:1308
Scene scene
const Depsgraph * depsgraph
int count
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
return ret
unsigned __int64 uint64_t
Definition: stdint.h:93
struct CustomDataTransferLayerMap * next
cd_datatransfer_interp interp
void * first
Definition: DNA_listBase.h:47
int64_t cd_dirty_vert
struct MEdge * medge
float smoothresh
struct CustomData pdata ldata
struct MVert * mvert
struct MDeformVert * dvert
int totedge
char cd_flag
int totvert
short flag
struct MLoop * mloop
Mesh_Runtime runtime
int totpoly
int totloop
struct MPoly * mpoly
CustomData_MeshMasks last_data_mask
Object_Runtime runtime
void * data
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)