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
|
|
|
*/
|
|
|
|
|
2013-04-15 23:12:40 +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"
|
2011-07-25 15:27:01 +00:00
|
|
|
#include "BLI_math.h"
|
2013-05-08 12:59:35 +00:00
|
|
|
#include "BLI_rand.h"
|
2015-11-25 11:51:05 +01:00
|
|
|
#include "BLI_task.h"
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
2018-06-22 15:45:46 +02:00
|
|
|
#include "BKE_bvhutils.h"
|
2018-05-08 12:58:01 +02:00
|
|
|
#include "BKE_curve.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"
|
2013-06-10 18:12:07 +00:00
|
|
|
#include "BKE_library.h"
|
2015-10-08 14:21:11 +02:00
|
|
|
#include "BKE_library_query.h"
|
2018-05-07 18:15:27 +02:00
|
|
|
#include "BKE_mesh.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"
|
2018-05-07 18:15:27 +02:00
|
|
|
#include "MOD_util.h"
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2015-11-25 11:51:05 +01:00
|
|
|
//#define USE_TIMEIT
|
2013-09-03 21:22:43 +00:00
|
|
|
|
|
|
|
#ifdef USE_TIMEIT
|
|
|
|
# include "PIL_time.h"
|
|
|
|
# include "PIL_time_utildefines.h"
|
|
|
|
#endif
|
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
/**************************************
|
|
|
|
* Util functions. *
|
|
|
|
**************************************/
|
|
|
|
|
|
|
|
/* Util macro. */
|
|
|
|
#define OUT_OF_MEMORY() ((void)printf("WeightVGProximity: Out of memory.\n"))
|
|
|
|
|
2015-11-25 11:51:05 +01:00
|
|
|
typedef struct Vert2GeomData {
|
|
|
|
/* Read-only data */
|
|
|
|
float (*v_cos)[3];
|
|
|
|
|
|
|
|
const SpaceTransform *loc2trgt;
|
|
|
|
|
|
|
|
BVHTreeFromMesh *treeData[3];
|
|
|
|
|
|
|
|
/* Write data, but not needing locking (two different threads will never write same index). */
|
|
|
|
float *dist[3];
|
|
|
|
} Vert2GeomData;
|
|
|
|
|
2018-09-03 16:49:08 +02:00
|
|
|
/* Data which is localized to each computed chunk (i.e. thread-safe, and with continuous subset of index range). */
|
2015-11-25 11:51:05 +01:00
|
|
|
typedef struct Vert2GeomDataChunk {
|
|
|
|
/* Read-only data */
|
|
|
|
float last_hit_co[3][3];
|
|
|
|
bool is_init[3];
|
|
|
|
} Vert2GeomDataChunk;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback used by BLI_task 'for loop' helper.
|
|
|
|
*/
|
2018-01-10 12:49:51 +01:00
|
|
|
static void vert2geom_task_cb_ex(
|
|
|
|
void *__restrict userdata,
|
|
|
|
const int iter,
|
|
|
|
const ParallelRangeTLS *__restrict tls)
|
2015-11-25 11:51:05 +01:00
|
|
|
{
|
|
|
|
Vert2GeomData *data = userdata;
|
2018-01-05 16:33:13 +01:00
|
|
|
Vert2GeomDataChunk *data_chunk = tls->userdata_chunk;
|
2015-11-25 11:51:05 +01:00
|
|
|
|
|
|
|
float tmp_co[3];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Convert the vertex to tree coordinates. */
|
|
|
|
copy_v3_v3(tmp_co, data->v_cos[iter]);
|
|
|
|
BLI_space_transform_apply(data->loc2trgt, tmp_co);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(data->dist); i++) {
|
|
|
|
if (data->dist[i]) {
|
|
|
|
BVHTreeNearest nearest = {0};
|
|
|
|
|
|
|
|
/* Note that we use local proximity heuristics (to reduce the nearest search).
|
|
|
|
*
|
|
|
|
* If we already had an hit before in same chunk of tasks (i.e. previous vertex by index),
|
|
|
|
* we assume this vertex is going to have a close hit to that other vertex, so we can initiate
|
|
|
|
* the "nearest.dist" with the expected value to that last hit.
|
|
|
|
* This will lead in pruning of the search tree.
|
|
|
|
*/
|
|
|
|
nearest.dist_sq = data_chunk->is_init[i] ? len_squared_v3v3(tmp_co, data_chunk->last_hit_co[i]) : FLT_MAX;
|
|
|
|
nearest.index = -1;
|
|
|
|
|
|
|
|
/* Compute and store result. If invalid (-1 idx), keep FLT_MAX dist. */
|
|
|
|
BLI_bvhtree_find_nearest(data->treeData[i]->tree, tmp_co, &nearest,
|
2015-11-26 11:08:25 +11:00
|
|
|
data->treeData[i]->nearest_callback, data->treeData[i]);
|
2015-11-25 11:51:05 +01:00
|
|
|
data->dist[i][iter] = sqrtf(nearest.dist_sq);
|
|
|
|
|
|
|
|
if (nearest.index != -1) {
|
|
|
|
copy_v3_v3(data_chunk->last_hit_co[i], nearest.co);
|
|
|
|
data_chunk->is_init[i] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
/**
|
|
|
|
* Find nearest vertex and/or edge and/or face, for each vertex (adapted from shrinkwrap.c).
|
|
|
|
*/
|
2018-05-12 08:04:56 +02:00
|
|
|
static void get_vert2geom_distance(
|
|
|
|
int numVerts, float (*v_cos)[3],
|
|
|
|
float *dist_v, float *dist_e, float *dist_f,
|
2018-05-12 08:21:07 +02:00
|
|
|
Mesh *target, const SpaceTransform *loc2trgt)
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2015-11-25 11:51:05 +01:00
|
|
|
Vert2GeomData data = {0};
|
2015-12-02 13:15:52 +11:00
|
|
|
Vert2GeomDataChunk data_chunk = {{{0}}};
|
2015-11-25 11:51:05 +01:00
|
|
|
|
2014-08-13 08:38:16 +10:00
|
|
|
BVHTreeFromMesh treeData_v = {NULL};
|
|
|
|
BVHTreeFromMesh treeData_e = {NULL};
|
|
|
|
BVHTreeFromMesh treeData_f = {NULL};
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
if (dist_v) {
|
|
|
|
/* Create a bvh-tree of the given target's verts. */
|
2018-05-09 10:10:30 +02:00
|
|
|
BKE_bvhtree_from_mesh_get(&treeData_v, target, BVHTREE_FROM_VERTS, 2);
|
2012-03-24 06:24:53 +00:00
|
|
|
if (treeData_v.tree == NULL) {
|
2011-07-25 15:27:01 +00:00
|
|
|
OUT_OF_MEMORY();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dist_e) {
|
|
|
|
/* Create a bvh-tree of the given target's edges. */
|
2018-05-09 10:10:30 +02:00
|
|
|
BKE_bvhtree_from_mesh_get(&treeData_e, target, BVHTREE_FROM_EDGES, 2);
|
2012-03-24 06:24:53 +00:00
|
|
|
if (treeData_e.tree == NULL) {
|
2011-07-25 15:27:01 +00:00
|
|
|
OUT_OF_MEMORY();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dist_f) {
|
|
|
|
/* Create a bvh-tree of the given target's faces. */
|
2018-05-09 10:10:30 +02:00
|
|
|
BKE_bvhtree_from_mesh_get(&treeData_f, target, BVHTREE_FROM_LOOPTRI, 2);
|
2012-03-24 06:24:53 +00:00
|
|
|
if (treeData_f.tree == NULL) {
|
2011-07-25 15:27:01 +00:00
|
|
|
OUT_OF_MEMORY();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-25 11:51:05 +01:00
|
|
|
data.v_cos = v_cos;
|
|
|
|
data.loc2trgt = loc2trgt;
|
|
|
|
data.treeData[0] = &treeData_v;
|
|
|
|
data.treeData[1] = &treeData_e;
|
|
|
|
data.treeData[2] = &treeData_f;
|
|
|
|
data.dist[0] = dist_v;
|
|
|
|
data.dist[1] = dist_e;
|
|
|
|
data.dist[2] = dist_f;
|
|
|
|
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
|
|
|
settings.use_threading = (numVerts > 10000);
|
|
|
|
settings.userdata_chunk = &data_chunk;
|
|
|
|
settings.userdata_chunk_size = sizeof(data_chunk);
|
|
|
|
BLI_task_parallel_range(
|
|
|
|
0, numVerts,
|
|
|
|
&data,
|
|
|
|
vert2geom_task_cb_ex,
|
|
|
|
&settings);
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
if (dist_v)
|
|
|
|
free_bvhtree_from_mesh(&treeData_v);
|
|
|
|
if (dist_e)
|
|
|
|
free_bvhtree_from_mesh(&treeData_e);
|
|
|
|
if (dist_f)
|
|
|
|
free_bvhtree_from_mesh(&treeData_f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the real distance between a vertex and another reference object.
|
|
|
|
* Note that it works in final world space (i.e. with constraints etc. applied).
|
|
|
|
*/
|
2018-05-12 08:04:56 +02:00
|
|
|
static void get_vert2ob_distance(
|
|
|
|
int numVerts, float (*v_cos)[3], float *dist,
|
|
|
|
Object *ob, Object *obr)
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
|
|
|
/* Vertex and ref object coordinates. */
|
2011-09-05 04:00:08 +00:00
|
|
|
float v_wco[3];
|
2012-05-06 13:38:33 +00:00
|
|
|
unsigned int i = numVerts;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
while (i-- > 0) {
|
2011-07-25 15:27:01 +00:00
|
|
|
/* Get world-coordinates of the vertex (constraints and anim included). */
|
2011-09-05 04:00:08 +00:00
|
|
|
mul_v3_m4v3(v_wco, ob->obmat, v_cos[i]);
|
2011-07-25 15:27:01 +00:00
|
|
|
/* Return distance between both coordinates. */
|
2011-09-05 04:00:08 +00:00
|
|
|
dist[i] = len_v3v3(v_wco, obr->obmat[3]);
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the real distance between an object and another reference object.
|
|
|
|
* Note that it works in final world space (i.e. with constraints etc. applied).
|
|
|
|
*/
|
2012-05-06 13:38:33 +00:00
|
|
|
static float get_ob2ob_distance(const Object *ob, const Object *obr)
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2018-06-17 17:04:27 +02:00
|
|
|
return len_v3v3(ob->obmat[3], obr->obmat[3]);
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 21:12:51 +00:00
|
|
|
/**
|
2012-07-16 23:23:33 +00:00
|
|
|
* Maps distances to weights, with an optional "smoothing" mapping.
|
2011-08-08 21:12:51 +00:00
|
|
|
*/
|
2013-04-15 23:12:40 +00:00
|
|
|
static void do_map(Object *ob, float *weights, const int nidx, const float min_d, const float max_d, short mode)
|
2011-08-08 21:12:51 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
const float range_inv = 1.0f / (max_d - min_d); /* invert since multiplication is faster */
|
|
|
|
unsigned int i = nidx;
|
2012-03-24 06:24:53 +00:00
|
|
|
if (max_d == min_d) {
|
2011-09-08 07:36:59 +00:00
|
|
|
while (i-- > 0) {
|
|
|
|
weights[i] = (weights[i] >= max_d) ? 1.0f : 0.0f; /* "Step" behavior... */
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
else if (max_d > min_d) {
|
2011-09-08 07:36:59 +00:00
|
|
|
while (i-- > 0) {
|
2012-05-06 13:38:33 +00:00
|
|
|
if (weights[i] >= max_d) weights[i] = 1.0f; /* most likely case first */
|
|
|
|
else if (weights[i] <= min_d) weights[i] = 0.0f;
|
|
|
|
else weights[i] = (weights[i] - min_d) * range_inv;
|
2011-09-08 07:36:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (i-- > 0) {
|
2012-05-06 13:38:33 +00:00
|
|
|
if (weights[i] <= max_d) weights[i] = 1.0f; /* most likely case first */
|
|
|
|
else if (weights[i] >= min_d) weights[i] = 0.0f;
|
|
|
|
else weights[i] = (weights[i] - min_d) * range_inv;
|
2011-09-08 07:36:59 +00:00
|
|
|
}
|
2011-09-05 03:53:26 +00:00
|
|
|
}
|
2011-08-08 21:12:51 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (!ELEM(mode, MOD_WVG_MAPPING_NONE, MOD_WVG_MAPPING_CURVE)) {
|
2013-04-15 23:12:40 +00:00
|
|
|
RNG *rng = NULL;
|
|
|
|
|
2018-05-07 18:15:27 +02:00
|
|
|
if (mode == MOD_WVG_MAPPING_RANDOM) {
|
2013-08-04 03:45:30 +00:00
|
|
|
rng = BLI_rng_new_srandom(BLI_ghashutil_strhash(ob->id.name + 2));
|
2018-05-07 18:15:27 +02:00
|
|
|
}
|
2013-04-15 23:12:40 +00:00
|
|
|
|
|
|
|
weightvg_do_map(nidx, weights, mode, NULL, 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-09-05 16:16:00 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-08 21:12:51 +00:00
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
/**************************************
|
|
|
|
* Modifiers functions. *
|
|
|
|
**************************************/
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2011-07-28 01:38:48 +00:00
|
|
|
wmd->proximity_mode = MOD_WVG_PROXIMITY_OBJECT;
|
|
|
|
wmd->proximity_flags = MOD_WVG_PROXIMITY_GEOM_VERTS;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2011-09-07 07:46:26 +00:00
|
|
|
wmd->falloff_type = MOD_WVG_MAPPING_NONE;
|
2011-09-05 16:16:00 +00:00
|
|
|
|
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;
|
2011-09-05 03:09:49 +00:00
|
|
|
wmd->max_dist = 1.0f; /* vert arbitrary distance, but don't use 0 */
|
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
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) 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
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) 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);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
|
2017-01-31 09:47:59 +01:00
|
|
|
walk(userData, ob, &wmd->proximity_ob_target, IDWALK_CB_NOP);
|
|
|
|
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
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) 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
|
|
|
{
|
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *)md;
|
|
|
|
if (wmd->proximity_ob_target != NULL) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, wmd->proximity_ob_target, DEG_OB_COMP_TRANSFORM, "WeightVGProximity Modifier");
|
|
|
|
DEG_add_object_relation(ctx->node, wmd->proximity_ob_target, DEG_OB_COMP_GEOMETRY, "WeightVGProximity 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
|
|
|
}
|
|
|
|
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, "WeightVGProximity Modifier");
|
|
|
|
DEG_add_object_relation(ctx->node, wmd->mask_tex_map_obj, DEG_OB_COMP_GEOMETRY, "WeightVGProximity Modifier");
|
2019-02-05 10:04:09 +01:00
|
|
|
}
|
|
|
|
if (wmd->mask_texture != NULL) {
|
|
|
|
DEG_add_generic_id_relation(ctx->node, &wmd->mask_texture->id, "WeightVGProximity 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-12 12:01:17 +01:00
|
|
|
DEG_add_modifier_to_transform_relation(ctx->node, "WeightVGProximity 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
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
|
2011-07-25 15:27:01 +00:00
|
|
|
/* If no vertex group, bypass. */
|
2011-09-05 05:28:32 +00:00
|
|
|
if (wmd->defgrp_name[0] == '\0') return 1;
|
2011-07-25 15:27:01 +00:00
|
|
|
/* If no target object, bypass. */
|
|
|
|
return (wmd->proximity_ob_target == NULL);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-05-08 12:58:01 +02:00
|
|
|
BLI_assert(mesh != NULL);
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
|
2011-07-25 15:27:01 +00:00
|
|
|
MDeformVert *dvert = NULL;
|
2011-09-15 17:28:18 +00:00
|
|
|
MDeformWeight **dw, **tdw;
|
2011-07-25 15:27:01 +00:00
|
|
|
float (*v_cos)[3] = NULL; /* The vertices coordinates. */
|
2018-05-01 17:33:04 +02:00
|
|
|
Object *ob = ctx->object;
|
2011-07-27 18:48:23 +00:00
|
|
|
Object *obr = NULL; /* Our target object. */
|
2012-10-22 17:19:05 +00:00
|
|
|
int defgrp_index;
|
2011-07-25 15:27:01 +00:00
|
|
|
float *tw = NULL;
|
|
|
|
float *org_w = NULL;
|
2012-05-06 13:38:33 +00:00
|
|
|
float *new_w = NULL;
|
2011-07-25 15:27:01 +00:00
|
|
|
int *tidx, *indices = NULL;
|
|
|
|
int numIdx = 0;
|
2011-09-15 17:28:18 +00:00
|
|
|
int i;
|
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
|
|
|
/* Flags. */
|
|
|
|
#if 0
|
2015-04-20 23:37:04 +10: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-12-19 14:09:36 +00:00
|
|
|
|
2013-09-03 21:22:43 +00:00
|
|
|
#ifdef USE_TIMEIT
|
|
|
|
TIMEIT_START(perf);
|
2011-12-19 14:09:36 +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 our target object. */
|
2018-12-07 15:45:53 +01:00
|
|
|
obr = DEG_get_evaluated_object(ctx->depsgraph, wmd->proximity_ob_target);
|
2018-05-07 18:15:27 +02:00
|
|
|
if (obr == NULL) {
|
|
|
|
return mesh;
|
|
|
|
}
|
2011-07-27 18:48:23 +00:00
|
|
|
|
|
|
|
/* Get vgroup idx from its name. */
|
2012-10-22 17:19:05 +00:00
|
|
|
defgrp_index = defgroup_name_index(ob, wmd->defgrp_name);
|
2018-05-07 18:15:27 +02:00
|
|
|
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);
|
|
|
|
/* If no vertices were ever added to an object's vgroup, dvert might be NULL. */
|
|
|
|
/* As this modifier never add vertices to vgroup, just return. */
|
|
|
|
if (!has_mdef) {
|
|
|
|
return mesh;
|
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
|
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
|
|
|
/* Ultimate security check. */
|
|
|
|
if (!dvert) {
|
|
|
|
return mesh;
|
|
|
|
}
|
2018-08-08 20:13:17 +02:00
|
|
|
mesh->dvert = dvert;
|
2018-05-07 18:15:27 +02:00
|
|
|
|
|
|
|
/* Find out which vertices to work on (all vertices in vgroup), and get their relevant weight. */
|
2018-01-14 22:14:20 +01:00
|
|
|
tidx = MEM_malloc_arrayN(numVerts, sizeof(int), "WeightVGProximity Modifier, tidx");
|
|
|
|
tw = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGProximity Modifier, tw");
|
|
|
|
tdw = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGProximity Modifier, tdw");
|
2011-07-25 15:27:01 +00:00
|
|
|
for (i = 0; i < numVerts; i++) {
|
2012-10-22 17:19:05 +00:00
|
|
|
MDeformWeight *_dw = defvert_find_index(&dvert[i], defgrp_index);
|
2012-03-24 06:24:53 +00:00
|
|
|
if (_dw) {
|
2011-09-15 17:28:18 +00:00
|
|
|
tidx[numIdx] = i;
|
|
|
|
tw[numIdx] = _dw->weight;
|
|
|
|
tdw[numIdx++] = _dw;
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-15 17:28:18 +00:00
|
|
|
/* If no vertices found, return org data! */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (numIdx == 0) {
|
2011-09-15 17:28:18 +00:00
|
|
|
MEM_freeN(tidx);
|
|
|
|
MEM_freeN(tw);
|
|
|
|
MEM_freeN(tdw);
|
2018-05-07 18:15:27 +02:00
|
|
|
return mesh;
|
2011-09-15 17:28:18 +00:00
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
if (numIdx != numVerts) {
|
2018-01-14 22:14:20 +01:00
|
|
|
indices = MEM_malloc_arrayN(numIdx, sizeof(int), "WeightVGProximity Modifier, indices");
|
2011-12-22 14:04:25 +00:00
|
|
|
memcpy(indices, tidx, sizeof(int) * numIdx);
|
2018-01-14 22:14:20 +01:00
|
|
|
org_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGProximity Modifier, org_w");
|
2011-12-22 14:04:25 +00:00
|
|
|
memcpy(org_w, tw, sizeof(float) * numIdx);
|
2018-01-14 22:14:20 +01:00
|
|
|
dw = MEM_malloc_arrayN(numIdx, sizeof(MDeformWeight *), "WeightVGProximity Modifier, dw");
|
2012-05-06 13:38:33 +00:00
|
|
|
memcpy(dw, tdw, sizeof(MDeformWeight *) * numIdx);
|
2011-12-22 14:04:25 +00:00
|
|
|
MEM_freeN(tw);
|
|
|
|
MEM_freeN(tdw);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
org_w = tw;
|
|
|
|
dw = tdw;
|
|
|
|
}
|
2018-01-14 22:14:20 +01:00
|
|
|
new_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGProximity Modifier, new_w");
|
2011-07-25 15:27:01 +00:00
|
|
|
MEM_freeN(tidx);
|
|
|
|
|
|
|
|
/* Get our vertex coordinates. */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (numIdx != numVerts) {
|
2018-08-08 20:13:17 +02:00
|
|
|
float (*tv_cos)[3] = BKE_mesh_vertexCos_get(mesh, NULL);
|
2018-05-07 18:15:27 +02:00
|
|
|
v_cos = MEM_malloc_arrayN(numIdx, sizeof(float[3]), "WeightVGProximity Modifier, v_cos");
|
|
|
|
for (i = 0; i < numIdx; i++) {
|
2011-12-18 21:46:26 +00:00
|
|
|
copy_v3_v3(v_cos[i], tv_cos[indices[i]]);
|
2018-05-07 18:15:27 +02:00
|
|
|
}
|
2011-12-18 21:46:26 +00:00
|
|
|
MEM_freeN(tv_cos);
|
|
|
|
}
|
2018-05-07 18:15:27 +02:00
|
|
|
else {
|
2018-08-08 20:13:17 +02:00
|
|
|
v_cos = BKE_mesh_vertexCos_get(mesh, NULL);
|
2018-05-07 18:15:27 +02:00
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
/* Compute wanted distances. */
|
2011-07-28 01:38:48 +00:00
|
|
|
if (wmd->proximity_mode == MOD_WVG_PROXIMITY_OBJECT) {
|
2011-09-15 17:28:18 +00:00
|
|
|
const float dist = get_ob2ob_distance(ob, obr);
|
2018-05-07 18:15:27 +02:00
|
|
|
for (i = 0; i < numIdx; i++) {
|
2011-07-25 15:27:01 +00:00
|
|
|
new_w[i] = dist;
|
2018-05-07 18:15:27 +02:00
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
2011-07-28 01:38:48 +00:00
|
|
|
else if (wmd->proximity_mode == MOD_WVG_PROXIMITY_GEOMETRY) {
|
2016-04-25 14:57:25 +10:00
|
|
|
const bool use_trgt_verts = (wmd->proximity_flags & MOD_WVG_PROXIMITY_GEOM_VERTS) != 0;
|
|
|
|
const bool use_trgt_edges = (wmd->proximity_flags & MOD_WVG_PROXIMITY_GEOM_EDGES) != 0;
|
|
|
|
const bool use_trgt_faces = (wmd->proximity_flags & MOD_WVG_PROXIMITY_GEOM_FACES) != 0;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
|
|
|
if (use_trgt_verts || use_trgt_edges || use_trgt_faces) {
|
2019-02-11 20:20:12 +01:00
|
|
|
Mesh *target_mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(obr, false);
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2018-05-07 18:15:27 +02:00
|
|
|
/* We must check that we do have a valid target_mesh! */
|
2018-05-08 12:58:01 +02:00
|
|
|
if (target_mesh != NULL) {
|
2011-07-25 15:27:01 +00:00
|
|
|
SpaceTransform loc2trgt;
|
2018-01-14 22:14:20 +01:00
|
|
|
float *dists_v = use_trgt_verts ? MEM_malloc_arrayN(numIdx, sizeof(float), "dists_v") : NULL;
|
|
|
|
float *dists_e = use_trgt_edges ? MEM_malloc_arrayN(numIdx, sizeof(float), "dists_e") : NULL;
|
|
|
|
float *dists_f = use_trgt_faces ? MEM_malloc_arrayN(numIdx, sizeof(float), "dists_f") : NULL;
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2014-08-01 16:28:31 +02:00
|
|
|
BLI_SPACE_TRANSFORM_SETUP(&loc2trgt, ob, obr);
|
2011-07-25 15:27:01 +00:00
|
|
|
get_vert2geom_distance(numIdx, v_cos, dists_v, dists_e, dists_f,
|
2018-05-07 18:15:27 +02:00
|
|
|
target_mesh, &loc2trgt);
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0; i < numIdx; i++) {
|
2011-07-25 15:27:01 +00:00
|
|
|
new_w[i] = dists_v ? dists_v[i] : FLT_MAX;
|
2012-03-24 06:24:53 +00:00
|
|
|
if (dists_e)
|
2012-10-23 13:28:22 +00:00
|
|
|
new_w[i] = min_ff(dists_e[i], new_w[i]);
|
2012-03-24 06:24:53 +00:00
|
|
|
if (dists_f)
|
2012-10-23 13:28:22 +00:00
|
|
|
new_w[i] = min_ff(dists_f[i], new_w[i]);
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
2018-05-07 18:15:27 +02:00
|
|
|
|
|
|
|
MEM_SAFE_FREE(dists_v);
|
|
|
|
MEM_SAFE_FREE(dists_e);
|
|
|
|
MEM_SAFE_FREE(dists_f);
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
/* Else, fall back to default obj2vert behavior. */
|
2011-07-28 01:38:48 +00:00
|
|
|
else {
|
2011-07-25 15:27:01 +00:00
|
|
|
get_vert2ob_distance(numIdx, v_cos, new_w, ob, obr);
|
2011-07-28 01:38:48 +00:00
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
2011-07-28 01:38:48 +00:00
|
|
|
else {
|
2011-07-25 15:27:01 +00:00
|
|
|
get_vert2ob_distance(numIdx, v_cos, new_w, ob, obr);
|
2011-07-28 01:38:48 +00:00
|
|
|
}
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
2011-09-08 07:36:59 +00:00
|
|
|
/* Map distances to weights. */
|
2013-04-15 23:12:40 +00:00
|
|
|
do_map(ob, new_w, numIdx, wmd->min_dist, wmd->max_dist, wmd->falloff_type);
|
2011-09-08 07:36:59 +00: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, numIdx, indices, org_w, new_w, ob, 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 vgroup. Note we never add nor remove vertices from vgroup here. */
|
2014-03-20 22:56:28 +11:00
|
|
|
weightvg_update_vg(dvert, defgrp_index, dw, numIdx, indices, org_w, false, 0.0f, false, 0.0f);
|
2011-07-25 15:27:01 +00: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
|
|
|
/* 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, numIdx, indices);
|
|
|
|
#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-09-05 05:28:32 +00:00
|
|
|
MEM_freeN(v_cos);
|
2018-05-07 18:15:27 +02:00
|
|
|
MEM_SAFE_FREE(indices);
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2013-09-03 21:22:43 +00:00
|
|
|
#ifdef USE_TIMEIT
|
|
|
|
TIMEIT_END(perf);
|
2011-12-19 14:09:36 +00:00
|
|
|
#endif
|
|
|
|
|
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_WeightVGProximity = {
|
2011-09-07 07:46:26 +00:00
|
|
|
/* name */ "VertexWeightProximity",
|
2011-07-25 15:27:01 +00:00
|
|
|
/* structName */ "WeightVGProximityModifierData",
|
|
|
|
/* structSize */ sizeof(WeightVGProximityModifierData),
|
2011-12-20 14:15:59 +00:00
|
|
|
/* type */ eModifierTypeType_NonGeometrical,
|
2012-05-03 21:35:04 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
|
|
|
eModifierTypeFlag_SupportsMapping |
|
|
|
|
eModifierTypeFlag_SupportsEditmode |
|
|
|
|
eModifierTypeFlag_UsesPreview,
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2018-05-08 15:04:10 +02:00
|
|
|
/* copyData */ modifier_copyData_generic,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
|
|
|
/* deformVerts_DM */ NULL,
|
|
|
|
/* deformMatrices_DM */ NULL,
|
|
|
|
/* deformVertsEM_DM */ NULL,
|
|
|
|
/* deformMatricesEM_DM*/NULL,
|
2018-05-07 18:15:27 +02:00
|
|
|
/* applyModifier_DM */ NULL,
|
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,
|
2018-04-04 14:56:32 +02:00
|
|
|
/* freeData */ NULL,
|
2011-07-25 15:27:01 +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,
|
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,
|
2011-07-25 15:27:01 +00:00
|
|
|
};
|