2011-07-25 15:27:01 +00:00
|
|
|
/*
|
2011-09-07 07:06:43 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2011 by Bastien Montagne.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): None yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*/
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2011-09-22 11:52:42 +00:00
|
|
|
/** \file blender/modifiers/intern/MOD_weightvgproximity.c
|
|
|
|
* \ingroup modifiers
|
2011-07-25 15:27:01 +00:00
|
|
|
*/
|
|
|
|
|
2013-04-15 23:12:40 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
#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"
|
2011-07-25 15:27:01 +00:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_texture.h" /* Texture masking. */
|
|
|
|
|
|
|
|
#include "depsgraph_private.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
|
|
|
#include "DEG_depsgraph_build.h"
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* Data which is localized to each computed chunk (i.e. thread-safe, and with continous subset of index range). */
|
|
|
|
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).
|
|
|
|
*/
|
|
|
|
static void get_vert2geom_distance(int numVerts, float (*v_cos)[3],
|
|
|
|
float *dist_v, float *dist_e, float *dist_f,
|
|
|
|
DerivedMesh *target, const SpaceTransform *loc2trgt)
|
|
|
|
{
|
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. */
|
|
|
|
bvhtree_from_mesh_verts(&treeData_v, target, 0.0, 2, 6);
|
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. */
|
|
|
|
bvhtree_from_mesh_edges(&treeData_e, target, 0.0, 2, 6);
|
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. */
|
2015-07-23 13:20:34 +10:00
|
|
|
bvhtree_from_mesh_looptri(&treeData_f, target, 0.0, 2, 6);
|
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).
|
|
|
|
*/
|
|
|
|
static void get_vert2ob_distance(int numVerts, float (*v_cos)[3], float *dist,
|
2012-05-06 13:38:33 +00:00
|
|
|
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
|
|
|
{
|
2011-07-26 18:51:35 +00: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;
|
|
|
|
|
|
|
|
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));
|
2013-04-15 23:12:40 +00:00
|
|
|
|
|
|
|
weightvg_do_map(nidx, weights, mode, NULL, rng);
|
|
|
|
|
|
|
|
if (rng)
|
|
|
|
BLI_rng_free(rng);
|
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
|
|
|
}
|
|
|
|
|
2013-06-10 18:12:07 +00:00
|
|
|
static void freeData(ModifierData *md)
|
|
|
|
{
|
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
|
|
|
|
if (wmd->mask_texture) {
|
|
|
|
id_us_min(&wmd->mask_texture->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
static void copyData(ModifierData *md, ModifierData *target)
|
|
|
|
{
|
2013-12-22 04:35:52 +11:00
|
|
|
#if 0
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
|
|
|
|
WeightVGProximityModifierData *twmd = (WeightVGProximityModifierData *) target;
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
#endif
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2013-12-22 04:35:52 +11:00
|
|
|
modifier_copyData_generic(md, target);
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
|
2011-07-25 15:27:01 +00:00
|
|
|
CustomDataMask dataMask = 0;
|
|
|
|
|
|
|
|
/* We need vertex groups! */
|
|
|
|
dataMask |= CD_MASK_MDEFORMVERT;
|
|
|
|
|
|
|
|
/* Ask for UV coordinates if we need them. */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (wmd->mask_tex_mapping == MOD_DISP_MAP_UV)
|
2011-07-25 15:27:01 +00:00
|
|
|
dataMask |= CD_MASK_MTFACE;
|
|
|
|
|
2012-03-22 08:41:50 +00:00
|
|
|
/* No need to ask for CD_PREVIEW_MLOOPCOL... */
|
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
|
|
|
|
2011-07-25 15:27:01 +00:00
|
|
|
return dataMask;
|
|
|
|
}
|
|
|
|
|
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 updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
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
|
|
|
DagNode *curNode;
|
|
|
|
|
|
|
|
if (wmd->proximity_ob_target) {
|
2018-02-22 12:54:06 +01:00
|
|
|
curNode = dag_get_node(ctx->forest, wmd->proximity_ob_target);
|
|
|
|
dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
|
2011-07-25 15:27:01 +00:00
|
|
|
"WeightVGProximity Modifier");
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (wmd->mask_tex_map_obj && wmd->mask_tex_mapping == MOD_DISP_MAP_OBJECT) {
|
2018-02-22 12:54:06 +01:00
|
|
|
curNode = dag_get_node(ctx->forest, wmd->mask_tex_map_obj);
|
2011-07-25 15:27:01 +00:00
|
|
|
|
2018-02-22 12:54:06 +01:00
|
|
|
dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
|
2011-07-25 15:27:01 +00:00
|
|
|
"WeightVGProximity Modifier");
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (wmd->mask_tex_mapping == MOD_DISP_MAP_GLOBAL)
|
2018-02-22 12:54:06 +01:00
|
|
|
dag_add_relation(ctx->forest, ctx->obNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
|
2011-07-25 15:27:01 +00:00
|
|
|
"WeightVGProximity Modifier");
|
|
|
|
}
|
|
|
|
|
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");
|
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_mapping == MOD_DISP_MAP_GLOBAL) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "WeightVGProximity Modifier");
|
|
|
|
DEG_add_object_relation(ctx->node, ctx->object, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 03:59:19 +00:00
|
|
|
static bool isDisabled(ModifierData *md, int 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *derivedData,
|
2012-05-09 15:00:26 +00:00
|
|
|
ModifierApplyFlag UNUSED(flag))
|
2011-07-25 15:27:01 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
|
2011-12-19 14:09:36 +00:00
|
|
|
DerivedMesh *dm = derivedData;
|
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
|
|
|
int numVerts;
|
|
|
|
float (*v_cos)[3] = NULL; /* The vertices coordinates. */
|
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. */
|
|
|
|
numVerts = dm->getNumVerts(dm);
|
|
|
|
|
|
|
|
/* Check if we can just return the original mesh.
|
|
|
|
* Must have verts and therefore verts assigned to vgroups to do anything useful!
|
|
|
|
*/
|
2014-02-08 06:07:10 +11:00
|
|
|
if ((numVerts == 0) || BLI_listbase_is_empty(&ob->defbase))
|
2011-07-25 15:27:01 +00:00
|
|
|
return dm;
|
|
|
|
|
2011-07-27 18:48:23 +00:00
|
|
|
/* Get our target object. */
|
|
|
|
obr = wmd->proximity_ob_target;
|
|
|
|
if (obr == NULL)
|
|
|
|
return dm;
|
|
|
|
|
|
|
|
/* Get vgroup idx from its name. */
|
2012-10-22 17:19:05 +00:00
|
|
|
defgrp_index = defgroup_name_index(ob, wmd->defgrp_name);
|
|
|
|
if (defgrp_index == -1)
|
2011-07-27 18:48:23 +00:00
|
|
|
return dm;
|
|
|
|
|
2011-12-19 14:09:36 +00:00
|
|
|
dvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MDEFORMVERT, numVerts);
|
2012-01-22 10:14:01 +00:00
|
|
|
/* 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. */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (!dvert)
|
2012-01-22 10:14:01 +00:00
|
|
|
return dm;
|
2011-07-25 15:27:01 +00: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);
|
|
|
|
return dm;
|
|
|
|
}
|
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. */
|
2018-01-14 22:14:20 +01:00
|
|
|
v_cos = MEM_malloc_arrayN(numIdx, sizeof(float[3]), "WeightVGProximity Modifier, v_cos");
|
2012-03-24 06:24:53 +00:00
|
|
|
if (numIdx != numVerts) {
|
2011-12-18 21:46:26 +00:00
|
|
|
/* XXX In some situations, this code can be up to about 50 times more performant
|
|
|
|
* than simply using getVertCo for each affected vertex...
|
|
|
|
*/
|
2018-01-14 22:14:20 +01:00
|
|
|
float (*tv_cos)[3] = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "WeightVGProximity Modifier, tv_cos");
|
2011-12-19 14:09:36 +00:00
|
|
|
dm->getVertCos(dm, tv_cos);
|
2011-12-18 21:46:26 +00:00
|
|
|
for (i = 0; i < numIdx; i++)
|
|
|
|
copy_v3_v3(v_cos[i], tv_cos[indices[i]]);
|
|
|
|
MEM_freeN(tv_cos);
|
|
|
|
}
|
2011-12-22 14:04:25 +00:00
|
|
|
else
|
|
|
|
dm->getVertCos(dm, v_cos);
|
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);
|
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] = dist;
|
|
|
|
}
|
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) {
|
|
|
|
DerivedMesh *target_dm = obr->derivedFinal;
|
2014-03-20 22:56:28 +11:00
|
|
|
bool free_target_dm = false;
|
2011-07-25 15:27:01 +00:00
|
|
|
if (!target_dm) {
|
2014-07-20 01:30:29 +10:00
|
|
|
if (ELEM(obr->type, OB_CURVE, OB_SURF, OB_FONT))
|
2011-07-25 15:27:01 +00:00
|
|
|
target_dm = CDDM_from_curve(obr);
|
|
|
|
else if (obr->type == OB_MESH) {
|
2012-05-06 13:38:33 +00:00
|
|
|
Mesh *me = (Mesh *)obr->data;
|
2011-09-08 08:18:46 +00:00
|
|
|
if (me->edit_btmesh)
|
2014-01-23 14:50:50 +01:00
|
|
|
target_dm = CDDM_from_editbmesh(me->edit_btmesh, false, false);
|
2011-07-25 15:27:01 +00:00
|
|
|
else
|
2013-12-26 08:26:41 +11:00
|
|
|
target_dm = CDDM_from_mesh(me);
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
2014-03-20 22:56:28 +11:00
|
|
|
free_target_dm = true;
|
2011-07-25 15:27:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We must check that we do have a valid target_dm! */
|
|
|
|
if (target_dm) {
|
|
|
|
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,
|
|
|
|
target_dm, &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
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
if (free_target_dm) target_dm->release(target_dm);
|
|
|
|
if (dists_v) MEM_freeN(dists_v);
|
|
|
|
if (dists_e) MEM_freeN(dists_e);
|
|
|
|
if (dists_f) MEM_freeN(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. */
|
2011-12-19 14:09:36 +00:00
|
|
|
weightvg_do_mask(numIdx, indices, org_w, new_w, ob, dm, wmd->mask_constant,
|
2012-04-10 14:11:45 +00:00
|
|
|
wmd->mask_defgrp_name, wmd->modifier.scene, wmd->mask_texture,
|
|
|
|
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);
|
2012-03-24 06:24:53 +00:00
|
|
|
if (indices)
|
2011-12-22 14:04:25 +00:00
|
|
|
MEM_freeN(indices);
|
2011-09-05 05:28:32 +00:00
|
|
|
MEM_freeN(v_cos);
|
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. */
|
2011-12-19 14:09:36 +00:00
|
|
|
return dm;
|
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
|
|
|
|
|
|
|
/* copyData */ copyData,
|
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
|
|
|
/* applyModifier */ applyModifier,
|
2013-05-02 14:42:05 +00:00
|
|
|
/* applyModifierEM */ NULL,
|
2011-07-25 15:27:01 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
2013-06-10 18:12:07 +00:00
|
|
|
/* freeData */ freeData,
|
2011-07-25 15:27:01 +00:00
|
|
|
/* isDisabled */ isDisabled,
|
|
|
|
/* updateDepgraph */ updateDepgraph,
|
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
|
|
|
};
|