2011-07-25 15:27:01 +00:00
|
|
|
/*
|
2011-09-07 07:06:43 +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) 2011 by Bastien Montagne.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup modifiers
|
2011-07-25 15:27:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
2019-02-25 11:39:14 +01:00
|
|
|
|
2014-02-08 06:07:10 +11:00
|
|
|
#include "BLI_listbase.h"
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_math.h"
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2018-05-07 18:15:27 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2011-07-25 15:27:01 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
2018-05-07 18:15:27 +02:00
|
|
|
#include "BKE_customdata.h"
|
2011-07-25 15:27:01 +00:00
|
|
|
#include "BKE_deform.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_query.h"
|
2011-07-25 15:27:01 +00:00
|
|
|
#include "BKE_modifier.h"
|
2019-04-17 06:17:24 +02:00
|
|
|
#include "BKE_texture.h" /* Texture masking. */
|
2011-07-25 15:27:01 +00:00
|
|
|
|
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
|
|
|
#include "DEG_depsgraph_build.h"
|
2018-06-22 15:03:42 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
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
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2017-08-01 09:06:34 +10:00
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
#include "MOD_weightvg_util.h"
|
2017-08-01 09:06:34 +10:00
|
|
|
#include "MOD_modifiertypes.h"
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This mixes the old weight with the new weight factor.
|
|
|
|
*/
|
|
|
|
static float mix_weight(float weight, float weight2, char mix_mode)
|
|
|
|
{
|
|
|
|
#if 0
|
2019-04-17 06:17:24 +02:00
|
|
|
/*
|
|
|
|
* XXX Don't know why, but the switch version takes many CPU time,
|
|
|
|
* and produces lag in realtime playback...
|
|
|
|
*/
|
2019-04-17 08:24:14 +02:00
|
|
|
switch (mix_mode) {
|
2019-04-17 06:17:24 +02:00
|
|
|
case MOD_WVG_MIX_ADD:
|
|
|
|
return (weight + weight2);
|
|
|
|
case MOD_WVG_MIX_SUB:
|
|
|
|
return (weight - weight2);
|
|
|
|
case MOD_WVG_MIX_MUL:
|
|
|
|
return (weight * weight2);
|
|
|
|
case MOD_WVG_MIX_DIV:
|
|
|
|
/* Avoid dividing by zero (or really small values). */
|
2019-05-31 23:21:16 +10:00
|
|
|
if (0.0 <= weight2 < MOD_WVG_ZEROFLOOR) {
|
2019-04-17 06:17:24 +02:00
|
|
|
weight2 = MOD_WVG_ZEROFLOOR;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
|
|
|
else if (-MOD_WVG_ZEROFLOOR < weight2) {
|
2019-04-17 06:17:24 +02:00
|
|
|
weight2 = -MOD_WVG_ZEROFLOOR;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return (weight / weight2);
|
|
|
|
case MOD_WVG_MIX_DIF:
|
|
|
|
return (weight < weight2 ? weight2 - weight : weight - weight2);
|
|
|
|
case MOD_WVG_MIX_AVG:
|
|
|
|
return (weight + weight2) / 2.0;
|
|
|
|
case MOD_WVG_MIX_SET:
|
|
|
|
default:
|
|
|
|
return weight2;
|
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
#endif
|
2019-04-22 09:15:10 +10:00
|
|
|
if (mix_mode == MOD_WVG_MIX_SET) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return weight2;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
else if (mix_mode == MOD_WVG_MIX_ADD) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (weight + weight2);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
else if (mix_mode == MOD_WVG_MIX_SUB) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (weight - weight2);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
else if (mix_mode == MOD_WVG_MIX_MUL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (weight * weight2);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
else if (mix_mode == MOD_WVG_MIX_DIV) {
|
|
|
|
/* Avoid dividing by zero (or really small values). */
|
2019-04-22 09:15:10 +10:00
|
|
|
if (weight2 < 0.0f && weight2 > -MOD_WVG_ZEROFLOOR) {
|
2019-04-17 06:17:24 +02:00
|
|
|
weight2 = -MOD_WVG_ZEROFLOOR;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
else if (weight2 >= 0.0f && weight2 < MOD_WVG_ZEROFLOOR) {
|
2019-04-17 06:17:24 +02:00
|
|
|
weight2 = MOD_WVG_ZEROFLOOR;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return (weight / weight2);
|
|
|
|
}
|
2019-04-22 09:15:10 +10:00
|
|
|
else if (mix_mode == MOD_WVG_MIX_DIF) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (weight < weight2 ? weight2 - weight : weight - weight2);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
else if (mix_mode == MOD_WVG_MIX_AVG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (weight + weight2) * 0.5f;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
return weight2;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************
|
|
|
|
* Modifiers functions. *
|
|
|
|
**************************************/
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
wmd->default_weight_a = 0.0f;
|
|
|
|
wmd->default_weight_b = 0.0f;
|
|
|
|
wmd->mix_mode = MOD_WVG_MIX_SET;
|
|
|
|
wmd->mix_set = MOD_WVG_SET_AND;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
wmd->mask_constant = 1.0f;
|
|
|
|
wmd->mask_tex_use_channel = MOD_WVG_MASK_TEX_USE_INT; /* Use intensity by default. */
|
|
|
|
wmd->mask_tex_mapping = MOD_DISP_MAP_LOCAL;
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void requiredDataMask(Object *UNUSED(ob),
|
|
|
|
ModifierData *md,
|
|
|
|
CustomData_MeshMasks *r_cddata_masks)
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* We need vertex groups! */
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Ask for UV coordinates if we need them. */
|
|
|
|
if (wmd->mask_tex_mapping == MOD_DISP_MAP_UV) {
|
|
|
|
r_cddata_masks->fmask |= CD_MASK_MTFACE;
|
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* No need to ask for CD_PREVIEW_MLOOPCOL... */
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 03:59:19 +00:00
|
|
|
static bool dependsOnTime(ModifierData *md)
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (wmd->mask_texture) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_texture_dependsOnTime(wmd->mask_texture);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
2015-10-05 15:57:10 +02:00
|
|
|
static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md;
|
|
|
|
walk(userData, ob, &wmd->mask_tex_map_obj, IDWALK_CB_NOP);
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
walk(userData, ob, (ID **)&wmd->mask_texture, IDWALK_CB_USER);
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
foreachObjectLink(md, ob, (ObjectWalkFunc)walk, userData);
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
2011-08-17 13:07:51 +00:00
|
|
|
static void foreachTexLink(ModifierData *md, Object *ob, TexWalkFunc walk, void *userData)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
walk(userData, ob, md, "mask_texture");
|
2011-08-17 13:07:51 +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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md;
|
|
|
|
if (wmd->mask_tex_map_obj != NULL && wmd->mask_tex_mapping == MOD_DISP_MAP_OBJECT) {
|
|
|
|
DEG_add_object_relation(
|
|
|
|
ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_TRANSFORM, "WeightVGMix Modifier");
|
|
|
|
DEG_add_object_relation(
|
|
|
|
ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_GEOMETRY, "WeightVGMix Modifier");
|
|
|
|
|
|
|
|
DEG_add_modifier_to_transform_relation(ctx->node, "WeightVGMix Modifier");
|
|
|
|
}
|
|
|
|
else if (wmd->mask_tex_mapping == MOD_DISP_MAP_GLOBAL) {
|
|
|
|
DEG_add_modifier_to_transform_relation(ctx->node, "WeightVGMix Modifier");
|
|
|
|
}
|
|
|
|
if (wmd->mask_texture != NULL) {
|
|
|
|
DEG_add_generic_id_relation(ctx->node, &wmd->mask_texture->id, "WeightVGMix 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
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static bool isDisabled(const struct Scene *UNUSED(scene),
|
|
|
|
ModifierData *md,
|
|
|
|
bool UNUSED(useRenderParams))
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md;
|
|
|
|
/* If no vertex group, bypass. */
|
|
|
|
return (wmd->defgrp_name_a[0] == '\0');
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-07 18:15:27 +02:00
|
|
|
static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(mesh != NULL);
|
|
|
|
|
|
|
|
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md;
|
|
|
|
|
|
|
|
MDeformVert *dvert = NULL;
|
|
|
|
MDeformWeight **dw1, **tdw1, **dw2, **tdw2;
|
|
|
|
float *org_w;
|
|
|
|
float *new_w;
|
|
|
|
int *tidx, *indices = NULL;
|
|
|
|
int numIdx = 0;
|
|
|
|
int i;
|
|
|
|
/* Flags. */
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
#if 0
|
2019-04-17 06:17:24 +02:00
|
|
|
const bool do_prev = (wmd->modifier.mode & eModifierMode_DoWeightPreview) != 0;
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
#endif
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Get number of verts. */
|
|
|
|
const int numVerts = mesh->totvert;
|
|
|
|
|
|
|
|
/* Check if we can just return the original mesh.
|
|
|
|
* Must have verts and therefore verts assigned to vgroups to do anything useful!
|
|
|
|
*/
|
|
|
|
if ((numVerts == 0) || BLI_listbase_is_empty(&ctx->object->defbase)) {
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get vgroup idx from its name. */
|
|
|
|
const int defgrp_index = defgroup_name_index(ctx->object, wmd->defgrp_name_a);
|
|
|
|
if (defgrp_index == -1) {
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
/* Get second vgroup idx from its name, if given. */
|
|
|
|
int defgrp_index_other = -1;
|
|
|
|
if (wmd->defgrp_name_b[0] != '\0') {
|
|
|
|
defgrp_index_other = defgroup_name_index(ctx->object, wmd->defgrp_name_b);
|
|
|
|
if (defgrp_index_other == -1) {
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool has_mdef = CustomData_has_layer(&mesh->vdata, CD_MDEFORMVERT);
|
|
|
|
/* If no vertices were ever added to an object's vgroup, dvert might be NULL. */
|
|
|
|
if (!has_mdef) {
|
|
|
|
/* If not affecting all vertices, just return. */
|
|
|
|
if (wmd->mix_set != MOD_WVG_SET_ALL) {
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_mdef) {
|
|
|
|
dvert = CustomData_duplicate_referenced_layer(&mesh->vdata, CD_MDEFORMVERT, numVerts);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Add a valid data layer! */
|
|
|
|
dvert = CustomData_add_layer(&mesh->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, numVerts);
|
|
|
|
}
|
|
|
|
/* Ultimate security check. */
|
|
|
|
if (!dvert) {
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
mesh->dvert = dvert;
|
|
|
|
|
|
|
|
/* Find out which vertices to work on. */
|
|
|
|
tidx = MEM_malloc_arrayN(numVerts, sizeof(int), "WeightVGMix Modifier, tidx");
|
|
|
|
tdw1 = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGMix Modifier, tdw1");
|
|
|
|
tdw2 = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGMix Modifier, tdw2");
|
|
|
|
switch (wmd->mix_set) {
|
|
|
|
case MOD_WVG_SET_A:
|
|
|
|
/* All vertices in first vgroup. */
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
MDeformWeight *dw = defvert_find_index(&dvert[i], defgrp_index);
|
|
|
|
if (dw) {
|
|
|
|
tdw1[numIdx] = dw;
|
|
|
|
tdw2[numIdx] = (defgrp_index_other >= 0) ?
|
|
|
|
defvert_find_index(&dvert[i], defgrp_index_other) :
|
|
|
|
NULL;
|
|
|
|
tidx[numIdx++] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MOD_WVG_SET_B:
|
|
|
|
/* All vertices in second vgroup. */
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
MDeformWeight *dw = (defgrp_index_other >= 0) ?
|
|
|
|
defvert_find_index(&dvert[i], defgrp_index_other) :
|
|
|
|
NULL;
|
|
|
|
if (dw) {
|
|
|
|
tdw1[numIdx] = defvert_find_index(&dvert[i], defgrp_index);
|
|
|
|
tdw2[numIdx] = dw;
|
|
|
|
tidx[numIdx++] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MOD_WVG_SET_OR:
|
|
|
|
/* All vertices in one vgroup or the other. */
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
MDeformWeight *adw = defvert_find_index(&dvert[i], defgrp_index);
|
|
|
|
MDeformWeight *bdw = (defgrp_index_other >= 0) ?
|
|
|
|
defvert_find_index(&dvert[i], defgrp_index_other) :
|
|
|
|
NULL;
|
|
|
|
if (adw || bdw) {
|
|
|
|
tdw1[numIdx] = adw;
|
|
|
|
tdw2[numIdx] = bdw;
|
|
|
|
tidx[numIdx++] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MOD_WVG_SET_AND:
|
|
|
|
/* All vertices in both vgroups. */
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
MDeformWeight *adw = defvert_find_index(&dvert[i], defgrp_index);
|
|
|
|
MDeformWeight *bdw = (defgrp_index_other >= 0) ?
|
|
|
|
defvert_find_index(&dvert[i], defgrp_index_other) :
|
|
|
|
NULL;
|
|
|
|
if (adw && bdw) {
|
|
|
|
tdw1[numIdx] = adw;
|
|
|
|
tdw2[numIdx] = bdw;
|
|
|
|
tidx[numIdx++] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MOD_WVG_SET_ALL:
|
|
|
|
default:
|
|
|
|
/* Use all vertices. */
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
tdw1[i] = defvert_find_index(&dvert[i], defgrp_index);
|
|
|
|
tdw2[i] = (defgrp_index_other >= 0) ? defvert_find_index(&dvert[i], defgrp_index_other) :
|
|
|
|
NULL;
|
|
|
|
}
|
|
|
|
numIdx = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (numIdx == 0) {
|
|
|
|
/* Use no vertices! Hence, return org data. */
|
|
|
|
MEM_freeN(tdw1);
|
|
|
|
MEM_freeN(tdw2);
|
|
|
|
MEM_freeN(tidx);
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
if (numIdx != -1) {
|
|
|
|
indices = MEM_malloc_arrayN(numIdx, sizeof(int), "WeightVGMix Modifier, indices");
|
|
|
|
memcpy(indices, tidx, sizeof(int) * numIdx);
|
|
|
|
dw1 = MEM_malloc_arrayN(numIdx, sizeof(MDeformWeight *), "WeightVGMix Modifier, dw1");
|
|
|
|
memcpy(dw1, tdw1, sizeof(MDeformWeight *) * numIdx);
|
|
|
|
MEM_freeN(tdw1);
|
|
|
|
dw2 = MEM_malloc_arrayN(numIdx, sizeof(MDeformWeight *), "WeightVGMix Modifier, dw2");
|
|
|
|
memcpy(dw2, tdw2, sizeof(MDeformWeight *) * numIdx);
|
|
|
|
MEM_freeN(tdw2);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Use all vertices. */
|
|
|
|
numIdx = numVerts;
|
|
|
|
/* Just copy MDeformWeight pointers arrays, they will be freed at the end. */
|
|
|
|
dw1 = tdw1;
|
|
|
|
dw2 = tdw2;
|
|
|
|
}
|
|
|
|
MEM_freeN(tidx);
|
|
|
|
|
|
|
|
org_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGMix Modifier, org_w");
|
|
|
|
new_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGMix Modifier, new_w");
|
|
|
|
|
|
|
|
/* Mix weights. */
|
|
|
|
for (i = 0; i < numIdx; i++) {
|
|
|
|
float weight2;
|
|
|
|
org_w[i] = dw1[i] ? dw1[i]->weight : wmd->default_weight_a;
|
|
|
|
weight2 = dw2[i] ? dw2[i]->weight : wmd->default_weight_b;
|
|
|
|
|
|
|
|
new_w[i] = mix_weight(org_w[i], weight2, wmd->mix_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do masking. */
|
|
|
|
struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
|
|
|
|
weightvg_do_mask(ctx,
|
|
|
|
numIdx,
|
|
|
|
indices,
|
|
|
|
org_w,
|
|
|
|
new_w,
|
|
|
|
ctx->object,
|
|
|
|
mesh,
|
|
|
|
wmd->mask_constant,
|
|
|
|
wmd->mask_defgrp_name,
|
|
|
|
scene,
|
|
|
|
wmd->mask_texture,
|
|
|
|
wmd->mask_tex_use_channel,
|
|
|
|
wmd->mask_tex_mapping,
|
|
|
|
wmd->mask_tex_map_obj,
|
|
|
|
wmd->mask_tex_uvlayer_name);
|
|
|
|
|
|
|
|
/* Update (add to) vgroup.
|
|
|
|
* XXX Depending on the MOD_WVG_SET_xxx option chosen, we might have to add vertices to vgroup.
|
|
|
|
*/
|
|
|
|
weightvg_update_vg(
|
|
|
|
dvert, defgrp_index, dw1, numIdx, indices, org_w, true, -FLT_MAX, false, 0.0f);
|
|
|
|
|
|
|
|
/* If weight preview enabled... */
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
#if 0 /* XXX Currently done in mod stack :/ */
|
2019-05-31 23:21:16 +10:00
|
|
|
if (do_prev) {
|
2019-04-17 06:17:24 +02:00
|
|
|
DM_update_weight_mcol(ob, dm, 0, org_w, numIdx, indices);
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Freeing stuff. */
|
|
|
|
MEM_freeN(org_w);
|
|
|
|
MEM_freeN(new_w);
|
|
|
|
MEM_freeN(dw1);
|
|
|
|
MEM_freeN(dw2);
|
|
|
|
MEM_SAFE_FREE(indices);
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Return the vgroup-modified mesh. */
|
|
|
|
return mesh;
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_WeightVGMix = {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* name */ "VertexWeightMix",
|
|
|
|
/* structName */ "WeightVGMixModifierData",
|
|
|
|
/* structSize */ sizeof(WeightVGMixModifierData),
|
|
|
|
/* type */ eModifierTypeType_NonGeometrical,
|
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsMapping |
|
|
|
|
eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_UsesPreview,
|
|
|
|
|
|
|
|
/* copyData */ modifier_copyData_generic,
|
|
|
|
|
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
|
|
|
/* applyModifier */ applyModifier,
|
|
|
|
|
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
|
|
|
/* freeData */ NULL,
|
|
|
|
/* isDisabled */ isDisabled,
|
|
|
|
/* updateDepsgraph */ updateDepsgraph,
|
|
|
|
/* dependsOnTime */ dependsOnTime,
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
/* foreachObjectLink */ foreachObjectLink,
|
|
|
|
/* foreachIDLink */ foreachIDLink,
|
|
|
|
/* foreachTexLink */ foreachTexLink,
|
|
|
|
/* freeRuntimeData */ NULL,
|
2011-07-25 15:27:01 +00:00
|
|
|
};
|