Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/data_transfer.c')
-rw-r--r--source/blender/blenkernel/intern/data_transfer.c387
1 files changed, 171 insertions, 216 deletions
diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index 3639649eab5..7006e4ddaa6 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -42,12 +42,10 @@
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
-#include "BKE_cdderivedmesh.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_data_transfer.h"
#include "BKE_deform.h"
-#include "BKE_DerivedMesh.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_mesh_runtime.h"
@@ -257,77 +255,76 @@ int BKE_object_data_transfer_dttype_to_srcdst_index(const int dtdata_type)
/* Generic pre/post processing, only used by custom loop normals currently. */
static void data_transfer_dtdata_type_preprocess(
- Object *UNUSED(ob_src), Object *UNUSED(ob_dst), DerivedMesh *dm_src, DerivedMesh *dm_dst, Mesh *me_dst,
- const int dtdata_type, const bool dirty_nors_dst, const bool use_split_nors_src, const float split_angle_src)
+ Mesh *me_src, Mesh *me_dst,
+ const int dtdata_type, const bool dirty_nors_dst)
{
if (dtdata_type == DT_TYPE_LNOR) {
/* Compute custom normals into regular loop normals, which will be used for the transfer. */
- MVert *verts_dst = dm_dst ? dm_dst->getVertArray(dm_dst) : me_dst->mvert;
- const int num_verts_dst = dm_dst ? dm_dst->getNumVerts(dm_dst) : me_dst->totvert;
- MEdge *edges_dst = dm_dst ? dm_dst->getEdgeArray(dm_dst) : me_dst->medge;
- const int num_edges_dst = dm_dst ? dm_dst->getNumEdges(dm_dst) : me_dst->totedge;
- MPoly *polys_dst = dm_dst ? dm_dst->getPolyArray(dm_dst) : me_dst->mpoly;
- const int num_polys_dst = dm_dst ? dm_dst->getNumPolys(dm_dst) : me_dst->totpoly;
- MLoop *loops_dst = dm_dst ? dm_dst->getLoopArray(dm_dst) : me_dst->mloop;
- const int num_loops_dst = dm_dst ? dm_dst->getNumLoops(dm_dst) : me_dst->totloop;
- CustomData *pdata_dst = dm_dst ? dm_dst->getPolyDataLayout(dm_dst) : &me_dst->pdata;
- CustomData *ldata_dst = dm_dst ? dm_dst->getLoopDataLayout(dm_dst) : &me_dst->ldata;
+ MVert *verts_dst = me_dst->mvert;
+ const int num_verts_dst = me_dst->totvert;
+ MEdge *edges_dst = me_dst->medge;
+ const int num_edges_dst = me_dst->totedge;
+ MPoly *polys_dst = me_dst->mpoly;
+ const int num_polys_dst = me_dst->totpoly;
+ MLoop *loops_dst = me_dst->mloop;
+ const int num_loops_dst = me_dst->totloop;
+ CustomData *pdata_dst = &me_dst->pdata;
+ CustomData *ldata_dst = &me_dst->ldata;
const bool use_split_nors_dst = (me_dst->flag & ME_AUTOSMOOTH) != 0;
const float split_angle_dst = me_dst->smoothresh;
- dm_src->calcLoopNormals(dm_src, use_split_nors_src, split_angle_src);
+ BKE_mesh_calc_normals_split(me_src);
- if (dm_dst) {
- dm_dst->calcLoopNormals(dm_dst, use_split_nors_dst, split_angle_dst);
- }
- else {
- float (*poly_nors_dst)[3];
- float (*loop_nors_dst)[3];
- short (*custom_nors_dst)[2] = CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL);
-
- /* Cache poly nors into a temp CDLayer. */
- poly_nors_dst = CustomData_get_layer(pdata_dst, CD_NORMAL);
- if (dirty_nors_dst || !poly_nors_dst) {
- if (!poly_nors_dst) {
- poly_nors_dst = CustomData_add_layer(pdata_dst, CD_NORMAL, CD_CALLOC, NULL, num_polys_dst);
- CustomData_set_layer_flag(pdata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
- }
- BKE_mesh_calc_normals_poly(verts_dst, NULL, num_verts_dst, loops_dst, polys_dst,
- num_loops_dst, num_polys_dst, poly_nors_dst, true);
- }
- /* Cache loop nors into a temp CDLayer. */
- loop_nors_dst = CustomData_get_layer(ldata_dst, CD_NORMAL);
- if (dirty_nors_dst || loop_nors_dst) {
- if (!loop_nors_dst) {
- loop_nors_dst = CustomData_add_layer(ldata_dst, CD_NORMAL, CD_CALLOC, NULL, num_loops_dst);
- CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
- }
- BKE_mesh_normals_loop_split(verts_dst, num_verts_dst, edges_dst, num_edges_dst,
- loops_dst, loop_nors_dst, num_loops_dst,
- polys_dst, (const float (*)[3])poly_nors_dst, num_polys_dst,
- use_split_nors_dst, split_angle_dst, NULL, custom_nors_dst, NULL);
- }
+ float (*poly_nors_dst)[3];
+ float (*loop_nors_dst)[3];
+ short (*custom_nors_dst)[2] = CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL);
+
+ /* Cache poly nors into a temp CDLayer. */
+ poly_nors_dst = CustomData_get_layer(pdata_dst, CD_NORMAL);
+ const bool do_poly_nors_dst = (poly_nors_dst == NULL);
+ if (do_poly_nors_dst) {
+ poly_nors_dst = CustomData_add_layer(pdata_dst, CD_NORMAL, CD_CALLOC, NULL, num_polys_dst);
+ CustomData_set_layer_flag(pdata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
+ }
+ if (dirty_nors_dst || do_poly_nors_dst) {
+ BKE_mesh_calc_normals_poly(
+ verts_dst, NULL, num_verts_dst, loops_dst, polys_dst,
+ num_loops_dst, num_polys_dst, poly_nors_dst, true);
+ }
+ /* Cache loop nors into a temp CDLayer. */
+ loop_nors_dst = CustomData_get_layer(ldata_dst, CD_NORMAL);
+ const bool do_loop_nors_dst = (loop_nors_dst == NULL);
+ if (do_loop_nors_dst) {
+ loop_nors_dst = CustomData_add_layer(ldata_dst, CD_NORMAL, CD_CALLOC, NULL, num_loops_dst);
+ CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
+ }
+ if (dirty_nors_dst || do_loop_nors_dst) {
+ BKE_mesh_normals_loop_split(
+ verts_dst, num_verts_dst, edges_dst, num_edges_dst,
+ loops_dst, loop_nors_dst, num_loops_dst,
+ polys_dst, (const float (*)[3])poly_nors_dst, num_polys_dst,
+ use_split_nors_dst, split_angle_dst, NULL, custom_nors_dst, NULL);
}
}
}
static void data_transfer_dtdata_type_postprocess(
- Object *UNUSED(ob_src), Object *UNUSED(ob_dst), DerivedMesh *UNUSED(dm_src), DerivedMesh *dm_dst, Mesh *me_dst,
+ Object *UNUSED(ob_src), Object *UNUSED(ob_dst), Mesh *UNUSED(me_src), Mesh *me_dst,
const int dtdata_type, const bool changed)
{
if (dtdata_type == DT_TYPE_LNOR) {
/* Bake edited destination loop normals into custom normals again. */
- MVert *verts_dst = dm_dst ? dm_dst->getVertArray(dm_dst) : me_dst->mvert;
- const int num_verts_dst = dm_dst ? dm_dst->getNumVerts(dm_dst) : me_dst->totvert;
- MEdge *edges_dst = dm_dst ? dm_dst->getEdgeArray(dm_dst) : me_dst->medge;
- const int num_edges_dst = dm_dst ? dm_dst->getNumEdges(dm_dst) : me_dst->totedge;
- MPoly *polys_dst = dm_dst ? dm_dst->getPolyArray(dm_dst) : me_dst->mpoly;
- const int num_polys_dst = dm_dst ? dm_dst->getNumPolys(dm_dst) : me_dst->totpoly;
- MLoop *loops_dst = dm_dst ? dm_dst->getLoopArray(dm_dst) : me_dst->mloop;
- const int num_loops_dst = dm_dst ? dm_dst->getNumLoops(dm_dst) : me_dst->totloop;
- CustomData *pdata_dst = dm_dst ? dm_dst->getPolyDataLayout(dm_dst) : &me_dst->pdata;
- CustomData *ldata_dst = dm_dst ? dm_dst->getLoopDataLayout(dm_dst) : &me_dst->ldata;
+ MVert *verts_dst = me_dst->mvert;
+ const int num_verts_dst = me_dst->totvert;
+ MEdge *edges_dst = me_dst->medge;
+ const int num_edges_dst = me_dst->totedge;
+ MPoly *polys_dst = me_dst->mpoly;
+ const int num_polys_dst = me_dst->totpoly;
+ MLoop *loops_dst = me_dst->mloop;
+ const int num_loops_dst = me_dst->totloop;
+ CustomData *pdata_dst = &me_dst->pdata;
+ CustomData *ldata_dst = &me_dst->ldata;
const float (*poly_nors_dst)[3] = CustomData_get_layer(pdata_dst, CD_NORMAL);
float (*loop_nors_dst)[3] = CustomData_get_layer(ldata_dst, CD_NORMAL);
@@ -531,7 +528,7 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(
continue;
}
data_src = CustomData_get_layer_n(cd_src, cddata_type, idx_src);
- /* If dest is a derivedmesh, we do not want to overwrite cdlayers of org mesh! */
+ /* If dest is a evaluated mesh (fro; ;odifier), we do not want to overwrite cdlayers of orig mesh! */
if (use_dupref_dst) {
data_dst = CustomData_duplicate_referenced_layer_n(cd_dst, cddata_type, idx_src, num_elem_dst);
}
@@ -575,7 +572,7 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(
data_dst_to_delete[idx_dst] = false;
}
if (r_map) {
- /* If dest is a derivedmesh, we do not want to overwrite cdlayers of org mesh! */
+ /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */
if (use_dupref_dst) {
data_dst = CustomData_duplicate_referenced_layer_n(cd_dst, cddata_type, idx_dst, num_elem_dst);
}
@@ -633,7 +630,7 @@ static bool data_transfer_layersmapping_cdlayers(
data_dst = CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
}
else if (use_dupref_dst && r_map) {
- /* If dest is a derivedmesh, we do not want to overwrite cdlayers of org mesh! */
+ /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */
data_dst = CustomData_duplicate_referenced_layer(cd_dst, cddata_type, num_elem_dst);
}
@@ -660,7 +657,7 @@ static bool data_transfer_layersmapping_cdlayers(
if (tolayers >= 0) { /* Real-layer index */
idx_dst = tolayers;
- /* If dest is a derivedmesh, we do not want to overwrite cdlayers of org mesh! */
+ /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */
if (use_dupref_dst && r_map) {
data_dst = CustomData_duplicate_referenced_layer_n(cd_dst, cddata_type, idx_dst, num_elem_dst);
}
@@ -676,7 +673,7 @@ static bool data_transfer_layersmapping_cdlayers(
data_dst = CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
}
else {
- /* If dest is a derivedmesh, we do not want to overwrite cdlayers of org mesh! */
+ /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */
if (use_dupref_dst && r_map) {
data_dst = CustomData_duplicate_referenced_layer_n(cd_dst, cddata_type, idx_dst, num_elem_dst);
}
@@ -697,7 +694,7 @@ static bool data_transfer_layersmapping_cdlayers(
CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst);
}
}
- /* If dest is a derivedmesh, we do not want to overwrite cdlayers of org mesh! */
+ /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */
if (use_dupref_dst && r_map) {
data_dst = CustomData_duplicate_referenced_layer_n(cd_dst, cddata_type, idx_dst, num_elem_dst);
}
@@ -714,7 +711,7 @@ static bool data_transfer_layersmapping_cdlayers(
CustomData_add_layer_named(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst, name);
idx_dst = CustomData_get_named_layer(cd_dst, cddata_type, name);
}
- /* If dest is a derivedmesh, we do not want to overwrite cdlayers of org mesh! */
+ /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */
if (use_dupref_dst && r_map) {
data_dst = CustomData_duplicate_referenced_layer_n(cd_dst, cddata_type, idx_dst, num_elem_dst);
}
@@ -763,7 +760,7 @@ static bool data_transfer_layersmapping_cdlayers(
}
static bool data_transfer_layersmapping_generate(
- ListBase *r_map, Object *ob_src, Object *ob_dst, DerivedMesh *dm_src, DerivedMesh *dm_dst, Mesh *me_dst,
+ 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)
@@ -775,12 +772,12 @@ static bool data_transfer_layersmapping_generate(
if (elem_type == ME_VERT) {
if (!(cddata_type & CD_FAKE)) {
- cd_src = dm_src->getVertDataLayout(dm_src);
- cd_dst = dm_dst ? dm_dst->getVertDataLayout(dm_dst) : &me_dst->vdata;
+ cd_src = &me_src->vdata;
+ cd_dst = &me_dst->vdata;
if (!data_transfer_layersmapping_cdlayers(r_map, cddata_type, mix_mode, mix_factor, mix_weights,
num_elem_dst, use_create, use_delete,
- cd_src, cd_dst, dm_dst != NULL,
+ cd_src, cd_dst, me_dst != ob_dst->data,
fromlayers, tolayers,
interp, interp_data))
{
@@ -795,24 +792,17 @@ static bool data_transfer_layersmapping_generate(
const size_t data_offset = offsetof(MVert, bweight);
const uint64_t data_flag = 0;
- if (!(dm_src->cd_flag & ME_CDFLAG_VERT_BWEIGHT)) {
- if (use_delete && !dm_dst) {
+ if (!(me_src->cd_flag & ME_CDFLAG_VERT_BWEIGHT)) {
+ if (use_delete) {
me_dst->cd_flag &= ~ME_CDFLAG_VERT_BWEIGHT;
}
return true;
}
- if (dm_dst) {
- dm_dst->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
- }
- else {
- me_dst->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
- }
+ me_dst->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
if (r_map) {
data_transfer_layersmapping_add_item(r_map, cddata_type, mix_mode, mix_factor, mix_weights,
- dm_src->getVertArray(dm_src),
- dm_dst ? dm_dst->getVertArray(dm_dst) : me_dst->mvert,
- dm_src->getNumVerts(dm_src),
- dm_dst ? dm_dst->getNumVerts(dm_dst) : me_dst->totvert,
+ me_src->mvert, me_dst->mvert,
+ me_src->totvert, me_dst->totvert,
elem_size, data_size, data_offset, data_flag,
data_transfer_interp_char, interp_data);
}
@@ -821,12 +811,12 @@ static bool data_transfer_layersmapping_generate(
else if (cddata_type == CD_FAKE_MDEFORMVERT) {
bool ret;
- cd_src = dm_src->getVertDataLayout(dm_src);
- cd_dst = dm_dst ? dm_dst->getVertDataLayout(dm_dst) : &me_dst->vdata;
+ cd_src = &me_src->vdata;
+ cd_dst = &me_dst->vdata;
ret = data_transfer_layersmapping_vgroups(r_map, mix_mode, mix_factor, mix_weights,
num_elem_dst, use_create, use_delete,
- ob_src, ob_dst, cd_src, cd_dst, dm_dst != NULL,
+ ob_src, ob_dst, cd_src, cd_dst, me_dst != ob_dst->data,
fromlayers, tolayers);
/* Mesh stores its dvert in a specific pointer too. :( */
@@ -840,12 +830,12 @@ static bool data_transfer_layersmapping_generate(
}
else if (elem_type == ME_EDGE) {
if (!(cddata_type & CD_FAKE)) { /* Unused for edges, currently... */
- cd_src = dm_src->getEdgeDataLayout(dm_src);
- cd_dst = dm_dst ? dm_dst->getEdgeDataLayout(dm_dst) : &me_dst->edata;
+ cd_src = &me_src->edata;
+ cd_dst = &me_dst->edata;
if (!data_transfer_layersmapping_cdlayers(r_map, cddata_type, mix_mode, mix_factor, mix_weights,
num_elem_dst, use_create, use_delete,
- cd_src, cd_dst, dm_dst != NULL,
+ cd_src, cd_dst, me_dst != ob_dst->data,
fromlayers, tolayers,
interp, interp_data))
{
@@ -860,24 +850,17 @@ static bool data_transfer_layersmapping_generate(
const size_t data_offset = offsetof(MEdge, crease);
const uint64_t data_flag = 0;
- if (!(dm_src->cd_flag & ME_CDFLAG_EDGE_CREASE)) {
- if (use_delete && !dm_dst) {
+ if (!(me_src->cd_flag & ME_CDFLAG_EDGE_CREASE)) {
+ if (use_delete && !me_dst) {
me_dst->cd_flag &= ~ME_CDFLAG_EDGE_CREASE;
}
return true;
}
- if (dm_dst) {
- dm_dst->cd_flag |= ME_CDFLAG_EDGE_CREASE;
- }
- else {
- me_dst->cd_flag |= ME_CDFLAG_EDGE_CREASE;
- }
+ me_dst->cd_flag |= ME_CDFLAG_EDGE_CREASE;
if (r_map) {
data_transfer_layersmapping_add_item(r_map, cddata_type, mix_mode, mix_factor, mix_weights,
- dm_src->getEdgeArray(dm_src),
- dm_dst ? dm_dst->getEdgeArray(dm_dst) : me_dst->medge,
- dm_src->getNumEdges(dm_src),
- dm_dst ? dm_dst->getNumEdges(dm_dst) : me_dst->totedge,
+ me_src->medge, me_dst->medge,
+ me_src->totedge, me_dst->totedge,
elem_size, data_size, data_offset, data_flag,
data_transfer_interp_char, interp_data);
}
@@ -889,24 +872,17 @@ static bool data_transfer_layersmapping_generate(
const size_t data_offset = offsetof(MEdge, bweight);
const uint64_t data_flag = 0;
- if (!(dm_src->cd_flag & ME_CDFLAG_EDGE_BWEIGHT)) {
- if (use_delete && !dm_dst) {
+ if (!(me_src->cd_flag & ME_CDFLAG_EDGE_BWEIGHT)) {
+ if (use_delete && !me_dst) {
me_dst->cd_flag &= ~ME_CDFLAG_EDGE_BWEIGHT;
}
return true;
}
- if (dm_dst) {
- dm_dst->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
- }
- else {
- me_dst->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
- }
+ me_dst->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
if (r_map) {
data_transfer_layersmapping_add_item(r_map, cddata_type, mix_mode, mix_factor, mix_weights,
- dm_src->getEdgeArray(dm_src),
- dm_dst ? dm_dst->getEdgeArray(dm_dst) : me_dst->medge,
- dm_src->getNumEdges(dm_src),
- dm_dst ? dm_dst->getNumEdges(dm_dst) : me_dst->totedge,
+ me_src->medge, me_dst->medge,
+ me_src->totedge, me_dst->totedge,
elem_size, data_size, data_offset, data_flag,
data_transfer_interp_char, interp_data);
}
@@ -920,10 +896,8 @@ static bool data_transfer_layersmapping_generate(
data_transfer_layersmapping_add_item(
r_map, cddata_type, mix_mode, mix_factor, mix_weights,
- dm_src->getEdgeArray(dm_src),
- dm_dst ? dm_dst->getEdgeArray(dm_dst) : me_dst->medge,
- dm_src->getNumEdges(dm_src),
- dm_dst ? dm_dst->getNumEdges(dm_dst) : me_dst->totedge,
+ me_src->medge, me_dst->medge,
+ me_src->totedge, me_dst->totedge,
elem_size, data_size, data_offset, data_flag, NULL, interp_data);
return true;
}
@@ -943,12 +917,12 @@ static bool data_transfer_layersmapping_generate(
}
if (!(cddata_type & CD_FAKE)) {
- cd_src = dm_src->getLoopDataLayout(dm_src);
- cd_dst = dm_dst ? dm_dst->getLoopDataLayout(dm_dst) : &me_dst->ldata;
+ cd_src = &me_src->ldata;
+ cd_dst = &me_dst->ldata;
if (!data_transfer_layersmapping_cdlayers(
r_map, cddata_type, mix_mode, mix_factor, mix_weights,
- num_elem_dst, use_create, use_delete, cd_src, cd_dst, dm_dst != NULL,
+ num_elem_dst, use_create, use_delete, cd_src, cd_dst, me_dst != ob_dst->data,
fromlayers, tolayers,
interp, interp_data))
{
@@ -967,12 +941,12 @@ static bool data_transfer_layersmapping_generate(
}
if (!(cddata_type & CD_FAKE)) {
- cd_src = dm_src->getPolyDataLayout(dm_src);
- cd_dst = dm_dst ? dm_dst->getPolyDataLayout(dm_dst) : &me_dst->pdata;
+ cd_src = &me_src->pdata;
+ cd_dst = &me_dst->pdata;
if (!data_transfer_layersmapping_cdlayers(
r_map, cddata_type, mix_mode, mix_factor, mix_weights,
- num_elem_dst, use_create, use_delete, cd_src, cd_dst, dm_dst != NULL,
+ num_elem_dst, use_create, use_delete, cd_src, cd_dst, me_dst != ob_dst->data,
fromlayers, tolayers,
interp, interp_data))
{
@@ -989,10 +963,8 @@ static bool data_transfer_layersmapping_generate(
data_transfer_layersmapping_add_item(
r_map, cddata_type, mix_mode, mix_factor, mix_weights,
- dm_src->getPolyArray(dm_src),
- dm_dst ? dm_dst->getPolyArray(dm_dst) : me_dst->mpoly,
- dm_src->getNumPolys(dm_src),
- dm_dst ? dm_dst->getNumPolys(dm_dst) : me_dst->totpoly,
+ me_src->mpoly, me_dst->mpoly,
+ me_src->totpoly, me_dst->totpoly,
elem_size, data_size, data_offset, data_flag, NULL, interp_data);
return true;
}
@@ -1015,22 +987,22 @@ void BKE_object_data_transfer_layout(
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])
{
- DerivedMesh *dm_src;
+ Mesh *me_src;
Mesh *me_dst;
int i;
const bool use_create = true; /* We always create needed layers here. */
- CustomDataMask dm_src_mask = CD_MASK_BAREMESH;
+ CustomDataMask me_src_mask = CD_MASK_BAREMESH;
BLI_assert((ob_src != ob_dst) && (ob_src->type == OB_MESH) && (ob_dst->type == OB_MESH));
me_dst = ob_dst->data;
- /* Get source DM.*/
- dm_src_mask |= BKE_object_data_transfer_dttypes_to_cdmask(data_types);
- dm_src = mesh_get_derived_final(depsgraph, scene, ob_src, dm_src_mask);
- if (!dm_src) {
+ /* Get source evaluated mesh.*/
+ me_src_mask |= BKE_object_data_transfer_dttypes_to_cdmask(data_types);
+ me_src = mesh_get_eval_final(depsgraph, scene, ob_src, me_src_mask);
+ if (!me_src) {
return;
}
@@ -1059,35 +1031,35 @@ void BKE_object_data_transfer_layout(
const int num_elem_dst = me_dst->totvert;
data_transfer_layersmapping_generate(
- NULL, ob_src, ob_dst, dm_src, NULL, me_dst, ME_VERT, cddata_type, 0, 0.0f, NULL,
+ NULL, ob_src, ob_dst, me_src, me_dst, ME_VERT, cddata_type, 0, 0.0f, NULL,
num_elem_dst, use_create, use_delete, fromlayers, tolayers, NULL);
}
if (DT_DATATYPE_IS_EDGE(dtdata_type)) {
const int num_elem_dst = me_dst->totedge;
data_transfer_layersmapping_generate(
- NULL, ob_src, ob_dst, dm_src, NULL, me_dst, ME_EDGE, cddata_type, 0, 0.0f, NULL,
+ NULL, ob_src, ob_dst, me_src, me_dst, ME_EDGE, cddata_type, 0, 0.0f, NULL,
num_elem_dst, use_create, use_delete, fromlayers, tolayers, NULL);
}
if (DT_DATATYPE_IS_LOOP(dtdata_type)) {
const int num_elem_dst = me_dst->totloop;
data_transfer_layersmapping_generate(
- NULL, ob_src, ob_dst, dm_src, NULL, me_dst, ME_LOOP, cddata_type, 0, 0.0f, NULL,
+ NULL, ob_src, ob_dst, me_src, me_dst, ME_LOOP, cddata_type, 0, 0.0f, NULL,
num_elem_dst, use_create, use_delete, fromlayers, tolayers, NULL);
}
if (DT_DATATYPE_IS_POLY(dtdata_type)) {
const int num_elem_dst = me_dst->totpoly;
data_transfer_layersmapping_generate(
- NULL, ob_src, ob_dst, dm_src, NULL, me_dst, ME_POLY, cddata_type, 0, 0.0f, NULL,
+ NULL, ob_src, ob_dst, me_src, me_dst, ME_POLY, cddata_type, 0, 0.0f, NULL,
num_elem_dst, use_create, use_delete, fromlayers, tolayers, NULL);
}
}
}
-bool BKE_object_data_transfer_dm(
- struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, Object *ob_dst, DerivedMesh *dm_dst,
+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,
@@ -1103,9 +1075,8 @@ bool BKE_object_data_transfer_dm(
SpaceTransform auto_space_transform;
- DerivedMesh *dm_src;
- Mesh *me_dst, *me_src;
- bool dirty_nors_dst = true; /* Assumed always true if not using a dm as destination. */
+ Mesh *me_src;
+ bool dirty_nors_dst = true; /* Assumed always true if not using an evaluated mesh as destination. */
int i;
MDeformVert *mdef = NULL;
@@ -1119,53 +1090,40 @@ bool BKE_object_data_transfer_dm(
const bool use_delete = false; /* We never delete data layers from destination here. */
- CustomDataMask dm_src_mask = CD_MASK_BAREMESH;
+ CustomDataMask me_src_mask = CD_MASK_BAREMESH;
BLI_assert((ob_src != ob_dst) && (ob_src->type == OB_MESH) && (ob_dst->type == OB_MESH));
- me_dst = ob_dst->data;
- me_src = ob_src->data;
- if (dm_dst) {
- dirty_nors_dst = (dm_dst->dirty & DM_DIRTY_NORMALS) != 0;
- use_create = false; /* Never create needed custom layers on DM (modifier case). */
+ if (me_dst) {
+ dirty_nors_dst = (me_dst->runtime.cd_dirty_vert & CD_NORMAL) != 0;
+ /* Never create needed custom layers on passed destination mesh
+ * (assumed to *not* be ob_dst->data, aka modifier case). */
+ use_create = false;
+ }
+ else {
+ me_dst = ob_dst->data;
}
if (vgroup_name) {
- if (dm_dst) {
- mdef = dm_dst->getVertDataArray(dm_dst, CD_MDEFORMVERT);
- }
- else {
- mdef = CustomData_get_layer(&me_dst->vdata, CD_MDEFORMVERT);
- }
+ mdef = CustomData_get_layer(&me_dst->vdata, CD_MDEFORMVERT);
if (mdef) {
vg_idx = defgroup_name_index(ob_dst, vgroup_name);
}
}
- /* Get source DM.*/
- dm_src_mask |= BKE_object_data_transfer_dttypes_to_cdmask(data_types);
- /* XXX Hack! In case this is being evaluated from dm stack, we cannot compute final dm,
- * can lead to infinite recursion in case of dependency cycles of DataTransfer modifiers...
- * Issue is, this means we cannot be sure to have requested cd layers in source.
- *
- * Also, we need to make a local copy of dm_src, otherwise we may end with concurrent creation
- * of data in it (multi-threaded evaluation of the modifier stack, see T46672).
- */
- dm_src = dm_dst ? ob_src->derivedFinal : mesh_get_derived_final(depsgraph, scene, ob_src, dm_src_mask);
- if (!dm_src) {
+ /* Get source evaluated mesh.*/
+ me_src_mask |= BKE_object_data_transfer_dttypes_to_cdmask(data_types);
+ me_src = mesh_get_eval_final(depsgraph, scene, ob_src, me_src_mask);
+ if (!me_src) {
return changed;
}
- dm_src = CDDM_copy(dm_src);
if (auto_transform) {
- MVert *verts_dst = dm_dst ? dm_dst->getVertArray(dm_dst) : me_dst->mvert;
- const int num_verts_dst = dm_dst ? dm_dst->getNumVerts(dm_dst) : me_dst->totvert;
-
if (space_transform == NULL) {
space_transform = &auto_space_transform;
}
- BKE_mesh_remap_find_best_match_from_dm(verts_dst, num_verts_dst, dm_src, space_transform);
+ BKE_mesh_remap_find_best_match_from_mesh(me_dst->mvert, me_dst->totvert, me_src, space_transform);
}
/* Check all possible data types.
@@ -1179,9 +1137,7 @@ bool BKE_object_data_transfer_dm(
continue;
}
- data_transfer_dtdata_type_preprocess(ob_src, ob_dst, dm_src, dm_dst, me_dst,
- dtdata_type, dirty_nors_dst,
- (me_src->flag & ME_AUTOSMOOTH) != 0, me_src->smoothresh);
+ data_transfer_dtdata_type_preprocess(me_src, me_dst, dtdata_type, dirty_nors_dst);
cddata_type = BKE_object_data_transfer_dttype_to_cdtype(dtdata_type);
@@ -1195,11 +1151,11 @@ bool BKE_object_data_transfer_dm(
}
if (DT_DATATYPE_IS_VERT(dtdata_type)) {
- MVert *verts_dst = dm_dst ? dm_dst->getVertArray(dm_dst) : me_dst->mvert;
- const int num_verts_dst = dm_dst ? dm_dst->getNumVerts(dm_dst) : me_dst->totvert;
+ MVert *verts_dst = me_dst->mvert;
+ const int num_verts_dst = me_dst->totvert;
if (!geom_map_init[VDATA]) {
- const int num_verts_src = dm_src->getNumVerts(dm_src);
+ const int num_verts_src = me_src->totvert;
if ((map_vert_mode == MREMAP_MODE_TOPOLOGY) && (num_verts_dst != num_verts_src)) {
BKE_report(reports, RPT_ERROR,
@@ -1207,13 +1163,13 @@ bool BKE_object_data_transfer_dm(
"'Topology' mapping cannot be used in this case");
continue;
}
- if ((map_vert_mode & MREMAP_USE_EDGE) && (dm_src->getNumEdges(dm_src) == 0)) {
+ if ((map_vert_mode & MREMAP_USE_EDGE) && (me_src->totedge == 0)) {
BKE_report(reports, RPT_ERROR,
"Source mesh doesn't have any edges, "
"None of the 'Edge' mappings can be used in this case");
continue;
}
- if ((map_vert_mode & MREMAP_USE_POLY) && (dm_src->getNumPolys(dm_src) == 0)) {
+ if ((map_vert_mode & MREMAP_USE_POLY) && (me_src->totpoly == 0)) {
BKE_report(reports, RPT_ERROR,
"Source mesh doesn't have any faces, "
"None of the 'Face' mappings can be used in this case");
@@ -1225,9 +1181,9 @@ bool BKE_object_data_transfer_dm(
continue;
}
- BKE_mesh_remap_calc_verts_from_dm(
+ BKE_mesh_remap_calc_verts_from_mesh(
map_vert_mode, space_transform, max_distance, ray_radius,
- verts_dst, num_verts_dst, dirty_nors_dst, dm_src, &geom_map[VDATA]);
+ verts_dst, num_verts_dst, dirty_nors_dst, me_src, &geom_map[VDATA]);
geom_map_init[VDATA] = true;
}
@@ -1237,7 +1193,7 @@ bool BKE_object_data_transfer_dm(
}
if (data_transfer_layersmapping_generate(
- &lay_map, ob_src, ob_dst, dm_src, dm_dst, me_dst, ME_VERT,
+ &lay_map, ob_src, ob_dst, me_src, me_dst, ME_VERT,
cddata_type, mix_mode, mix_factor, weights[VDATA],
num_verts_dst, use_create, use_delete, fromlayers, tolayers, space_transform))
{
@@ -1253,13 +1209,13 @@ bool BKE_object_data_transfer_dm(
}
}
if (DT_DATATYPE_IS_EDGE(dtdata_type)) {
- MVert *verts_dst = dm_dst ? dm_dst->getVertArray(dm_dst) : me_dst->mvert;
- const int num_verts_dst = dm_dst ? dm_dst->getNumVerts(dm_dst) : me_dst->totvert;
- MEdge *edges_dst = dm_dst ? dm_dst->getEdgeArray(dm_dst) : me_dst->medge;
- const int num_edges_dst = dm_dst ? dm_dst->getNumEdges(dm_dst) : me_dst->totedge;
+ MVert *verts_dst = me_dst->mvert;
+ const int num_verts_dst = me_dst->totvert;
+ MEdge *edges_dst = me_dst->medge;
+ const int num_edges_dst = me_dst->totedge;
if (!geom_map_init[EDATA]) {
- const int num_edges_src = dm_src->getNumEdges(dm_src);
+ const int num_edges_src = me_src->totedge;
if ((map_edge_mode == MREMAP_MODE_TOPOLOGY) && (num_edges_dst != num_edges_src)) {
BKE_report(reports, RPT_ERROR,
@@ -1267,7 +1223,7 @@ bool BKE_object_data_transfer_dm(
"'Topology' mapping cannot be used in this case");
continue;
}
- if ((map_edge_mode & MREMAP_USE_POLY) && (dm_src->getNumPolys(dm_src) == 0)) {
+ if ((map_edge_mode & MREMAP_USE_POLY) && (me_src->totpoly == 0)) {
BKE_report(reports, RPT_ERROR,
"Source mesh doesn't have any faces, "
"None of the 'Face' mappings can be used in this case");
@@ -1279,10 +1235,10 @@ bool BKE_object_data_transfer_dm(
continue;
}
- BKE_mesh_remap_calc_edges_from_dm(
+ BKE_mesh_remap_calc_edges_from_mesh(
map_edge_mode, space_transform, max_distance, ray_radius,
verts_dst, num_verts_dst, edges_dst, num_edges_dst, dirty_nors_dst,
- dm_src, &geom_map[EDATA]);
+ me_src, &geom_map[EDATA]);
geom_map_init[EDATA] = true;
}
@@ -1294,7 +1250,7 @@ bool BKE_object_data_transfer_dm(
}
if (data_transfer_layersmapping_generate(
- &lay_map, ob_src, ob_dst, dm_src, dm_dst, me_dst, ME_EDGE,
+ &lay_map, ob_src, ob_dst, me_src, me_dst, ME_EDGE,
cddata_type, mix_mode, mix_factor, weights[EDATA],
num_edges_dst, use_create, use_delete, fromlayers, tolayers, space_transform))
{
@@ -1310,21 +1266,21 @@ bool BKE_object_data_transfer_dm(
}
}
if (DT_DATATYPE_IS_LOOP(dtdata_type)) {
- MVert *verts_dst = dm_dst ? dm_dst->getVertArray(dm_dst) : me_dst->mvert;
- const int num_verts_dst = dm_dst ? dm_dst->getNumVerts(dm_dst) : me_dst->totvert;
- MEdge *edges_dst = dm_dst ? dm_dst->getEdgeArray(dm_dst) : me_dst->medge;
- const int num_edges_dst = dm_dst ? dm_dst->getNumEdges(dm_dst) : me_dst->totedge;
- MPoly *polys_dst = dm_dst ? dm_dst->getPolyArray(dm_dst) : me_dst->mpoly;
- const int num_polys_dst = dm_dst ? dm_dst->getNumPolys(dm_dst) : me_dst->totpoly;
- MLoop *loops_dst = dm_dst ? dm_dst->getLoopArray(dm_dst) : me_dst->mloop;
- const int num_loops_dst = dm_dst ? dm_dst->getNumLoops(dm_dst) : me_dst->totloop;
- CustomData *pdata_dst = dm_dst ? dm_dst->getPolyDataLayout(dm_dst) : &me_dst->pdata;
- CustomData *ldata_dst = dm_dst ? dm_dst->getLoopDataLayout(dm_dst) : &me_dst->ldata;
+ MVert *verts_dst = me_dst->mvert;
+ const int num_verts_dst = me_dst->totvert;
+ MEdge *edges_dst = me_dst->medge;
+ const int num_edges_dst = me_dst->totedge;
+ MPoly *polys_dst = me_dst->mpoly;
+ const int num_polys_dst = me_dst->totpoly;
+ MLoop *loops_dst = me_dst->mloop;
+ const int num_loops_dst = me_dst->totloop;
+ CustomData *pdata_dst = &me_dst->pdata;
+ CustomData *ldata_dst = &me_dst->ldata;
MeshRemapIslandsCalc island_callback = data_transfer_get_loop_islands_generator(cddata_type);
if (!geom_map_init[LDATA]) {
- const int num_loops_src = dm_src->getNumLoops(dm_src);
+ const int num_loops_src = me_src->totloop;
if ((map_loop_mode == MREMAP_MODE_TOPOLOGY) && (num_loops_dst != num_loops_src)) {
BKE_report(reports, RPT_ERROR,
@@ -1332,7 +1288,7 @@ bool BKE_object_data_transfer_dm(
"'Topology' mapping cannot be used in this case");
continue;
}
- if ((map_loop_mode & MREMAP_USE_EDGE) && (dm_src->getNumEdges(dm_src) == 0)) {
+ if ((map_loop_mode & MREMAP_USE_EDGE) && (me_src->totedge == 0)) {
BKE_report(reports, RPT_ERROR,
"Source mesh doesn't have any edges, "
"None of the 'Edge' mappings can be used in this case");
@@ -1344,13 +1300,13 @@ bool BKE_object_data_transfer_dm(
continue;
}
- BKE_mesh_remap_calc_loops_from_dm(
+ BKE_mesh_remap_calc_loops_from_mesh(
map_loop_mode, space_transform, max_distance, ray_radius,
verts_dst, num_verts_dst, edges_dst, num_edges_dst,
loops_dst, num_loops_dst, polys_dst, num_polys_dst,
ldata_dst, pdata_dst,
(me_dst->flag & ME_AUTOSMOOTH) != 0, me_dst->smoothresh, dirty_nors_dst,
- dm_src, (me_src->flag & ME_AUTOSMOOTH) != 0, me_src->smoothresh,
+ me_src,
island_callback, islands_handling_precision, &geom_map[LDATA]);
geom_map_init[LDATA] = true;
}
@@ -1363,7 +1319,7 @@ bool BKE_object_data_transfer_dm(
}
if (data_transfer_layersmapping_generate(
- &lay_map, ob_src, ob_dst, dm_src, dm_dst, me_dst, ME_LOOP,
+ &lay_map, ob_src, ob_dst, me_src, me_dst, ME_LOOP,
cddata_type, mix_mode, mix_factor, weights[LDATA],
num_loops_dst, use_create, use_delete, fromlayers, tolayers, space_transform))
{
@@ -1379,16 +1335,16 @@ bool BKE_object_data_transfer_dm(
}
}
if (DT_DATATYPE_IS_POLY(dtdata_type)) {
- MVert *verts_dst = dm_dst ? dm_dst->getVertArray(dm_dst) : me_dst->mvert;
- const int num_verts_dst = dm_dst ? dm_dst->getNumVerts(dm_dst) : me_dst->totvert;
- MPoly *polys_dst = dm_dst ? dm_dst->getPolyArray(dm_dst) : me_dst->mpoly;
- const int num_polys_dst = dm_dst ? dm_dst->getNumPolys(dm_dst) : me_dst->totpoly;
- MLoop *loops_dst = dm_dst ? dm_dst->getLoopArray(dm_dst) : me_dst->mloop;
- const int num_loops_dst = dm_dst ? dm_dst->getNumLoops(dm_dst) : me_dst->totloop;
- CustomData *pdata_dst = dm_dst ? dm_dst->getPolyDataLayout(dm_dst) : &me_dst->pdata;
+ MVert *verts_dst = me_dst->mvert;
+ const int num_verts_dst = me_dst->totvert;
+ MPoly *polys_dst = me_dst->mpoly;
+ const int num_polys_dst = me_dst->totpoly;
+ MLoop *loops_dst = me_dst->mloop;
+ const int num_loops_dst = me_dst->totloop;
+ CustomData *pdata_dst = &me_dst->pdata;
if (!geom_map_init[PDATA]) {
- const int num_polys_src = dm_src->getNumPolys(dm_src);
+ const int num_polys_src = me_src->totpoly;
if ((map_poly_mode == MREMAP_MODE_TOPOLOGY) && (num_polys_dst != num_polys_src)) {
BKE_report(reports, RPT_ERROR,
@@ -1396,7 +1352,7 @@ bool BKE_object_data_transfer_dm(
"'Topology' mapping cannot be used in this case");
continue;
}
- if ((map_poly_mode & MREMAP_USE_EDGE) && (dm_src->getNumEdges(dm_src) == 0)) {
+ if ((map_poly_mode & MREMAP_USE_EDGE) && (me_src->totedge == 0)) {
BKE_report(reports, RPT_ERROR,
"Source mesh doesn't have any edges, "
"None of the 'Edge' mappings can be used in this case");
@@ -1408,11 +1364,11 @@ bool BKE_object_data_transfer_dm(
continue;
}
- BKE_mesh_remap_calc_polys_from_dm(
+ BKE_mesh_remap_calc_polys_from_mesh(
map_poly_mode, space_transform, max_distance, ray_radius,
verts_dst, num_verts_dst, loops_dst, num_loops_dst,
polys_dst, num_polys_dst, pdata_dst, dirty_nors_dst,
- dm_src, &geom_map[PDATA]);
+ me_src, &geom_map[PDATA]);
geom_map_init[PDATA] = true;
}
@@ -1424,7 +1380,7 @@ bool BKE_object_data_transfer_dm(
}
if (data_transfer_layersmapping_generate(
- &lay_map, ob_src, ob_dst, dm_src, dm_dst, me_dst, ME_POLY,
+ &lay_map, ob_src, ob_dst, me_src, me_dst, ME_POLY,
cddata_type, mix_mode, mix_factor, weights[PDATA],
num_polys_dst, use_create, use_delete, fromlayers, tolayers, space_transform))
{
@@ -1440,14 +1396,13 @@ bool BKE_object_data_transfer_dm(
}
}
- data_transfer_dtdata_type_postprocess(ob_src, ob_dst, dm_src, dm_dst, me_dst, dtdata_type, changed);
+ data_transfer_dtdata_type_postprocess(ob_src, ob_dst, me_src, me_dst, dtdata_type, changed);
}
for (i = 0; i < DATAMAX; i++) {
BKE_mesh_remap_free(&geom_map[i]);
MEM_SAFE_FREE(weights[i]);
}
- dm_src->release(dm_src);
return changed;
@@ -1467,7 +1422,7 @@ bool BKE_object_data_transfer_mesh(
const int mix_mode, const float mix_factor, const char *vgroup_name, const bool invert_vgroup,
ReportList *reports)
{
- return BKE_object_data_transfer_dm(
+ return BKE_object_data_transfer_ex(
depsgraph, scene, ob_src, ob_dst, NULL, data_types, use_create,
map_vert_mode, map_edge_mode, map_loop_mode, map_poly_mode,
space_transform, auto_transform,