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"
|
|
|
|
|
2012-10-22 15:39:06 +00:00
|
|
|
#include "DNA_object_types.h"
|
2018-05-11 10:55:26 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-12-24 03:03:42 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-10-22 15:39:06 +00:00
|
|
|
#include "BKE_deform.h"
|
2018-05-11 10:55:26 +02:00
|
|
|
#include "BKE_mesh.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-12-20 11:17:45 +01:00
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
2012-10-22 02:39:26 +00:00
|
|
|
#include "bmesh.h"
|
2013-08-23 04:22:07 +00:00
|
|
|
#include "bmesh_tools.h"
|
2012-10-19 10:40:32 +00:00
|
|
|
|
2012-10-22 03:25:53 +00:00
|
|
|
// #define USE_TIMEIT
|
|
|
|
|
2012-10-22 02:09:41 +00:00
|
|
|
#ifdef USE_TIMEIT
|
|
|
|
# include "PIL_time.h"
|
2013-09-03 21:22:43 +00:00
|
|
|
# include "PIL_time_utildefines.h"
|
2012-10-22 02:09:41 +00:00
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-02-13 14:16:36 +00:00
|
|
|
#include "MOD_util.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
DecimateModifierData *dmd = (DecimateModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
dmd->percent = 1.0;
|
2013-01-03 08:09:57 +00:00
|
|
|
dmd->angle = DEG2RADF(5.0f);
|
2015-06-04 19:49:59 +10:00
|
|
|
dmd->defgrp_factor = 1.0;
|
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)
|
2012-10-22 15:39:06 +00:00
|
|
|
{
|
|
|
|
DecimateModifierData *dmd = (DecimateModifierData *) 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 (dmd->defgrp_name[0] != '\0' && (dmd->defgrp_factor > 0.0f)) {
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
2015-06-04 19:49:59 +10:00
|
|
|
}
|
2012-10-22 15:39:06 +00:00
|
|
|
}
|
|
|
|
|
2018-12-20 11:17:45 +01:00
|
|
|
static DecimateModifierData *getOriginalModifierData(
|
|
|
|
const DecimateModifierData *dmd, const ModifierEvalContext *ctx)
|
|
|
|
{
|
|
|
|
Object *ob_orig = DEG_get_original_object(ctx->object);
|
|
|
|
return (DecimateModifierData *)modifiers_findByName(ob_orig, dmd->modifier.name);
|
|
|
|
}
|
|
|
|
|
2018-12-21 16:53:33 +01:00
|
|
|
static void updateFaceCount(
|
2019-01-22 19:49:44 +01:00
|
|
|
const ModifierEvalContext *ctx, DecimateModifierData *dmd, int face_count)
|
2018-12-21 16:53:33 +01:00
|
|
|
{
|
2019-01-22 19:49:44 +01:00
|
|
|
dmd->face_count = face_count;
|
|
|
|
|
2018-12-21 16:53:33 +01:00
|
|
|
if (DEG_is_active(ctx->depsgraph)) {
|
|
|
|
/* update for display only */
|
|
|
|
DecimateModifierData *dmd_orig = getOriginalModifierData(dmd, ctx);
|
|
|
|
dmd_orig->face_count = face_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-12 08:21:07 +02:00
|
|
|
static Mesh *applyModifier(
|
|
|
|
ModifierData *md, const ModifierEvalContext *ctx,
|
|
|
|
Mesh *meshData)
|
2012-10-19 10:40:32 +00:00
|
|
|
{
|
|
|
|
DecimateModifierData *dmd = (DecimateModifierData *) md;
|
2018-05-11 10:55:26 +02:00
|
|
|
Mesh *mesh = meshData, *result = NULL;
|
2012-10-19 10:40:32 +00:00
|
|
|
BMesh *bm;
|
2013-06-02 23:20:49 +00:00
|
|
|
bool calc_face_normal;
|
2012-10-22 15:39:06 +00:00
|
|
|
float *vweights = NULL;
|
|
|
|
|
2012-10-22 02:09:41 +00:00
|
|
|
#ifdef USE_TIMEIT
|
2012-10-23 06:37:58 +00:00
|
|
|
TIMEIT_START(decim);
|
2012-10-22 02:09:41 +00:00
|
|
|
#endif
|
2012-10-20 17:31:07 +00:00
|
|
|
|
2012-10-23 16:21:55 +00:00
|
|
|
/* set up front so we dont show invalid info in the UI */
|
2018-12-21 16:53:33 +01:00
|
|
|
updateFaceCount(ctx, dmd, mesh->totpoly);
|
2012-10-23 16:21:55 +00:00
|
|
|
|
2012-10-23 06:37:58 +00:00
|
|
|
switch (dmd->mode) {
|
|
|
|
case MOD_DECIM_MODE_COLLAPSE:
|
|
|
|
if (dmd->percent == 1.0f) {
|
2018-05-11 10:55:26 +02:00
|
|
|
return mesh;
|
2012-10-23 06:37:58 +00:00
|
|
|
}
|
2013-06-02 23:20:49 +00:00
|
|
|
calc_face_normal = true;
|
2012-10-23 06:37:58 +00:00
|
|
|
break;
|
|
|
|
case MOD_DECIM_MODE_UNSUBDIV:
|
|
|
|
if (dmd->iter == 0) {
|
2018-05-11 10:55:26 +02:00
|
|
|
return mesh;
|
2012-10-23 06:37:58 +00:00
|
|
|
}
|
2013-06-02 23:20:49 +00:00
|
|
|
calc_face_normal = false;
|
2012-10-23 06:37:58 +00:00
|
|
|
break;
|
|
|
|
case MOD_DECIM_MODE_DISSOLVE:
|
|
|
|
if (dmd->angle == 0.0f) {
|
2018-05-11 10:55:26 +02:00
|
|
|
return mesh;
|
2012-10-23 06:37:58 +00:00
|
|
|
}
|
2013-06-02 23:20:49 +00:00
|
|
|
calc_face_normal = true;
|
2012-10-23 06:37:58 +00:00
|
|
|
break;
|
2013-08-06 03:45:11 +00:00
|
|
|
default:
|
2018-05-11 10:55:26 +02:00
|
|
|
return mesh;
|
2012-10-20 17:31:07 +00:00
|
|
|
}
|
2012-10-23 06:37:58 +00:00
|
|
|
|
2012-10-23 16:21:55 +00:00
|
|
|
if (dmd->face_count <= 3) {
|
2012-10-27 11:12:09 +00:00
|
|
|
modifier_setError(md, "Modifier requires more than 3 input faces");
|
2018-05-11 10:55:26 +02:00
|
|
|
return mesh;
|
2012-10-20 17:31:07 +00:00
|
|
|
}
|
|
|
|
|
2012-10-23 04:26:39 +00:00
|
|
|
if (dmd->mode == MOD_DECIM_MODE_COLLAPSE) {
|
2015-06-04 19:49:59 +10:00
|
|
|
if (dmd->defgrp_name[0] && (dmd->defgrp_factor > 0.0f)) {
|
2012-10-23 04:26:39 +00:00
|
|
|
MDeformVert *dvert;
|
|
|
|
int defgrp_index;
|
2012-10-22 15:39:06 +00:00
|
|
|
|
2018-06-29 19:02:19 +02:00
|
|
|
MOD_get_vgroup(ctx->object, mesh, dmd->defgrp_name, &dvert, &defgrp_index);
|
2012-10-22 15:39:06 +00:00
|
|
|
|
2012-10-23 04:26:39 +00:00
|
|
|
if (dvert) {
|
2018-05-11 10:55:26 +02:00
|
|
|
const unsigned int vert_tot = mesh->totvert;
|
2012-10-23 04:26:39 +00:00
|
|
|
unsigned int i;
|
2012-10-22 15:39:06 +00:00
|
|
|
|
2018-01-14 22:14:20 +01:00
|
|
|
vweights = MEM_malloc_arrayN(vert_tot, sizeof(float), __func__);
|
2012-10-22 15:39:06 +00:00
|
|
|
|
2012-10-23 04:26:39 +00:00
|
|
|
if (dmd->flag & MOD_DECIM_FLAG_INVERT_VGROUP) {
|
|
|
|
for (i = 0; i < vert_tot; i++) {
|
2015-06-05 15:26:37 +10:00
|
|
|
vweights[i] = 1.0f - defvert_find_weight(&dvert[i], defgrp_index);
|
2012-10-23 04:26:39 +00:00
|
|
|
}
|
2012-10-22 15:39:06 +00:00
|
|
|
}
|
2012-10-23 04:26:39 +00:00
|
|
|
else {
|
|
|
|
for (i = 0; i < vert_tot; i++) {
|
2015-06-05 15:26:37 +10:00
|
|
|
vweights[i] = defvert_find_weight(&dvert[i], defgrp_index);
|
2012-10-23 04:26:39 +00:00
|
|
|
}
|
2012-10-22 15:39:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 10:55:26 +02:00
|
|
|
bm = BKE_mesh_to_bmesh_ex(
|
2018-10-23 13:50:43 +11:00
|
|
|
mesh,
|
|
|
|
&(struct BMeshCreateParams){0},
|
|
|
|
&(struct BMeshFromMeshParams){
|
|
|
|
.calc_face_normal = calc_face_normal,
|
2019-03-08 17:16:30 +11:00
|
|
|
.cd_mask_extra = {.vmask = CD_MASK_ORIGINDEX, .emask = CD_MASK_ORIGINDEX, .pmask = CD_MASK_ORIGINDEX},
|
2018-10-23 13:50:43 +11:00
|
|
|
});
|
2012-10-19 10:40:32 +00:00
|
|
|
|
2012-10-23 04:26:39 +00:00
|
|
|
switch (dmd->mode) {
|
|
|
|
case MOD_DECIM_MODE_COLLAPSE:
|
2012-10-23 06:13:56 +00:00
|
|
|
{
|
2015-04-20 23:37:04 +10:00
|
|
|
const bool do_triangulate = (dmd->flag & MOD_DECIM_FLAG_TRIANGULATE) != 0;
|
2015-11-18 07:50:07 +11:00
|
|
|
const int symmetry_axis = (dmd->flag & MOD_DECIM_FLAG_SYMMETRY) ? dmd->symmetry_axis : -1;
|
|
|
|
const float symmetry_eps = 0.00002f;
|
|
|
|
BM_mesh_decimate_collapse(
|
|
|
|
bm, dmd->percent, vweights, dmd->defgrp_factor, do_triangulate,
|
|
|
|
symmetry_axis, symmetry_eps);
|
2012-10-23 04:26:39 +00:00
|
|
|
break;
|
2012-10-23 06:13:56 +00:00
|
|
|
}
|
2012-10-23 04:26:39 +00:00
|
|
|
case MOD_DECIM_MODE_UNSUBDIV:
|
2012-10-23 06:13:56 +00:00
|
|
|
{
|
2012-10-23 04:26:39 +00:00
|
|
|
BM_mesh_decimate_unsubdivide(bm, dmd->iter);
|
|
|
|
break;
|
2012-10-23 06:13:56 +00:00
|
|
|
}
|
2012-10-23 05:20:02 +00:00
|
|
|
case MOD_DECIM_MODE_DISSOLVE:
|
2012-10-23 06:13:56 +00:00
|
|
|
{
|
2015-04-20 23:37:04 +10:00
|
|
|
const bool do_dissolve_boundaries = (dmd->flag & MOD_DECIM_FLAG_ALL_BOUNDARY_VERTS) != 0;
|
2013-06-03 05:07:16 +00:00
|
|
|
BM_mesh_decimate_dissolve(bm, dmd->angle, do_dissolve_boundaries, (BMO_Delimit)dmd->delimit);
|
2012-10-23 05:20:02 +00:00
|
|
|
break;
|
2012-10-23 06:13:56 +00:00
|
|
|
}
|
2012-10-23 04:26:39 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 15:39:06 +00:00
|
|
|
if (vweights) {
|
|
|
|
MEM_freeN(vweights);
|
|
|
|
}
|
2012-10-19 10:40:32 +00:00
|
|
|
|
2018-12-21 16:53:33 +01:00
|
|
|
updateFaceCount(ctx, dmd, bm->totface);
|
2018-12-20 11:17:45 +01: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
|
|
|
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL);
|
2013-10-28 02:05:33 +00:00
|
|
|
BLI_assert(bm->vtoolflagpool == NULL &&
|
|
|
|
bm->etoolflagpool == NULL &&
|
|
|
|
bm->ftoolflagpool == NULL); /* make sure we never alloc'd these */
|
|
|
|
BLI_assert(bm->vtable == NULL &&
|
|
|
|
bm->etable == NULL &&
|
|
|
|
bm->ftable == NULL);
|
|
|
|
|
2012-10-24 07:24:11 +00:00
|
|
|
BM_mesh_free(bm);
|
2012-10-19 10:40:32 +00:00
|
|
|
|
2012-10-22 02:09:41 +00:00
|
|
|
#ifdef USE_TIMEIT
|
2012-10-24 07:24:11 +00:00
|
|
|
TIMEIT_END(decim);
|
2012-10-22 02:09:41 +00:00
|
|
|
#endif
|
2012-10-20 17:31:07 +00:00
|
|
|
|
2018-05-11 10:55:26 +02:00
|
|
|
result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
|
2013-06-02 04:09:29 +00:00
|
|
|
|
2012-10-19 10:40:32 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
ModifierTypeInfo modifierType_Decimate = {
|
|
|
|
/* name */ "Decimate",
|
|
|
|
/* structName */ "DecimateModifierData",
|
|
|
|
/* structSize */ sizeof(DecimateModifierData),
|
|
|
|
/* type */ eModifierTypeType_Nonconstructive,
|
2012-10-24 05:44:27 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
|
|
|
eModifierTypeFlag_AcceptsCVs,
|
2018-05-08 15:20:18 +02:00
|
|
|
|
2018-05-08 15:04:10 +02:00
|
|
|
/* copyData */ modifier_copyData_generic,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
2018-05-11 10:55:26 +02:00
|
|
|
/* applyModifier */ applyModifier,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* initData */ initData,
|
2012-10-22 15:39:06 +00:00
|
|
|
/* requiredDataMask */ requiredDataMask,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* freeData */ NULL,
|
|
|
|
/* isDisabled */ NULL,
|
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
|
|
|
};
|