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:39:14 +01:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_math.h"
|
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
2011-12-24 03:03:42 +00:00
|
|
|
|
2018-05-08 16:42:01 +02:00
|
|
|
#include "BKE_editmesh.h"
|
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_mesh.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_particle.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_deform.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
#include "MOD_util.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
SmoothModifierData *smd = (SmoothModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
smd->fac = 0.5f;
|
|
|
|
smd->repeat = 1;
|
|
|
|
smd->flag = MOD_SMOOTH_X | MOD_SMOOTH_Y | MOD_SMOOTH_Z;
|
|
|
|
smd->defgrp_name[0] = '\0';
|
|
|
|
}
|
|
|
|
|
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
|
|
|
SmoothModifierData *smd = (SmoothModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
short flag;
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
flag = smd->flag & (MOD_SMOOTH_X | MOD_SMOOTH_Y | MOD_SMOOTH_Z);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* disable if modifier is off for X, Y and Z or if factor is 0 */
|
2012-03-24 06:24:53 +00:00
|
|
|
if ((smd->fac == 0.0f) || flag == 0) return 1;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
SmoothModifierData *smd = (SmoothModifierData *)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 (smd->defgrp_name[0] != '\0') {
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void smoothModifier_do(
|
2018-05-08 16:42:01 +02:00
|
|
|
SmoothModifierData *smd, Object *ob, Mesh *mesh,
|
2012-05-06 13:38:33 +00:00
|
|
|
float (*vertexCos)[3], int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
MDeformVert *dvert = NULL;
|
|
|
|
MEdge *medges = NULL;
|
|
|
|
|
|
|
|
int i, j, numDMEdges, defgrp_index;
|
|
|
|
unsigned char *uctmp;
|
|
|
|
float *ftmp, fac, facm;
|
|
|
|
|
2018-01-14 22:14:20 +01:00
|
|
|
ftmp = (float *)MEM_calloc_arrayN(numVerts, 3 * sizeof(float),
|
2012-05-06 13:38:33 +00:00
|
|
|
"smoothmodifier_f");
|
2010-04-11 22:12:30 +00:00
|
|
|
if (!ftmp) return;
|
2018-01-14 22:14:20 +01:00
|
|
|
uctmp = (unsigned char *)MEM_calloc_arrayN(numVerts, sizeof(unsigned char),
|
2012-05-06 13:38:33 +00:00
|
|
|
"smoothmodifier_uc");
|
2010-04-11 22:12:30 +00:00
|
|
|
if (!uctmp) {
|
|
|
|
if (ftmp) MEM_freeN(ftmp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fac = smd->fac;
|
|
|
|
facm = 1 - fac;
|
|
|
|
|
2018-11-27 14:26:43 +01:00
|
|
|
if (mesh != NULL) {
|
2018-05-08 16:42:01 +02:00
|
|
|
medges = mesh->medge;
|
|
|
|
numDMEdges = mesh->totedge;
|
2012-06-08 08:17:34 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
medges = NULL;
|
|
|
|
numDMEdges = 0;
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-06-29 19:02:19 +02:00
|
|
|
MOD_get_vgroup(ob, mesh, smd->defgrp_name, &dvert, &defgrp_index);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* NOTICE: this can be optimized a little bit by moving the
|
2012-03-09 18:28:30 +00:00
|
|
|
* if (dvert) out of the loop, if needed */
|
2010-04-11 22:12:30 +00:00
|
|
|
for (j = 0; j < smd->repeat; j++) {
|
|
|
|
for (i = 0; i < numDMEdges; i++) {
|
|
|
|
float fvec[3];
|
|
|
|
float *v1, *v2;
|
|
|
|
unsigned int idx1, idx2;
|
|
|
|
|
|
|
|
idx1 = medges[i].v1;
|
|
|
|
idx2 = medges[i].v2;
|
|
|
|
|
|
|
|
v1 = vertexCos[idx1];
|
|
|
|
v2 = vertexCos[idx2];
|
|
|
|
|
2011-03-27 13:49:53 +00:00
|
|
|
mid_v3_v3v3(fvec, v1, v2);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
v1 = &ftmp[idx1 * 3];
|
|
|
|
v2 = &ftmp[idx2 * 3];
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
if (uctmp[idx1] < 255) {
|
|
|
|
uctmp[idx1]++;
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(v1, fvec);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
if (uctmp[idx2] < 255) {
|
|
|
|
uctmp[idx2]++;
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(v2, fvec);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dvert) {
|
2012-05-06 13:38:33 +00:00
|
|
|
MDeformVert *dv = dvert;
|
2011-12-14 22:54:38 +00:00
|
|
|
for (i = 0; i < numVerts; i++, dv++) {
|
2010-04-11 22:12:30 +00:00
|
|
|
float f, fm, facw, *fp, *v;
|
|
|
|
short flag = smd->flag;
|
|
|
|
|
|
|
|
v = vertexCos[i];
|
2012-05-06 13:38:33 +00:00
|
|
|
fp = &ftmp[i * 3];
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
f = defvert_find_weight(dv, defgrp_index);
|
2011-12-14 22:54:38 +00:00
|
|
|
if (f <= 0.0f) continue;
|
|
|
|
|
|
|
|
f *= fac;
|
2010-04-11 22:12:30 +00:00
|
|
|
fm = 1.0f - f;
|
|
|
|
|
|
|
|
/* fp is the sum of uctmp[i] verts, so must be averaged */
|
|
|
|
facw = 0.0f;
|
2018-06-17 17:04:27 +02:00
|
|
|
if (uctmp[i])
|
2010-04-11 22:12:30 +00:00
|
|
|
facw = f / (float)uctmp[i];
|
|
|
|
|
|
|
|
if (flag & MOD_SMOOTH_X)
|
|
|
|
v[0] = fm * v[0] + facw * fp[0];
|
|
|
|
if (flag & MOD_SMOOTH_Y)
|
|
|
|
v[1] = fm * v[1] + facw * fp[1];
|
|
|
|
if (flag & MOD_SMOOTH_Z)
|
|
|
|
v[2] = fm * v[2] + facw * fp[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* no vertex group */
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
float facw, *fp, *v;
|
|
|
|
short flag = smd->flag;
|
|
|
|
|
|
|
|
v = vertexCos[i];
|
2012-05-06 13:38:33 +00:00
|
|
|
fp = &ftmp[i * 3];
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* fp is the sum of uctmp[i] verts, so must be averaged */
|
|
|
|
facw = 0.0f;
|
2018-06-17 17:04:27 +02:00
|
|
|
if (uctmp[i])
|
2010-04-11 22:12:30 +00:00
|
|
|
facw = fac / (float)uctmp[i];
|
|
|
|
|
|
|
|
if (flag & MOD_SMOOTH_X)
|
|
|
|
v[0] = facm * v[0] + facw * fp[0];
|
|
|
|
if (flag & MOD_SMOOTH_Y)
|
|
|
|
v[1] = facm * v[1] + facw * fp[1];
|
|
|
|
if (flag & MOD_SMOOTH_Z)
|
|
|
|
v[2] = facm * v[2] + facw * fp[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
memset(ftmp, 0, 3 * sizeof(float) * numVerts);
|
|
|
|
memset(uctmp, 0, sizeof(unsigned char) * numVerts);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(ftmp);
|
|
|
|
MEM_freeN(uctmp);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
float (*vertexCos)[3], int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-11-27 14:26:43 +01:00
|
|
|
SmoothModifierData *smd = (SmoothModifierData *)md;
|
|
|
|
Mesh *mesh_src = NULL;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-11-27 20:10:41 +01:00
|
|
|
/* mesh_src is needed for vgroups, and taking edges into account. */
|
|
|
|
mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-11-27 14:26:43 +01:00
|
|
|
smoothModifier_do(smd, ctx->object, mesh_src, vertexCos, numVerts);
|
2018-05-08 16:42:01 +02:00
|
|
|
|
2018-11-27 14:26:43 +01:00
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void deformVertsEM(
|
2018-05-01 17:33:04 +02:00
|
|
|
ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData,
|
2018-05-08 16:42:01 +02:00
|
|
|
Mesh *mesh, float (*vertexCos)[3], int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-11-27 14:26:43 +01:00
|
|
|
SmoothModifierData *smd = (SmoothModifierData *)md;
|
2018-11-27 20:10:41 +01:00
|
|
|
Mesh *mesh_src = NULL;
|
2018-05-08 16:42:01 +02:00
|
|
|
|
2018-11-27 20:10:41 +01:00
|
|
|
/* mesh_src is needed for vgroups, and taking edges into account. */
|
|
|
|
mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
|
2018-05-08 16:42:01 +02:00
|
|
|
|
2018-11-27 14:26:43 +01:00
|
|
|
smoothModifier_do(smd, ctx->object, mesh_src, vertexCos, numVerts);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-11-27 14:26:43 +01:00
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
2018-05-08 16:42:01 +02:00
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_Smooth = {
|
|
|
|
/* name */ "Smooth",
|
|
|
|
/* structName */ "SmoothModifierData",
|
|
|
|
/* structSize */ sizeof(SmoothModifierData),
|
|
|
|
/* type */ eModifierTypeType_OnlyDeform,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
2012-10-24 05:45:54 +00:00
|
|
|
eModifierTypeFlag_AcceptsCVs |
|
2012-05-06 13:38:33 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-05-08 15:04:10 +02:00
|
|
|
/* copyData */ modifier_copyData_generic,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2018-05-08 16:42:01 +02:00
|
|
|
/* deformVerts */ deformVerts,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformMatrices */ NULL,
|
2018-05-08 16:42:01 +02:00
|
|
|
/* deformVertsEM */ deformVertsEM,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformMatricesEM */ NULL,
|
|
|
|
/* applyModifier */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* freeData */ NULL,
|
2010-04-11 22:12:30 +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 */ NULL,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
/* foreachObjectLink */ NULL,
|
|
|
|
/* foreachIDLink */ NULL,
|
2011-08-12 18:11:22 +00:00
|
|
|
/* foreachTexLink */ NULL,
|
2019-03-18 15:56:16 +01:00
|
|
|
/* freeRuntimeData */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|