2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 by the Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup modifiers
|
2011-02-25 13:57:17 +00:00
|
|
|
*/
|
|
|
|
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_task.h"
|
|
|
|
|
2018-05-08 11:33:31 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2014-04-15 18:36:24 +06:00
|
|
|
#include "DNA_scene_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
#include "BKE_global.h"
|
2018-05-08 11:33:31 +02:00
|
|
|
#include "BKE_library.h"
|
2015-10-08 14:21:11 +02:00
|
|
|
#include "BKE_library_query.h"
|
2018-05-08 11:33:31 +02:00
|
|
|
#include "BKE_mesh.h"
|
2018-12-07 11:17:25 +01:00
|
|
|
#include "BKE_mesh_runtime.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_deform.h"
|
2013-04-13 20:31:52 +00:00
|
|
|
#include "BKE_editmesh.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-02-13 20:35:29 +11:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-06-22 15:03:42 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2018-02-13 20:35:29 +11:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "MOD_util.h"
|
|
|
|
|
2014-10-21 11:37:29 +02:00
|
|
|
#ifdef __SSE2__
|
|
|
|
# include <emmintrin.h>
|
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
mmd->gridsize = 5;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void freeData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (mmd->bindinfluences) MEM_freeN(mmd->bindinfluences);
|
|
|
|
if (mmd->bindoffsets) MEM_freeN(mmd->bindoffsets);
|
|
|
|
if (mmd->bindcagecos) MEM_freeN(mmd->bindcagecos);
|
|
|
|
if (mmd->dyngrid) MEM_freeN(mmd->dyngrid);
|
|
|
|
if (mmd->dyninfluences) MEM_freeN(mmd->dyninfluences);
|
|
|
|
if (mmd->dynverts) MEM_freeN(mmd->dynverts);
|
2012-05-06 13:38:33 +00:00
|
|
|
if (mmd->bindweights) MEM_freeN(mmd->bindweights); /* deprecated */
|
|
|
|
if (mmd->bindcos) MEM_freeN(mmd->bindcos); /* deprecated */
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 12:45:30 +02:00
|
|
|
static void copyData(const ModifierData *md, ModifierData *target, const int flag)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-08 15:04:10 +02:00
|
|
|
const MeshDeformModifierData *mmd = (const MeshDeformModifierData *) md;
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *tmmd = (MeshDeformModifierData *) target;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-07-04 12:45:30 +02:00
|
|
|
modifier_copyData_generic(md, target, flag);
|
2014-11-18 11:28:40 +01:00
|
|
|
|
|
|
|
if (mmd->bindinfluences) tmmd->bindinfluences = MEM_dupallocN(mmd->bindinfluences);
|
|
|
|
if (mmd->bindoffsets) tmmd->bindoffsets = MEM_dupallocN(mmd->bindoffsets);
|
|
|
|
if (mmd->bindcagecos) tmmd->bindcagecos = MEM_dupallocN(mmd->bindcagecos);
|
|
|
|
if (mmd->dyngrid) tmmd->dyngrid = MEM_dupallocN(mmd->dyngrid);
|
|
|
|
if (mmd->dyninfluences) tmmd->dyninfluences = MEM_dupallocN(mmd->dyninfluences);
|
|
|
|
if (mmd->dynverts) tmmd->dynverts = MEM_dupallocN(mmd->dynverts);
|
2017-06-19 12:55:11 +02:00
|
|
|
if (mmd->bindweights) tmmd->bindweights = MEM_dupallocN(mmd->bindweights); /* deprecated */
|
|
|
|
if (mmd->bindcos) tmmd->bindcos = MEM_dupallocN(mmd->bindcos); /* deprecated */
|
2010-04-11 22:12:30 +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)
|
2018-06-17 17:04:27 +02:00
|
|
|
{
|
2010-04-11 22:12:30 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
|
|
|
|
|
|
|
/* ask for vertexgroups 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 (mmd->defgrp_name[0] != '\0') {
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 12:14:08 +02:00
|
|
|
static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
return !mmd->object;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foreachObjectLink(
|
2012-08-23 16:17:47 +00:00
|
|
|
ModifierData *md, Object *ob,
|
2015-10-05 15:57:10 +02:00
|
|
|
ObjectWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2017-01-31 09:47:59 +01:00
|
|
|
walk(userData, ob, &mmd->object, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 12:54:06 +01:00
|
|
|
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
{
|
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
|
|
|
if (mmd->object != NULL) {
|
|
|
|
/* TODO(sergey): Do we need transform component here? */
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, mmd->object, DEG_OB_COMP_GEOMETRY, "Mesh Deform 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-30 11:08:33 +11:00
|
|
|
static float meshdeform_dynamic_bind(MeshDeformModifierData *mmd, float (*dco)[3], float vec[3])
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
MDefCell *cell;
|
|
|
|
MDefInfluence *inf;
|
2014-10-21 11:37:29 +02:00
|
|
|
float gridvec[3], dvec[3], ivec[3], wx, wy, wz;
|
2010-04-11 22:12:30 +00:00
|
|
|
float weight, cageweight, totweight, *cageco;
|
|
|
|
int i, j, a, x, y, z, size;
|
2014-10-21 11:37:29 +02:00
|
|
|
#ifdef __SSE2__
|
|
|
|
__m128 co = _mm_setzero_ps();
|
|
|
|
#else
|
|
|
|
float co[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
totweight = 0.0f;
|
|
|
|
size = mmd->dyngridsize;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
gridvec[i] = (vec[i] - mmd->dyncellmin[i] - mmd->dyncellwidth * 0.5f) / mmd->dyncellwidth;
|
2012-05-03 21:35:04 +00:00
|
|
|
ivec[i] = (int)gridvec[i];
|
|
|
|
dvec[i] = gridvec[i] - ivec[i];
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
for (i = 0; i < 8; i++) {
|
2012-05-03 21:35:04 +00:00
|
|
|
if (i & 1) { x = ivec[0] + 1; wx = dvec[0]; }
|
2012-05-06 13:38:33 +00:00
|
|
|
else { x = ivec[0]; wx = 1.0f - dvec[0]; }
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-03 21:35:04 +00:00
|
|
|
if (i & 2) { y = ivec[1] + 1; wy = dvec[1]; }
|
2012-05-06 13:38:33 +00:00
|
|
|
else { y = ivec[1]; wy = 1.0f - dvec[1]; }
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-03 21:35:04 +00:00
|
|
|
if (i & 4) { z = ivec[2] + 1; wz = dvec[2]; }
|
2012-05-06 13:38:33 +00:00
|
|
|
else { z = ivec[2]; wz = 1.0f - dvec[2]; }
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-03 21:35:04 +00:00
|
|
|
CLAMP(x, 0, size - 1);
|
|
|
|
CLAMP(y, 0, size - 1);
|
|
|
|
CLAMP(z, 0, size - 1);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
a = x + y * size + z * size * size;
|
|
|
|
weight = wx * wy * wz;
|
|
|
|
|
|
|
|
cell = &mmd->dyngrid[a];
|
|
|
|
inf = mmd->dyninfluences + cell->offset;
|
|
|
|
for (j = 0; j < cell->totinfluence; j++, inf++) {
|
|
|
|
cageco = dco[inf->vertex];
|
|
|
|
cageweight = weight * inf->weight;
|
2014-10-21 11:37:29 +02:00
|
|
|
#ifdef __SSE2__
|
|
|
|
{
|
|
|
|
__m128 cageweight_r = _mm_set1_ps(cageweight);
|
|
|
|
/* This will load one extra element, this is ok because
|
2014-10-23 10:38:14 +02:00
|
|
|
* we ignore that part of register anyway.
|
2014-10-21 11:37:29 +02:00
|
|
|
*/
|
|
|
|
__m128 cageco_r = _mm_loadu_ps(cageco);
|
|
|
|
co = _mm_add_ps(co,
|
|
|
|
_mm_mul_ps(cageco_r, cageweight_r));
|
|
|
|
}
|
|
|
|
#else
|
2012-05-06 13:38:33 +00:00
|
|
|
co[0] += cageweight * cageco[0];
|
|
|
|
co[1] += cageweight * cageco[1];
|
|
|
|
co[2] += cageweight * cageco[2];
|
2014-10-21 11:37:29 +02:00
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
totweight += cageweight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 11:37:29 +02:00
|
|
|
#ifdef __SSE2__
|
2014-10-23 10:38:14 +02:00
|
|
|
copy_v3_v3(vec, (float *)&co);
|
2014-10-21 11:37:29 +02:00
|
|
|
#else
|
2010-04-12 00:36:50 +00:00
|
|
|
copy_v3_v3(vec, co);
|
2014-10-21 11:37:29 +02:00
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
return totweight;
|
|
|
|
}
|
|
|
|
|
2014-10-22 11:56:52 +02:00
|
|
|
typedef struct MeshdeformUserdata {
|
|
|
|
/*const*/ MeshDeformModifierData *mmd;
|
|
|
|
const MDeformVert *dvert;
|
|
|
|
/*const*/ float (*dco)[3];
|
|
|
|
int defgrp_index;
|
|
|
|
float (*vertexCos)[3];
|
|
|
|
float (*cagemat)[4];
|
|
|
|
float (*icagemat)[3];
|
|
|
|
} MeshdeformUserdata;
|
|
|
|
|
2018-01-10 12:49:51 +01:00
|
|
|
static void meshdeform_vert_task(
|
|
|
|
void *__restrict userdata,
|
|
|
|
const int iter,
|
|
|
|
const ParallelRangeTLS *__restrict UNUSED(tls))
|
2014-10-22 11:56:52 +02:00
|
|
|
{
|
|
|
|
MeshdeformUserdata *data = userdata;
|
|
|
|
/*const*/ MeshDeformModifierData *mmd = data->mmd;
|
|
|
|
const MDeformVert *dvert = data->dvert;
|
|
|
|
const int defgrp_index = data->defgrp_index;
|
|
|
|
const int *offsets = mmd->bindoffsets;
|
2018-06-01 11:02:54 +02:00
|
|
|
const MDefInfluence *__restrict influences = mmd->bindinfluences;
|
|
|
|
/*const*/ float (*__restrict dco)[3] = data->dco;
|
2014-10-22 11:56:52 +02:00
|
|
|
float (*vertexCos)[3] = data->vertexCos;
|
|
|
|
float co[3];
|
|
|
|
float weight, totweight, fac = 1.0f;
|
|
|
|
|
|
|
|
if (mmd->flag & MOD_MDEF_DYNAMIC_BIND)
|
|
|
|
if (!mmd->dynverts[iter])
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (dvert) {
|
|
|
|
fac = defvert_find_weight(&dvert[iter], defgrp_index);
|
|
|
|
|
|
|
|
if (mmd->flag & MOD_MDEF_INVERT_VGROUP) {
|
|
|
|
fac = 1.0f - fac;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fac <= 0.0f) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mmd->flag & MOD_MDEF_DYNAMIC_BIND) {
|
|
|
|
/* transform coordinate into cage's local space */
|
|
|
|
mul_v3_m4v3(co, data->cagemat, vertexCos[iter]);
|
|
|
|
totweight = meshdeform_dynamic_bind(mmd, dco, co);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
totweight = 0.0f;
|
|
|
|
zero_v3(co);
|
2018-06-01 11:02:54 +02:00
|
|
|
int start = offsets[iter];
|
|
|
|
int end = offsets[iter + 1];
|
2014-10-22 11:56:52 +02:00
|
|
|
|
2018-06-01 11:02:54 +02:00
|
|
|
for (int a = start; a < end; a++) {
|
2014-10-22 11:56:52 +02:00
|
|
|
weight = influences[a].weight;
|
|
|
|
madd_v3_v3fl(co, dco[influences[a].vertex], weight);
|
|
|
|
totweight += weight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totweight > 0.0f) {
|
|
|
|
mul_v3_fl(co, fac / totweight);
|
|
|
|
mul_m3_v3(data->icagemat, co);
|
|
|
|
if (G.debug_value != 527)
|
|
|
|
add_v3_v3(vertexCos[iter], co);
|
|
|
|
else
|
|
|
|
copy_v3_v3(vertexCos[iter], co);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
static void meshdeformModifier_do(
|
2018-05-30 11:34:08 +02:00
|
|
|
ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh,
|
2012-08-23 16:17:47 +00:00
|
|
|
float (*vertexCos)[3], int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *) md;
|
2018-05-30 11:34:08 +02:00
|
|
|
Object *ob = ctx->object;
|
|
|
|
|
2018-05-08 11:33:31 +02:00
|
|
|
Mesh *cagemesh;
|
2010-04-11 22:12:30 +00:00
|
|
|
MDeformVert *dvert = NULL;
|
|
|
|
float imat[4][4], cagemat[4][4], iobmat[4][4], icagemat[3][3], cmat[4][4];
|
2018-12-07 11:17:25 +01:00
|
|
|
float co[3], (*dco)[3] = NULL, (*bindcagecos)[3];
|
2014-10-22 11:56:52 +02:00
|
|
|
int a, totvert, totcagevert, defgrp_index;
|
2018-12-07 11:17:25 +01:00
|
|
|
float (*cagecos)[3] = NULL;
|
2014-10-22 11:56:52 +02:00
|
|
|
MeshdeformUserdata data;
|
2010-06-07 14:38:59 +00:00
|
|
|
|
2018-12-07 11:17:25 +01:00
|
|
|
static int recursive_bind_sentinel = 0;
|
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
if (mmd->object == NULL || (mmd->bindcagecos == NULL && mmd->bindfunc == NULL))
|
2010-04-11 22:12:30 +00:00
|
|
|
return;
|
2013-11-04 23:33:23 +00:00
|
|
|
|
2018-06-22 15:52:14 +02:00
|
|
|
/* Get cage mesh.
|
2014-04-15 18:36:24 +06:00
|
|
|
*
|
|
|
|
* Only do this is the target object is in edit mode by itself, meaning
|
|
|
|
* we don't allow linked edit meshes here.
|
2018-10-09 16:52:46 +11:00
|
|
|
* This is because editbmesh_get_mesh_cage_and_final() might easily
|
2014-04-15 18:36:24 +06:00
|
|
|
* conflict with the thread which evaluates object which is in the edit
|
|
|
|
* mode for this mesh.
|
|
|
|
*
|
|
|
|
* We'll support this case once granular dependency graph is landed.
|
|
|
|
*/
|
2019-03-26 11:25:07 +01:00
|
|
|
Object *ob_target = mmd->object;
|
2019-02-11 20:20:12 +01:00
|
|
|
cagemesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(ob_target, false);
|
2018-05-30 11:34:08 +02:00
|
|
|
if (cagemesh == NULL) {
|
2012-10-27 11:12:09 +00:00
|
|
|
modifier_setError(md, "Cannot get mesh from cage object");
|
2010-04-11 22:12:30 +00:00
|
|
|
return;
|
2010-05-26 18:16:16 +00:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* compute matrices to go in and out of cage object space */
|
2018-12-07 15:45:53 +01:00
|
|
|
invert_m4_m4(imat, ob_target->obmat);
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(cagemat, imat, ob->obmat);
|
|
|
|
mul_m4_m4m4(cmat, mmd->bindmat, cagemat);
|
2010-04-11 22:12:30 +00:00
|
|
|
invert_m4_m4(iobmat, cmat);
|
|
|
|
copy_m3_m4(icagemat, iobmat);
|
|
|
|
|
|
|
|
/* bind weights if needed */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (!mmd->bindcagecos) {
|
2010-04-11 22:12:30 +00:00
|
|
|
/* progress bar redraw can make this recursive .. */
|
2019-04-04 14:42:33 +02:00
|
|
|
if (!DEG_is_active(ctx->depsgraph)) {
|
|
|
|
modifier_setError(md, "Attempt to bind from inactive dependency graph");
|
|
|
|
goto finally;
|
|
|
|
}
|
2018-12-07 11:17:25 +01:00
|
|
|
if (!recursive_bind_sentinel) {
|
|
|
|
recursive_bind_sentinel = 1;
|
|
|
|
mmd->bindfunc(mmd, cagemesh, (float *)vertexCos, numVerts, cagemat);
|
|
|
|
recursive_bind_sentinel = 0;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2018-09-26 12:46:34 +02:00
|
|
|
|
2018-12-07 11:17:25 +01:00
|
|
|
goto finally;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* verify we have compatible weights */
|
2012-05-06 13:38:33 +00:00
|
|
|
totvert = numVerts;
|
2018-05-08 11:33:31 +02:00
|
|
|
totcagevert = cagemesh->totvert;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (mmd->totvert != totvert) {
|
2012-10-27 11:12:09 +00:00
|
|
|
modifier_setError(md, "Verts changed from %d to %d", mmd->totvert, totvert);
|
2018-12-07 11:17:25 +01:00
|
|
|
goto finally;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2010-05-26 18:16:16 +00:00
|
|
|
else if (mmd->totcagevert != totcagevert) {
|
2012-10-27 11:12:09 +00:00
|
|
|
modifier_setError(md, "Cage verts changed from %d to %d", mmd->totcagevert, totcagevert);
|
2018-12-07 11:17:25 +01:00
|
|
|
goto finally;
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
else if (mmd->bindcagecos == NULL) {
|
2012-10-27 11:12:09 +00:00
|
|
|
modifier_setError(md, "Bind data missing");
|
2018-12-07 11:17:25 +01:00
|
|
|
goto finally;
|
2010-05-26 18:16:16 +00:00
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* setup deformation data */
|
2018-05-08 11:33:31 +02:00
|
|
|
cagecos = BKE_mesh_vertexCos_get(cagemesh, NULL);
|
2012-05-06 13:38:33 +00:00
|
|
|
bindcagecos = (float(*)[3])mmd->bindcagecos;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2014-10-21 11:37:29 +02:00
|
|
|
/* We allocate 1 element extra to make it possible to
|
|
|
|
* load the values to SSE registers, which are float4.
|
|
|
|
*/
|
2018-01-14 22:14:20 +01:00
|
|
|
dco = MEM_calloc_arrayN((totcagevert + 1), sizeof(*dco), "MDefDco");
|
2014-10-21 11:37:29 +02:00
|
|
|
zero_v3(dco[totcagevert]);
|
2012-05-06 13:38:33 +00:00
|
|
|
for (a = 0; a < totcagevert; a++) {
|
2010-04-11 22:12:30 +00:00
|
|
|
/* get cage vertex in world space with binding transform */
|
2010-06-07 14:38:59 +00:00
|
|
|
copy_v3_v3(co, cagecos[a]);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-08-08 18:21:54 +00:00
|
|
|
if (G.debug_value != 527) {
|
2010-04-11 22:12:30 +00:00
|
|
|
mul_m4_v3(mmd->bindmat, co);
|
|
|
|
/* compute difference with world space bind coord */
|
2010-04-23 11:19:06 +00:00
|
|
|
sub_v3_v3v3(dco[a], co, bindcagecos[a]);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2018-12-07 11:17:25 +01:00
|
|
|
else {
|
2010-04-12 00:36:50 +00:00
|
|
|
copy_v3_v3(dco[a], co);
|
2018-12-07 11:17:25 +01:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-06-29 19:02:19 +02:00
|
|
|
MOD_get_vgroup(ob, mesh, mmd->defgrp_name, &dvert, &defgrp_index);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2014-10-22 11:56:52 +02:00
|
|
|
/* Initialize data to be pass to the for body function. */
|
|
|
|
data.mmd = mmd;
|
|
|
|
data.dvert = dvert;
|
|
|
|
data.dco = dco;
|
|
|
|
data.defgrp_index = defgrp_index;
|
|
|
|
data.vertexCos = vertexCos;
|
|
|
|
data.cagemat = cagemat;
|
|
|
|
data.icagemat = icagemat;
|
|
|
|
|
|
|
|
/* Do deformation. */
|
2018-01-08 11:35:48 +01:00
|
|
|
ParallelRangeSettings settings;
|
|
|
|
BLI_parallel_range_settings_defaults(&settings);
|
2018-01-11 14:51:30 +01:00
|
|
|
settings.min_iter_per_thread = 16;
|
2018-01-08 11:35:48 +01:00
|
|
|
BLI_task_parallel_range(0, totvert,
|
|
|
|
&data,
|
|
|
|
meshdeform_vert_task,
|
|
|
|
&settings);
|
2014-10-22 11:56:52 +02:00
|
|
|
|
2018-12-07 11:17:25 +01:00
|
|
|
finally:
|
|
|
|
MEM_SAFE_FREE(dco);
|
|
|
|
MEM_SAFE_FREE(cagecos);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void deformVerts(
|
2018-05-12 08:21:07 +02:00
|
|
|
ModifierData *md, const ModifierEvalContext *ctx,
|
|
|
|
Mesh *mesh,
|
2018-05-12 08:04:56 +02:00
|
|
|
float (*vertexCos)[3],
|
2018-05-12 08:21:07 +02:00
|
|
|
int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-11-27 17:21:16 +01:00
|
|
|
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-06-29 19:02:19 +02:00
|
|
|
MOD_previous_vcos_store(md, vertexCos); /* if next modifier needs original vertices */
|
2013-11-04 23:33:23 +00:00
|
|
|
|
2018-05-30 11:34:08 +02:00
|
|
|
meshdeformModifier_do(md, ctx, mesh_src, vertexCos, numVerts);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-11-27 20:10:41 +01:00
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
2018-05-08 11:33:31 +02:00
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void deformVertsEM(
|
2018-05-12 08:21:07 +02:00
|
|
|
ModifierData *md, const ModifierEvalContext *ctx,
|
2018-11-27 20:10:41 +01:00
|
|
|
struct BMEditMesh *editData,
|
2018-05-12 08:21:07 +02:00
|
|
|
Mesh *mesh,
|
2018-05-12 08:04:56 +02:00
|
|
|
float (*vertexCos)[3],
|
|
|
|
int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-11-27 20:10:41 +01:00
|
|
|
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-05-30 11:34:08 +02:00
|
|
|
meshdeformModifier_do(md, ctx, mesh_src, vertexCos, numVerts);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-11-27 20:10:41 +01:00
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
2018-05-08 11:33:31 +02:00
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2011-03-27 13:49:53 +00:00
|
|
|
#define MESHDEFORM_MIN_INFLUENCE 0.00001f
|
2010-04-23 11:19:06 +00:00
|
|
|
|
|
|
|
void modifier_mdef_compact_influences(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
|
2010-04-23 11:19:06 +00:00
|
|
|
float weight, *weights, totweight;
|
|
|
|
int totinfluence, totvert, totcagevert, a, b;
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
weights = mmd->bindweights;
|
2012-03-24 06:24:53 +00:00
|
|
|
if (!weights)
|
2010-04-23 11:19:06 +00:00
|
|
|
return;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
totvert = mmd->totvert;
|
|
|
|
totcagevert = mmd->totcagevert;
|
2010-04-23 11:19:06 +00:00
|
|
|
|
|
|
|
/* count number of influences above threshold */
|
2012-05-06 13:38:33 +00:00
|
|
|
for (b = 0; b < totvert; b++) {
|
|
|
|
for (a = 0; a < totcagevert; a++) {
|
|
|
|
weight = weights[a + b * totcagevert];
|
2010-04-23 11:19:06 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (weight > MESHDEFORM_MIN_INFLUENCE)
|
2010-04-23 11:19:06 +00:00
|
|
|
mmd->totinfluence++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate bind influences */
|
2018-01-14 22:14:20 +01:00
|
|
|
mmd->bindinfluences = MEM_calloc_arrayN(mmd->totinfluence, sizeof(MDefInfluence), "MDefBindInfluence");
|
|
|
|
mmd->bindoffsets = MEM_calloc_arrayN((totvert + 1), sizeof(int), "MDefBindOffset");
|
2010-04-23 11:19:06 +00:00
|
|
|
|
|
|
|
/* write influences */
|
2012-05-06 13:38:33 +00:00
|
|
|
totinfluence = 0;
|
2010-04-23 11:19:06 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
for (b = 0; b < totvert; b++) {
|
|
|
|
mmd->bindoffsets[b] = totinfluence;
|
|
|
|
totweight = 0.0f;
|
2010-04-23 11:19:06 +00:00
|
|
|
|
|
|
|
/* sum total weight */
|
2012-05-06 13:38:33 +00:00
|
|
|
for (a = 0; a < totcagevert; a++) {
|
|
|
|
weight = weights[a + b * totcagevert];
|
2010-04-23 11:19:06 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (weight > MESHDEFORM_MIN_INFLUENCE)
|
2010-04-23 11:19:06 +00:00
|
|
|
totweight += weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assign weights normalized */
|
2012-05-06 13:38:33 +00:00
|
|
|
for (a = 0; a < totcagevert; a++) {
|
|
|
|
weight = weights[a + b * totcagevert];
|
2010-04-23 11:19:06 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (weight > MESHDEFORM_MIN_INFLUENCE) {
|
2012-05-03 21:35:04 +00:00
|
|
|
mmd->bindinfluences[totinfluence].weight = weight / totweight;
|
|
|
|
mmd->bindinfluences[totinfluence].vertex = a;
|
2010-04-23 11:19:06 +00:00
|
|
|
totinfluence++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
mmd->bindoffsets[b] = totinfluence;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2010-04-23 11:19:06 +00:00
|
|
|
/* free */
|
|
|
|
MEM_freeN(mmd->bindweights);
|
2012-05-06 13:38:33 +00:00
|
|
|
mmd->bindweights = NULL;
|
2010-04-23 11:19:06 +00:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_MeshDeform = {
|
2012-10-24 05:45:54 +00:00
|
|
|
/* name */ "MeshDeform",
|
|
|
|
/* structName */ "MeshDeformModifierData",
|
|
|
|
/* structSize */ sizeof(MeshDeformModifierData),
|
|
|
|
/* type */ eModifierTypeType_OnlyDeform,
|
|
|
|
/* flags */ eModifierTypeFlag_AcceptsCVs |
|
2016-05-18 22:21:46 +10:00
|
|
|
eModifierTypeFlag_AcceptsLattice |
|
2012-10-24 05:45:54 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
|
|
|
|
|
|
|
/* copyData */ copyData,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2018-05-08 11:33:31 +02:00
|
|
|
/* deformVerts */ deformVerts,
|
2012-10-24 05:45:54 +00:00
|
|
|
/* deformMatrices */ NULL,
|
2018-05-08 11:33:31 +02:00
|
|
|
/* deformVertsEM */ deformVertsEM,
|
2012-10-24 05:45:54 +00:00
|
|
|
/* deformMatricesEM */ NULL,
|
|
|
|
/* applyModifier */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2012-10-24 05:45:54 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
|
|
|
/* freeData */ freeData,
|
|
|
|
/* isDisabled */ isDisabled,
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
/* updateDepsgraph */ updateDepsgraph,
|
2012-10-24 05:45:54 +00:00
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* foreachObjectLink */ foreachObjectLink,
|
2012-10-24 05:45:54 +00:00
|
|
|
/* foreachIDLink */ NULL,
|
|
|
|
/* foreachTexLink */ NULL,
|
2019-03-18 15:56:16 +01:00
|
|
|
/* freeRuntimeData */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|