2015-01-09 21:19:12 +01:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2014 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): None yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file blender/modifiers/intern/MOD_datatransfer.c
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
|
|
|
#include "BKE_customdata.h"
|
2015-02-15 18:46:46 +01:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
2015-01-12 12:03:28 +01:00
|
|
|
#include "BKE_data_transfer.h"
|
2015-01-09 21:19:12 +01:00
|
|
|
#include "BKE_library.h"
|
2015-10-08 14:21:11 +02:00
|
|
|
#include "BKE_library_query.h"
|
2015-01-09 21:19:12 +01:00
|
|
|
#include "BKE_mesh_mapping.h"
|
|
|
|
#include "BKE_mesh_remap.h"
|
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_report.h"
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
#include "MOD_util.h"
|
|
|
|
|
|
|
|
/**************************************
|
|
|
|
* Modifiers functions. *
|
|
|
|
**************************************/
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
|
|
|
DataTransferModifierData *dtmd = (DataTransferModifierData *) md;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dtmd->ob_source = NULL;
|
|
|
|
dtmd->data_types = 0;
|
|
|
|
|
|
|
|
dtmd->vmap_mode = MREMAP_MODE_VERT_NEAREST;
|
|
|
|
dtmd->emap_mode = MREMAP_MODE_EDGE_NEAREST;
|
|
|
|
dtmd->lmap_mode = MREMAP_MODE_LOOP_NEAREST_POLYNOR;
|
|
|
|
dtmd->pmap_mode = MREMAP_MODE_POLY_NEAREST;
|
|
|
|
|
|
|
|
dtmd->map_max_distance = 1.0f;
|
|
|
|
dtmd->map_ray_radius = 0.0f;
|
|
|
|
|
|
|
|
for (i = 0; i < DT_MULTILAYER_INDEX_MAX; i++) {
|
|
|
|
dtmd->layers_select_src[i] = DT_LAYERS_ALL_SRC;
|
|
|
|
dtmd->layers_select_dst[i] = DT_LAYERS_NAME_DST;
|
|
|
|
}
|
|
|
|
|
|
|
|
dtmd->mix_mode = CDT_MIX_TRANSFER;
|
|
|
|
dtmd->mix_factor = 1.0f;
|
|
|
|
dtmd->defgrp_name[0] = '\0';
|
|
|
|
|
|
|
|
dtmd->flags = MOD_DATATRANSFER_OBSRC_TRANSFORM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
|
|
|
|
{
|
|
|
|
DataTransferModifierData *dtmd = (DataTransferModifierData *) md;
|
|
|
|
CustomDataMask dataMask = 0;
|
|
|
|
|
|
|
|
if (dtmd->defgrp_name[0]) {
|
|
|
|
/* We need vertex groups! */
|
|
|
|
dataMask |= CD_MASK_MDEFORMVERT;
|
|
|
|
}
|
|
|
|
|
|
|
|
dataMask |= BKE_object_data_transfer_dttypes_to_cdmask(dtmd->data_types);
|
|
|
|
|
|
|
|
return dataMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool dependsOnNormals(ModifierData *md)
|
|
|
|
{
|
|
|
|
DataTransferModifierData *dtmd = (DataTransferModifierData *) md;
|
|
|
|
int item_types = BKE_object_data_transfer_get_dttypes_item_types(dtmd->data_types);
|
|
|
|
|
|
|
|
if ((item_types & ME_VERT) && (dtmd->vmap_mode & (MREMAP_USE_NORPROJ | MREMAP_USE_NORMAL))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((item_types & ME_EDGE) && (dtmd->emap_mode & (MREMAP_USE_NORPROJ | MREMAP_USE_NORMAL))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((item_types & ME_LOOP) && (dtmd->lmap_mode & (MREMAP_USE_NORPROJ | MREMAP_USE_NORMAL))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((item_types & ME_POLY) && (dtmd->pmap_mode & (MREMAP_USE_NORPROJ | MREMAP_USE_NORMAL))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-05 15:57:10 +02:00
|
|
|
static void foreachObjectLink(
|
|
|
|
ModifierData *md, Object *ob,
|
|
|
|
ObjectWalkFunc walk, void *userData)
|
2015-01-09 21:19:12 +01:00
|
|
|
{
|
|
|
|
DataTransferModifierData *dtmd = (DataTransferModifierData *) md;
|
2017-01-31 09:47:59 +01:00
|
|
|
walk(userData, ob, &dtmd->ob_source, IDWALK_CB_NOP);
|
2015-01-09 21:19:12 +01:00
|
|
|
}
|
|
|
|
|
2018-02-22 12:54:06 +01:00
|
|
|
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
{
|
|
|
|
DataTransferModifierData *dtmd = (DataTransferModifierData *) md;
|
|
|
|
if (dtmd->ob_source != NULL) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, dtmd->ob_source, DEG_OB_COMP_GEOMETRY, "DataTransfer Modifier");
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-21 17:54:12 +02:00
|
|
|
static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, int UNUSED(useRenderParams))
|
2015-01-09 21:19:12 +01:00
|
|
|
{
|
|
|
|
DataTransferModifierData *dtmd = (DataTransferModifierData *) md;
|
|
|
|
/* If no source object, bypass. */
|
|
|
|
return (dtmd->ob_source == NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HIGH_POLY_WARNING 10000
|
2015-02-15 18:46:46 +01:00
|
|
|
#define DT_TYPES_AFFECT_MESH ( \
|
|
|
|
DT_TYPE_BWEIGHT_VERT | \
|
|
|
|
DT_TYPE_BWEIGHT_EDGE | DT_TYPE_CREASE | DT_TYPE_SHARP_EDGE | \
|
|
|
|
DT_TYPE_LNOR | \
|
|
|
|
DT_TYPE_SHARP_FACE \
|
|
|
|
)
|
2015-01-09 21:19:12 +01:00
|
|
|
|
2018-06-21 14:39:28 +02:00
|
|
|
static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *me_mod)
|
2015-01-09 21:19:12 +01:00
|
|
|
{
|
|
|
|
DataTransferModifierData *dtmd = (DataTransferModifierData *) md;
|
2018-06-21 14:39:28 +02:00
|
|
|
Mesh *result = me_mod;
|
2015-01-09 21:19:12 +01:00
|
|
|
ReportList reports;
|
|
|
|
|
2015-02-15 18:46:46 +01:00
|
|
|
/* Only used to check wehther we are operating on org data or not... */
|
2018-05-01 17:33:04 +02:00
|
|
|
Mesh *me = ctx->object->data;
|
2015-02-15 18:46:46 +01:00
|
|
|
|
2015-01-09 21:19:12 +01:00
|
|
|
const bool invert_vgroup = (dtmd->flags & MOD_DATATRANSFER_INVERT_VGROUP) != 0;
|
|
|
|
|
|
|
|
const float max_dist = (dtmd->flags & MOD_DATATRANSFER_MAP_MAXDIST) ? dtmd->map_max_distance : FLT_MAX;
|
|
|
|
|
|
|
|
SpaceTransform space_transform_data;
|
|
|
|
SpaceTransform *space_transform = (dtmd->flags & MOD_DATATRANSFER_OBSRC_TRANSFORM) ? &space_transform_data : NULL;
|
|
|
|
|
|
|
|
if (space_transform) {
|
2018-05-01 17:33:04 +02:00
|
|
|
BLI_SPACE_TRANSFORM_SETUP(space_transform, ctx->object, dtmd->ob_source);
|
2015-01-09 21:19:12 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 14:39:28 +02:00
|
|
|
if ((result == me_mod || (me->mvert == result->mvert) || (me->medge == result->medge)) &&
|
|
|
|
(dtmd->data_types & DT_TYPES_AFFECT_MESH))
|
|
|
|
{
|
2015-02-15 18:46:46 +01:00
|
|
|
/* We need to duplicate data here, otherwise setting custom normals, edges' shaprness, etc., could
|
|
|
|
* modify org mesh, see T43671. */
|
2018-06-21 14:39:28 +02:00
|
|
|
BKE_id_copy_ex(
|
|
|
|
NULL, &me_mod->id, (ID **)&result,
|
|
|
|
LIB_ID_CREATE_NO_MAIN |
|
|
|
|
LIB_ID_CREATE_NO_USER_REFCOUNT |
|
|
|
|
LIB_ID_CREATE_NO_DEG_TAG |
|
|
|
|
LIB_ID_COPY_NO_PREVIEW,
|
|
|
|
false);
|
2015-02-15 18:46:46 +01:00
|
|
|
}
|
|
|
|
|
2015-01-09 21:19:12 +01:00
|
|
|
BKE_reports_init(&reports, RPT_STORE);
|
|
|
|
|
|
|
|
/* Note: no islands precision for now here. */
|
2018-06-21 15:32:01 +02:00
|
|
|
BKE_object_data_transfer_ex(ctx->depsgraph, md->scene, dtmd->ob_source, ctx->object, result, dtmd->data_types, false,
|
2015-01-09 21:19:12 +01:00
|
|
|
dtmd->vmap_mode, dtmd->emap_mode, dtmd->lmap_mode, dtmd->pmap_mode,
|
2015-07-13 18:00:08 +02:00
|
|
|
space_transform, false, max_dist, dtmd->map_ray_radius, 0.0f,
|
2015-01-09 21:19:12 +01:00
|
|
|
dtmd->layers_select_src, dtmd->layers_select_dst,
|
|
|
|
dtmd->mix_mode, dtmd->mix_factor, dtmd->defgrp_name, invert_vgroup, &reports);
|
|
|
|
|
|
|
|
if (BKE_reports_contain(&reports, RPT_ERROR)) {
|
|
|
|
modifier_setError(md, "%s", BKE_reports_string(&reports, RPT_ERROR));
|
|
|
|
}
|
2017-01-27 19:06:10 +01:00
|
|
|
else if ((dtmd->data_types & DT_TYPE_LNOR) && !(me->flag & ME_AUTOSMOOTH)) {
|
|
|
|
modifier_setError((ModifierData *)dtmd, "Enable 'Auto Smooth' option in mesh settings");
|
|
|
|
}
|
2018-06-21 14:39:28 +02:00
|
|
|
else if (result->totvert > HIGH_POLY_WARNING || ((Mesh *)(dtmd->ob_source->data))->totvert > HIGH_POLY_WARNING) {
|
2015-01-09 21:19:12 +01:00
|
|
|
modifier_setError(md, "You are using a rather high poly as source or destination, computation might be slow");
|
|
|
|
}
|
|
|
|
|
2018-06-21 14:39:28 +02:00
|
|
|
return result;
|
2015-01-09 21:19:12 +01:00
|
|
|
}
|
|
|
|
|
2015-02-15 18:46:46 +01:00
|
|
|
#undef HIGH_POLY_WARNING
|
|
|
|
#undef DT_TYPES_AFFECT_MESH
|
2015-01-09 21:19:12 +01:00
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_DataTransfer = {
|
|
|
|
/* name */ "DataTransfer",
|
|
|
|
/* structName */ "DataTransferModifierData",
|
|
|
|
/* structSize */ sizeof(DataTransferModifierData),
|
|
|
|
/* type */ eModifierTypeType_NonGeometrical,
|
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
|
|
|
eModifierTypeFlag_SupportsMapping |
|
|
|
|
eModifierTypeFlag_SupportsEditmode |
|
|
|
|
eModifierTypeFlag_UsesPreview,
|
|
|
|
|
2018-05-08 15:04:10 +02:00
|
|
|
/* copyData */ modifier_copyData_generic,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
|
|
|
/* deformVerts_DM */ NULL,
|
|
|
|
/* deformMatrices_DM */ NULL,
|
|
|
|
/* deformVertsEM_DM */ NULL,
|
|
|
|
/* deformMatricesEM_DM*/NULL,
|
2018-06-21 14:39:28 +02:00
|
|
|
/* applyModifier_DM */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
/* applyModifierEM_DM */NULL,
|
|
|
|
|
2015-01-09 21:19:12 +01:00
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
2018-06-21 14:39:28 +02:00
|
|
|
/* applyModifier */ applyModifier,
|
2015-01-09 21:19:12 +01:00
|
|
|
/* applyModifierEM */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2015-01-09 21:19:12 +01:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
|
|
|
/* freeData */ NULL,
|
|
|
|
/* isDisabled */ isDisabled,
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
/* updateDepsgraph */ updateDepsgraph,
|
2015-01-09 21:19:12 +01:00
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ dependsOnNormals,
|
|
|
|
/* foreachObjectLink */ foreachObjectLink,
|
2015-10-05 15:57:10 +02:00
|
|
|
/* foreachIDLink */ NULL,
|
2015-01-09 21:19:12 +01:00
|
|
|
/* foreachTexLink */ NULL,
|
|
|
|
};
|