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
|
|
|
|
2013-04-15 23:12:40 +00:00
|
|
|
#include "BLI_ghash.h"
|
2014-02-08 06:07:10 +11:00
|
|
|
#include "BLI_listbase.h"
|
2013-05-08 12:59:35 +00:00
|
|
|
#include "BLI_rand.h"
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
#include "DNA_color_types.h" /* CurveMapping. */
|
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"
|
|
|
|
|
|
|
|
#include "BKE_colortools.h" /* CurveMapping. */
|
|
|
|
#include "BKE_deform.h"
|
2015-10-08 14:21:11 +02:00
|
|
|
#include "BKE_library_query.h"
|
2011-07-25 15:27:01 +00:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_texture.h" /* Texture masking. */
|
|
|
|
|
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
|
|
|
|
|
|
|
/**************************************
|
|
|
|
* Modifiers functions. *
|
|
|
|
**************************************/
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
|
2011-08-17 13:07:51 +00:00
|
|
|
wmd->edit_flags = 0;
|
2011-09-07 07:46:26 +00:00
|
|
|
wmd->falloff_type = MOD_WVG_MAPPING_NONE;
|
2011-07-25 15:27:01 +00:00
|
|
|
wmd->default_weight = 0.0f;
|
|
|
|
|
|
|
|
wmd->cmap_curve = curvemapping_add(1, 0.0, 0.0, 1.0, 1.0);
|
|
|
|
curvemapping_initialize(wmd->cmap_curve);
|
|
|
|
|
|
|
|
wmd->rem_threshold = 0.01f;
|
2011-08-23 12:33:45 +00:00
|
|
|
wmd->add_threshold = 0.01f;
|
2011-07-25 15:27:01 +00: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void freeData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
|
2011-07-25 15:27:01 +00:00
|
|
|
curvemapping_free(wmd->cmap_curve);
|
|
|
|
}
|
|
|
|
|
2018-07-04 12:45:30 +02:00
|
|
|
static void copyData(const ModifierData *md, ModifierData *target, const int flag)
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2018-05-08 15:04:10 +02:00
|
|
|
const WeightVGEditModifierData *wmd = (const WeightVGEditModifierData *) md;
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGEditModifierData *twmd = (WeightVGEditModifierData *) target;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2018-07-04 12:45:30 +02:00
|
|
|
modifier_copyData_generic(md, target, flag);
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2013-12-22 04:35:52 +11:00
|
|
|
twmd->cmap_curve = curvemapping_copy(wmd->cmap_curve);
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
static void requiredDataMask(Object *UNUSED(ob), ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
/* We need vertex groups! */
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
/* Ask for UV coordinates if we need them. */
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
if (wmd->mask_tex_mapping == MOD_DISP_MAP_UV) {
|
|
|
|
r_cddata_masks->fmask |= CD_MASK_MTFACE;
|
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2012-03-22 08:41:50 +00: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
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (wmd->mask_texture)
|
2011-07-25 15:27:01 +00:00
|
|
|
return BKE_texture_dependsOnTime(wmd->mask_texture);
|
2013-06-02 03:59:19 +00: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
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
|
2017-01-31 09:47:59 +01:00
|
|
|
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)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2017-01-31 09:47:59 +01:00
|
|
|
walk(userData, ob, (ID **)&wmd->mask_texture, IDWALK_CB_USER);
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
foreachObjectLink(md, ob, (ObjectWalkFunc)walk, userData);
|
|
|
|
}
|
|
|
|
|
2011-08-17 13:07:51 +00:00
|
|
|
static void foreachTexLink(ModifierData *md, Object *ob, TexWalkFunc walk, void *userData)
|
|
|
|
{
|
|
|
|
walk(userData, ob, md, "mask_texture");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *)md;
|
|
|
|
if (wmd->mask_tex_map_obj != NULL && wmd->mask_tex_mapping == MOD_DISP_MAP_OBJECT) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_TRANSFORM, "WeightVGEdit Modifier");
|
2019-02-12 12:01:17 +01:00
|
|
|
DEG_add_modifier_to_transform_relation(ctx->node, "WeightVGEdit 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-11-27 21:14:35 +01:00
|
|
|
else if (wmd->mask_tex_mapping == MOD_DISP_MAP_GLOBAL) {
|
2019-02-12 12:01:17 +01:00
|
|
|
DEG_add_modifier_to_transform_relation(ctx->node, "WeightVGEdit 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-02-05 10:04:09 +01:00
|
|
|
if (wmd->mask_texture != NULL) {
|
|
|
|
DEG_add_generic_id_relation(ctx->node, &wmd->mask_texture->id, "WeightVGEdit 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-07-10 12:14:08 +02:00
|
|
|
static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams))
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
|
2011-07-25 15:27:01 +00:00
|
|
|
/* If no vertex group, bypass. */
|
2011-09-05 05:28:32 +00:00
|
|
|
return (wmd->defgrp_name[0] == '\0');
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 08:21:07 +02:00
|
|
|
static Mesh *applyModifier(
|
|
|
|
ModifierData *md,
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
Mesh *mesh)
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2018-05-08 12:58:01 +02:00
|
|
|
BLI_assert(mesh != NULL);
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
|
2018-05-07 18:15:27 +02:00
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
MDeformVert *dvert = NULL;
|
2011-09-15 17:28:18 +00:00
|
|
|
MDeformWeight **dw = NULL;
|
2011-09-05 05:28:32 +00:00
|
|
|
float *org_w; /* Array original weights. */
|
|
|
|
float *new_w; /* Array new weights. */
|
2011-07-25 15:27:01 +00:00
|
|
|
int i;
|
2018-05-07 18:15:27 +02:00
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
/* Flags. */
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool do_add = (wmd->edit_flags & MOD_WVG_EDIT_ADD2VG) != 0;
|
|
|
|
const bool do_rem = (wmd->edit_flags & MOD_WVG_EDIT_REMFVG) != 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
|
|
|
/* Only do weight-preview in Object, Sculpt and Pose modes! */
|
|
|
|
#if 0
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool do_prev = (wmd->modifier.mode & eModifierMode_DoWeightPreview);
|
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
|
|
|
|
|
|
|
/* Get number of verts. */
|
2018-05-07 18:15:27 +02:00
|
|
|
const int numVerts = mesh->totvert;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
/* Check if we can just return the original mesh.
|
|
|
|
* Must have verts and therefore verts assigned to vgroups to do anything useful!
|
|
|
|
*/
|
2018-05-07 18:15:27 +02:00
|
|
|
if ((numVerts == 0) || BLI_listbase_is_empty(&ctx->object->defbase)) {
|
|
|
|
return mesh;
|
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2011-07-27 18:48:23 +00:00
|
|
|
/* Get vgroup idx from its name. */
|
2018-05-07 18:15:27 +02:00
|
|
|
const int defgrp_index = defgroup_name_index(ctx->object, wmd->defgrp_name);
|
|
|
|
if (defgrp_index == -1) {
|
|
|
|
return mesh;
|
|
|
|
}
|
2011-07-27 18:48:23 +00:00
|
|
|
|
2018-05-07 18:15:27 +02:00
|
|
|
const bool has_mdef = CustomData_has_layer(&mesh->vdata, CD_MDEFORMVERT);
|
2012-01-22 10:14:01 +00:00
|
|
|
/* If no vertices were ever added to an object's vgroup, dvert might be NULL. */
|
2018-05-07 18:15:27 +02:00
|
|
|
if (!has_mdef) {
|
2012-01-22 10:14:01 +00:00
|
|
|
/* If this modifier is not allowed to add vertices, just return. */
|
2018-05-07 18:15:27 +02:00
|
|
|
if (!do_add) {
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_mdef) {
|
2018-08-08 20:13:17 +02:00
|
|
|
dvert = CustomData_duplicate_referenced_layer(&mesh->vdata, CD_MDEFORMVERT, numVerts);
|
2018-05-07 18:15:27 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Add a valid data layer! */
|
2018-08-08 20:13:17 +02:00
|
|
|
dvert = CustomData_add_layer(&mesh->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, numVerts);
|
2018-05-07 18:15:27 +02:00
|
|
|
}
|
|
|
|
/* Ultimate security check. */
|
|
|
|
if (!dvert) {
|
|
|
|
return mesh;
|
2012-05-06 13:00:56 +00:00
|
|
|
}
|
2018-08-08 20:13:17 +02:00
|
|
|
mesh->dvert = dvert;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
/* Get org weights, assuming 0.0 for vertices not in given vgroup. */
|
2018-01-14 22:14:20 +01:00
|
|
|
org_w = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGEdit Modifier, org_w");
|
|
|
|
new_w = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGEdit Modifier, new_w");
|
|
|
|
dw = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGEdit Modifier, dw");
|
2011-07-25 15:27:01 +00:00
|
|
|
for (i = 0; i < numVerts; i++) {
|
2012-10-22 17:19:05 +00:00
|
|
|
dw[i] = defvert_find_index(&dvert[i], defgrp_index);
|
2012-03-24 06:24:53 +00:00
|
|
|
if (dw[i]) {
|
2011-09-15 17:28:18 +00:00
|
|
|
org_w[i] = new_w[i] = dw[i]->weight;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
org_w[i] = new_w[i] = wmd->default_weight;
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
2011-09-05 16:16:00 +00:00
|
|
|
}
|
2011-09-05 05:28:32 +00:00
|
|
|
|
2011-09-05 16:16:00 +00:00
|
|
|
/* Do mapping. */
|
2011-09-07 07:46:26 +00:00
|
|
|
if (wmd->falloff_type != MOD_WVG_MAPPING_NONE) {
|
2013-04-15 23:12:40 +00:00
|
|
|
RNG *rng = NULL;
|
|
|
|
|
2018-05-07 18:15:27 +02:00
|
|
|
if (wmd->falloff_type == MOD_WVG_MAPPING_RANDOM) {
|
2018-05-01 17:33:04 +02:00
|
|
|
rng = BLI_rng_new_srandom(BLI_ghashutil_strhash(ctx->object->id.name + 2));
|
2018-05-07 18:15:27 +02:00
|
|
|
}
|
2013-04-15 23:12:40 +00:00
|
|
|
|
|
|
|
weightvg_do_map(numVerts, new_w, wmd->falloff_type, wmd->cmap_curve, rng);
|
|
|
|
|
2018-05-07 18:15:27 +02:00
|
|
|
if (rng) {
|
2013-04-15 23:12:40 +00:00
|
|
|
BLI_rng_free(rng);
|
2018-05-07 18:15:27 +02:00
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do masking. */
|
2018-06-22 15:03:42 +02:00
|
|
|
struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
|
2018-08-08 20:13:17 +02:00
|
|
|
weightvg_do_mask(ctx, numVerts, NULL, org_w, new_w, ctx->object, mesh, wmd->mask_constant,
|
2018-06-22 15:03:42 +02:00
|
|
|
wmd->mask_defgrp_name, scene, wmd->mask_texture,
|
2012-04-10 14:11:45 +00:00
|
|
|
wmd->mask_tex_use_channel, wmd->mask_tex_mapping,
|
|
|
|
wmd->mask_tex_map_obj, wmd->mask_tex_uvlayer_name);
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
/* Update/add/remove from vgroup. */
|
2012-10-22 17:19:05 +00:00
|
|
|
weightvg_update_vg(dvert, defgrp_index, dw, numVerts, NULL, org_w, do_add, wmd->add_threshold,
|
2011-07-25 15:27:01 +00:00
|
|
|
do_rem, wmd->rem_threshold);
|
|
|
|
|
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 weight preview enabled... */
|
|
|
|
#if 0 /* XXX Currently done in mod stack :/ */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (do_prev)
|
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
|
|
|
DM_update_weight_mcol(ob, dm, 0, org_w, 0, NULL);
|
|
|
|
#endif
|
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
/* Freeing stuff. */
|
2011-09-05 05:28:32 +00:00
|
|
|
MEM_freeN(org_w);
|
|
|
|
MEM_freeN(new_w);
|
2011-09-15 17:28:18 +00:00
|
|
|
MEM_freeN(dw);
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
/* Return the vgroup-modified mesh. */
|
2018-08-08 20:13:17 +02:00
|
|
|
return mesh;
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_WeightVGEdit = {
|
2011-09-07 07:46:26 +00:00
|
|
|
/* name */ "VertexWeightEdit",
|
2011-07-25 15:27:01 +00:00
|
|
|
/* structName */ "WeightVGEditModifierData",
|
|
|
|
/* structSize */ sizeof(WeightVGEditModifierData),
|
2011-12-20 14:15:59 +00:00
|
|
|
/* type */ eModifierTypeType_NonGeometrical,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
|
|
|
eModifierTypeFlag_SupportsMapping |
|
|
|
|
eModifierTypeFlag_SupportsEditmode |
|
|
|
|
eModifierTypeFlag_UsesPreview,
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
/* copyData */ copyData,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
2018-05-07 18:15:27 +02:00
|
|
|
/* applyModifier */ applyModifier,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
|
|
|
/* freeData */ freeData,
|
|
|
|
/* 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,
|
2011-07-25 15:27:01 +00:00
|
|
|
/* dependsOnTime */ dependsOnTime,
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
/* foreachObjectLink */ foreachObjectLink,
|
|
|
|
/* foreachIDLink */ foreachIDLink,
|
2011-08-17 13:07:51 +00:00
|
|
|
/* foreachTexLink */ foreachTexLink,
|
2019-03-18 15:56:16 +01:00
|
|
|
/* freeRuntimeData */ NULL,
|
2011-07-25 15:27:01 +00:00
|
|
|
};
|