2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* 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) 2005 by the Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-06 15:42:22 +11:00
|
|
|
/** \file \ingroup modifiers
|
2011-02-25 13:57:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2018-05-08 12:00:38 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2015-08-12 18:21:41 +02:00
|
|
|
#include "BLI_math.h"
|
2017-02-06 14:21:29 +01:00
|
|
|
#include "BLI_task.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-05-08 12:00:38 +02:00
|
|
|
#include "BKE_customdata.h"
|
|
|
|
#include "BKE_editmesh.h"
|
2013-06-10 14:04:03 +00:00
|
|
|
#include "BKE_library.h"
|
2015-10-08 14:21:11 +02:00
|
|
|
#include "BKE_library_query.h"
|
2017-02-06 12:33:37 +01:00
|
|
|
#include "BKE_image.h"
|
2015-08-12 18:21:41 +02:00
|
|
|
#include "BKE_mesh.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_texture.h"
|
|
|
|
#include "BKE_deform.h"
|
2016-10-23 14:04:27 +02:00
|
|
|
#include "BKE_object.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-05-23 15:52:35 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-06-22 15:03:42 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2018-05-23 15:52:35 +02:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "MOD_util.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
#include "RE_shader_ext.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Displace */
|
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
DisplaceModifierData *dmd = (DisplaceModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
dmd->texture = NULL;
|
|
|
|
dmd->strength = 1;
|
|
|
|
dmd->direction = MOD_DISP_DIR_NOR;
|
|
|
|
dmd->midlevel = 0.5;
|
2016-10-23 14:04:27 +02:00
|
|
|
dmd->space = MOD_DISP_SPACE_LOCAL;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
DisplaceModifierData *dmd = (DisplaceModifierData *)md;
|
|
|
|
CustomDataMask dataMask = 0;
|
|
|
|
|
|
|
|
/* ask for vertexgroups if we need them */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (dmd->defgrp_name[0]) dataMask |= CD_MASK_MDEFORMVERT;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* ask for UV coordinates if we need them */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (dmd->texmapping == MOD_DISP_MAP_UV) dataMask |= CD_MASK_MTFACE;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2015-08-12 18:21:41 +02:00
|
|
|
if (dmd->direction == MOD_DISP_DIR_CLNOR) {
|
|
|
|
dataMask |= CD_MASK_CUSTOMLOOPNORMAL;
|
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
return dataMask;
|
|
|
|
}
|
|
|
|
|
2013-06-02 03:59:19 +00:00
|
|
|
static bool dependsOnTime(ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
DisplaceModifierData *dmd = (DisplaceModifierData *)md;
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (dmd->texture) {
|
2010-04-11 22:12:30 +00:00
|
|
|
return BKE_texture_dependsOnTime(dmd->texture);
|
|
|
|
}
|
2012-03-06 18:40:15 +00:00
|
|
|
else {
|
2013-06-02 03:59:19 +00:00
|
|
|
return false;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 03:59:19 +00:00
|
|
|
static bool dependsOnNormals(ModifierData *md)
|
2010-09-30 10:51:36 +00:00
|
|
|
{
|
|
|
|
DisplaceModifierData *dmd = (DisplaceModifierData *)md;
|
2015-08-12 18:21:41 +02:00
|
|
|
return ELEM(dmd->direction, MOD_DISP_DIR_NOR, MOD_DISP_DIR_CLNOR);
|
2010-09-30 10:51:36 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void foreachObjectLink(
|
|
|
|
ModifierData *md, Object *ob,
|
|
|
|
ObjectWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
DisplaceModifierData *dmd = (DisplaceModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2017-01-31 09:47:59 +01:00
|
|
|
walk(userData, ob, &dmd->map_object, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void foreachIDLink(
|
|
|
|
ModifierData *md, Object *ob,
|
|
|
|
IDWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
DisplaceModifierData *dmd = (DisplaceModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2017-01-31 09:47:59 +01:00
|
|
|
walk(userData, ob, (ID **)&dmd->texture, IDWALK_CB_USER);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
foreachObjectLink(md, ob, (ObjectWalkFunc)walk, userData);
|
|
|
|
}
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void foreachTexLink(
|
|
|
|
ModifierData *md, Object *ob,
|
|
|
|
TexWalkFunc walk, void *userData)
|
2011-08-12 18:11:22 +00:00
|
|
|
{
|
|
|
|
walk(userData, ob, md, "texture");
|
|
|
|
}
|
|
|
|
|
2018-07-10 12:14:08 +02:00
|
|
|
static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
DisplaceModifierData *dmd = (DisplaceModifierData *) md;
|
2012-08-14 17:36:41 +00:00
|
|
|
return ((!dmd->texture && dmd->direction == MOD_DISP_DIR_RGB_XYZ) || dmd->strength == 0.0f);
|
2010-04-11 22:12:30 +00: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
|
|
|
{
|
|
|
|
DisplaceModifierData *dmd = (DisplaceModifierData *)md;
|
|
|
|
if (dmd->map_object != NULL && dmd->texmapping == MOD_DISP_MAP_OBJECT) {
|
2019-02-12 12:01:17 +01:00
|
|
|
DEG_add_modifier_to_transform_relation(ctx->node, "Displace Modifier");
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, dmd->map_object, DEG_OB_COMP_TRANSFORM, "Displace 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
|
|
|
}
|
2016-10-23 14:04:27 +02:00
|
|
|
if (dmd->texmapping == MOD_DISP_MAP_GLOBAL ||
|
|
|
|
(ELEM(dmd->direction, MOD_DISP_DIR_X, MOD_DISP_DIR_Y, MOD_DISP_DIR_Z, MOD_DISP_DIR_RGB_XYZ) &&
|
|
|
|
dmd->space == MOD_DISP_SPACE_GLOBAL))
|
|
|
|
{
|
2019-02-12 12:01:17 +01:00
|
|
|
DEG_add_modifier_to_transform_relation(ctx->node, "Displace 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-12-05 17:35:13 +01:00
|
|
|
if (dmd->texture != NULL) {
|
|
|
|
DEG_add_generic_id_relation(ctx->node, &dmd->texture->id, "Displace 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
|
|
|
}
|
|
|
|
|
2017-02-06 14:21:29 +01:00
|
|
|
typedef struct DisplaceUserdata {
|
|
|
|
/*const*/ DisplaceModifierData *dmd;
|
2018-06-22 15:03:42 +02:00
|
|
|
struct Scene *scene;
|
2017-02-06 14:21:29 +01:00
|
|
|
struct ImagePool *pool;
|
|
|
|
MDeformVert *dvert;
|
|
|
|
float weight;
|
|
|
|
int defgrp_index;
|
|
|
|
int direction;
|
|
|
|
bool use_global_direction;
|
2018-12-07 15:45:53 +01:00
|
|
|
Tex *tex_target;
|
2017-02-06 14:21:29 +01:00
|
|
|
float (*tex_co)[3];
|
|
|
|
float (*vertexCos)[3];
|
|
|
|
float local_mat[4][4];
|
|
|
|
MVert *mvert;
|
|
|
|
float (*vert_clnors)[3];
|
|
|
|
} DisplaceUserdata;
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void displaceModifier_do_task(
|
|
|
|
void *__restrict userdata,
|
|
|
|
const int iter,
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2017-02-06 14:21:29 +01:00
|
|
|
{
|
|
|
|
DisplaceUserdata *data = (DisplaceUserdata *)userdata;
|
|
|
|
DisplaceModifierData *dmd = data->dmd;
|
|
|
|
MDeformVert *dvert = data->dvert;
|
|
|
|
float weight = data->weight;
|
|
|
|
int defgrp_index = data->defgrp_index;
|
|
|
|
int direction = data->direction;
|
|
|
|
bool use_global_direction = data->use_global_direction;
|
|
|
|
float (*tex_co)[3] = data->tex_co;
|
|
|
|
float (*vertexCos)[3] = data->vertexCos;
|
|
|
|
MVert *mvert = data->mvert;
|
|
|
|
float (*vert_clnors)[3] = data->vert_clnors;
|
|
|
|
|
|
|
|
const float delta_fixed = 1.0f - dmd->midlevel; /* when no texture is used, we fallback to white */
|
|
|
|
|
|
|
|
TexResult texres;
|
|
|
|
float strength = dmd->strength;
|
|
|
|
float delta;
|
|
|
|
float local_vec[3];
|
|
|
|
|
|
|
|
if (dvert) {
|
|
|
|
weight = defvert_find_weight(dvert + iter, defgrp_index);
|
|
|
|
if (weight == 0.0f) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
if (data->tex_target) {
|
2017-02-06 14:21:29 +01:00
|
|
|
texres.nor = NULL;
|
2018-12-07 15:45:53 +01:00
|
|
|
BKE_texture_get_value_ex(data->scene, data->tex_target, tex_co[iter], &texres, data->pool, false);
|
2017-02-06 14:21:29 +01:00
|
|
|
delta = texres.tin - dmd->midlevel;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delta = delta_fixed; /* (1.0f - dmd->midlevel) */ /* never changes */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dvert) {
|
|
|
|
strength *= weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
delta *= strength;
|
|
|
|
CLAMP(delta, -10000, 10000);
|
|
|
|
|
|
|
|
switch (direction) {
|
|
|
|
case MOD_DISP_DIR_X:
|
|
|
|
if (use_global_direction) {
|
|
|
|
vertexCos[iter][0] += delta * data->local_mat[0][0];
|
|
|
|
vertexCos[iter][1] += delta * data->local_mat[1][0];
|
|
|
|
vertexCos[iter][2] += delta * data->local_mat[2][0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vertexCos[iter][0] += delta;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MOD_DISP_DIR_Y:
|
|
|
|
if (use_global_direction) {
|
|
|
|
vertexCos[iter][0] += delta * data->local_mat[0][1];
|
|
|
|
vertexCos[iter][1] += delta * data->local_mat[1][1];
|
|
|
|
vertexCos[iter][2] += delta * data->local_mat[2][1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vertexCos[iter][1] += delta;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MOD_DISP_DIR_Z:
|
|
|
|
if (use_global_direction) {
|
|
|
|
vertexCos[iter][0] += delta * data->local_mat[0][2];
|
|
|
|
vertexCos[iter][1] += delta * data->local_mat[1][2];
|
|
|
|
vertexCos[iter][2] += delta * data->local_mat[2][2];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vertexCos[iter][2] += delta;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MOD_DISP_DIR_RGB_XYZ:
|
|
|
|
local_vec[0] = texres.tr - dmd->midlevel;
|
|
|
|
local_vec[1] = texres.tg - dmd->midlevel;
|
|
|
|
local_vec[2] = texres.tb - dmd->midlevel;
|
|
|
|
if (use_global_direction) {
|
|
|
|
mul_transposed_mat3_m4_v3(data->local_mat, local_vec);
|
|
|
|
}
|
|
|
|
mul_v3_fl(local_vec, strength);
|
|
|
|
add_v3_v3(vertexCos[iter], local_vec);
|
|
|
|
break;
|
|
|
|
case MOD_DISP_DIR_NOR:
|
|
|
|
vertexCos[iter][0] += delta * (mvert[iter].no[0] / 32767.0f);
|
|
|
|
vertexCos[iter][1] += delta * (mvert[iter].no[1] / 32767.0f);
|
|
|
|
vertexCos[iter][2] += delta * (mvert[iter].no[2] / 32767.0f);
|
|
|
|
break;
|
|
|
|
case MOD_DISP_DIR_CLNOR:
|
|
|
|
madd_v3_v3fl(vertexCos[iter], vert_clnors[iter], delta);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
static void displaceModifier_do(
|
2018-05-23 15:52:35 +02:00
|
|
|
DisplaceModifierData *dmd, const ModifierEvalContext *ctx,
|
2018-05-08 12:00:38 +02:00
|
|
|
Mesh *mesh, float (*vertexCos)[3], const int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-23 15:52:35 +02:00
|
|
|
Object *ob = ctx->object;
|
2010-04-11 22:12:30 +00:00
|
|
|
MVert *mvert;
|
2011-07-11 09:15:20 +00:00
|
|
|
MDeformVert *dvert;
|
2015-08-12 18:21:41 +02:00
|
|
|
int direction = dmd->direction;
|
2010-04-11 22:12:30 +00:00
|
|
|
int defgrp_index;
|
|
|
|
float (*tex_co)[3];
|
2012-05-06 13:38:33 +00:00
|
|
|
float weight = 1.0f; /* init value unused but some compilers may complain */
|
2015-08-12 18:21:41 +02:00
|
|
|
float (*vert_clnors)[3] = NULL;
|
2017-02-18 23:52:31 +01:00
|
|
|
float local_mat[4][4] = {{0}};
|
2016-10-23 14:04:27 +02:00
|
|
|
const bool use_global_direction = dmd->space == MOD_DISP_SPACE_GLOBAL;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
if (dmd->texture == NULL && dmd->direction == MOD_DISP_DIR_RGB_XYZ) return;
|
2012-03-24 06:24:53 +00:00
|
|
|
if (dmd->strength == 0.0f) return;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-05-08 12:00:38 +02:00
|
|
|
mvert = mesh->mvert;
|
2018-06-29 19:02:19 +02:00
|
|
|
MOD_get_vgroup(ob, mesh, dmd->defgrp_name, &dvert, &defgrp_index);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
Tex *tex_target = (Tex *)DEG_get_evaluated_id(ctx->depsgraph, &dmd->texture->id);
|
|
|
|
if (tex_target != NULL) {
|
2018-01-14 22:14:20 +01:00
|
|
|
tex_co = MEM_calloc_arrayN((size_t)numVerts, sizeof(*tex_co),
|
2012-08-26 11:35:43 +00:00
|
|
|
"displaceModifier_do tex_co");
|
2018-12-07 15:45:53 +01:00
|
|
|
MOD_get_texture_coords((MappingInfoModifierData *)dmd, ctx, ob, mesh, vertexCos, tex_co);
|
2011-12-29 04:04:27 +00:00
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
MOD_init_texture((MappingInfoModifierData *)dmd, ctx);
|
2012-08-18 11:48:35 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
tex_co = NULL;
|
|
|
|
}
|
2012-04-10 14:11:45 +00:00
|
|
|
|
2015-08-12 18:21:41 +02:00
|
|
|
if (direction == MOD_DISP_DIR_CLNOR) {
|
2018-05-08 12:00:38 +02:00
|
|
|
CustomData *ldata = &mesh->ldata;
|
2015-08-12 18:21:41 +02:00
|
|
|
|
|
|
|
if (CustomData_has_layer(ldata, CD_CUSTOMLOOPNORMAL)) {
|
|
|
|
float (*clnors)[3] = NULL;
|
|
|
|
|
2018-05-08 12:00:38 +02:00
|
|
|
if ((mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) || !CustomData_has_layer(ldata, CD_NORMAL)) {
|
|
|
|
BKE_mesh_calc_normals_split(mesh);
|
2015-08-12 18:21:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clnors = CustomData_get_layer(ldata, CD_NORMAL);
|
2018-01-14 22:14:20 +01:00
|
|
|
vert_clnors = MEM_malloc_arrayN(numVerts, sizeof(*vert_clnors), __func__);
|
2018-05-08 12:00:38 +02:00
|
|
|
BKE_mesh_normals_loop_to_vertex(numVerts, mesh->mloop, mesh->totloop,
|
2015-09-04 01:04:37 +02:00
|
|
|
(const float (*)[3])clnors, vert_clnors);
|
2015-08-12 18:21:41 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
direction = MOD_DISP_DIR_NOR;
|
|
|
|
}
|
|
|
|
}
|
2016-10-23 14:04:27 +02:00
|
|
|
else if (ELEM(direction, MOD_DISP_DIR_X, MOD_DISP_DIR_Y, MOD_DISP_DIR_Z, MOD_DISP_DIR_RGB_XYZ) &&
|
|
|
|
use_global_direction)
|
|
|
|
{
|
|
|
|
copy_m4_m4(local_mat, ob->obmat);
|
|
|
|
}
|
2015-08-12 18:21:41 +02:00
|
|
|
|
2017-02-06 14:21:29 +01:00
|
|
|
DisplaceUserdata data = {NULL};
|
2018-06-22 15:03:42 +02:00
|
|
|
data.scene = DEG_get_evaluated_scene(ctx->depsgraph);
|
2017-02-06 14:21:29 +01:00
|
|
|
data.dmd = dmd;
|
|
|
|
data.dvert = dvert;
|
|
|
|
data.weight = weight;
|
|
|
|
data.defgrp_index = defgrp_index;
|
|
|
|
data.direction = direction;
|
|
|
|
data.use_global_direction = use_global_direction;
|
2018-12-07 15:45:53 +01:00
|
|
|
data.tex_target = tex_target;
|
2017-02-06 14:21:29 +01:00
|
|
|
data.tex_co = tex_co;
|
|
|
|
data.vertexCos = vertexCos;
|
|
|
|
copy_m4_m4(data.local_mat, local_mat);
|
|
|
|
data.mvert = mvert;
|
|
|
|
data.vert_clnors = vert_clnors;
|
2018-12-07 15:45:53 +01:00
|
|
|
if (tex_target != NULL) {
|
2017-02-06 14:21:29 +01:00
|
|
|
data.pool = BKE_image_pool_new();
|
2018-12-07 15:45:53 +01:00
|
|
|
BKE_texture_fetch_images_for_pool(tex_target, data.pool);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
settings.use_threading = (numVerts > 512);
|
|
|
|
BLI_task_parallel_range(0, numVerts,
|
|
|
|
&data,
|
|
|
|
displaceModifier_do_task,
|
|
|
|
&settings);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2017-02-06 14:21:29 +01:00
|
|
|
if (data.pool != NULL) {
|
|
|
|
BKE_image_pool_free(data.pool);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2012-08-18 11:48:35 +00:00
|
|
|
if (tex_co) {
|
|
|
|
MEM_freeN(tex_co);
|
|
|
|
}
|
2015-08-12 18:21:41 +02:00
|
|
|
|
|
|
|
if (vert_clnors) {
|
|
|
|
MEM_freeN(vert_clnors);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-08 12:00:38 +02:00
|
|
|
static void deformVerts(
|
|
|
|
ModifierData *md,
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
Mesh *mesh,
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-11-27 17:21:16 +01:00
|
|
|
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
|
2018-05-08 12:00:38 +02:00
|
|
|
|
2018-05-23 15:52:35 +02:00
|
|
|
displaceModifier_do((DisplaceModifierData *)md, ctx, mesh_src, vertexCos, numVerts);
|
2018-05-09 17:37:54 +02:00
|
|
|
|
2018-11-27 20:10:41 +01:00
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
2018-05-09 17:37:54 +02:00
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void deformVertsEM(
|
2018-05-01 17:33:04 +02:00
|
|
|
ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData,
|
2018-05-08 12:00:38 +02:00
|
|
|
Mesh *mesh, float (*vertexCos)[3], int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-11-27 17:21:16 +01:00
|
|
|
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
|
2018-05-08 12:00:38 +02:00
|
|
|
|
2018-05-23 15:52:35 +02:00
|
|
|
displaceModifier_do((DisplaceModifierData *)md, ctx, mesh_src, vertexCos, numVerts);
|
2018-05-08 12:00:38 +02:00
|
|
|
|
2018-11-27 20:10:41 +01:00
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
2018-05-08 12:00:38 +02:00
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_Displace = {
|
|
|
|
/* name */ "Displace",
|
|
|
|
/* structName */ "DisplaceModifierData",
|
|
|
|
/* structSize */ sizeof(DisplaceModifierData),
|
|
|
|
/* type */ eModifierTypeType_OnlyDeform,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-05-08 15:04:10 +02:00
|
|
|
/* copyData */ modifier_copyData_generic,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2018-05-08 12:00:38 +02:00
|
|
|
/* deformVerts_DM */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
/* deformMatrices_DM */ NULL,
|
2018-05-08 12:00:38 +02:00
|
|
|
/* deformVertsEM_DM */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
/* deformMatricesEM_DM*/NULL,
|
|
|
|
/* applyModifier_DM */ NULL,
|
|
|
|
|
2018-05-08 12:00:38 +02:00
|
|
|
/* deformVerts */ deformVerts,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformMatrices */ NULL,
|
2018-05-08 12:00:38 +02:00
|
|
|
/* deformVertsEM */ deformVertsEM,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformMatricesEM */ NULL,
|
|
|
|
/* applyModifier */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
2018-04-04 14:56:32 +02:00
|
|
|
/* freeData */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* 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,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* dependsOnTime */ dependsOnTime,
|
2010-09-30 10:51:36 +00:00
|
|
|
/* dependsOnNormals */ dependsOnNormals,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* foreachObjectLink */ foreachObjectLink,
|
|
|
|
/* foreachIDLink */ foreachIDLink,
|
2011-08-12 18:11:22 +00:00
|
|
|
/* foreachTexLink */ foreachTexLink,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|