2012-11-19 20:40:08 +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.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup modifiers
|
2012-11-19 20:40:08 +00:00
|
|
|
*/
|
|
|
|
|
2019-02-28 18:03:48 +01:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2018-05-09 16:00:12 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
2012-11-19 20:40:08 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
|
|
|
#include "BKE_modifier.h"
|
2018-05-09 16:00:12 +02:00
|
|
|
#include "BKE_mesh.h"
|
2012-11-19 20:40:08 +00:00
|
|
|
|
2013-08-23 04:22:07 +00:00
|
|
|
#include "bmesh.h"
|
|
|
|
#include "bmesh_tools.h"
|
|
|
|
|
2017-08-01 09:06:34 +10:00
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
|
2019-03-22 17:55:51 +01:00
|
|
|
static Mesh *triangulate_mesh(Mesh *mesh, const int quad_method, const int ngon_method, const int min_vertices, const int flag)
|
2012-11-19 20:40:08 +00:00
|
|
|
{
|
2018-05-09 16:00:12 +02:00
|
|
|
Mesh *result;
|
2012-11-19 20:40:08 +00:00
|
|
|
BMesh *bm;
|
2012-11-20 09:04:55 +00:00
|
|
|
int total_edges, i;
|
|
|
|
MEdge *me;
|
2019-03-08 17:16:30 +11:00
|
|
|
CustomData_MeshMasks cddata_masks = {.vmask = CD_MASK_ORIGINDEX, .emask = CD_MASK_ORIGINDEX, .pmask = CD_MASK_ORIGINDEX};
|
2019-02-28 18:03:48 +01:00
|
|
|
|
|
|
|
bool keep_clnors = (flag & MOD_TRIANGULATE_KEEP_CUSTOMLOOP_NORMALS) != 0;
|
|
|
|
|
|
|
|
if (keep_clnors) {
|
|
|
|
BKE_mesh_calc_normals_split(mesh);
|
|
|
|
/* We need that one to 'survive' to/from BMesh conversions. */
|
|
|
|
CustomData_clear_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY);
|
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
|
|
|
cddata_masks.lmask |= CD_MASK_NORMAL;
|
2019-02-28 18:03:48 +01:00
|
|
|
}
|
2012-11-19 20:40:08 +00:00
|
|
|
|
2018-05-09 16:00:12 +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 = true,
|
2019-02-28 18:03:48 +01:00
|
|
|
.cd_mask_extra = cddata_masks,
|
2018-10-23 13:50:43 +11:00
|
|
|
}));
|
2012-11-19 23:52:24 +00:00
|
|
|
|
2019-03-22 17:55:51 +01:00
|
|
|
BM_mesh_triangulate(bm, quad_method, ngon_method, min_vertices, false, NULL, NULL, NULL);
|
2012-11-19 20:40:08 +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
|
|
|
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, &cddata_masks);
|
2012-11-19 20:40:08 +00:00
|
|
|
BM_mesh_free(bm);
|
|
|
|
|
2019-02-28 18:03:48 +01:00
|
|
|
|
|
|
|
if (keep_clnors) {
|
|
|
|
float (*lnors)[3] = CustomData_get_layer(&result->ldata, CD_NORMAL);
|
2019-02-28 20:40:21 +01:00
|
|
|
BLI_assert(lnors != NULL);
|
2019-02-28 18:03:48 +01:00
|
|
|
|
2019-02-28 20:40:21 +01:00
|
|
|
BKE_mesh_set_custom_normals(result, lnors);
|
2019-02-28 18:03:48 +01:00
|
|
|
|
|
|
|
/* Do some cleanup, we do not want those temp data to stay around. */
|
|
|
|
CustomData_set_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY);
|
|
|
|
CustomData_set_layer_flag(&result->ldata, CD_NORMAL, CD_FLAG_TEMPORARY);
|
|
|
|
}
|
|
|
|
|
2018-05-09 16:00:12 +02:00
|
|
|
total_edges = result->totedge;
|
|
|
|
me = result->medge;
|
2012-11-20 09:04:55 +00:00
|
|
|
|
|
|
|
/* force drawing of all edges (seems to be omitted in CDDM_from_bmesh) */
|
2019-02-28 20:40:21 +01:00
|
|
|
for (i = 0; i < total_edges; i++, me++) {
|
2012-11-20 09:04:55 +00:00
|
|
|
me->flag |= ME_EDGEDRAW | ME_EDGERENDER;
|
2019-02-28 20:40:21 +01:00
|
|
|
}
|
2012-11-19 23:52:24 +00:00
|
|
|
|
2018-05-09 16:00:12 +02:00
|
|
|
result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
|
2012-11-19 20:40:08 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
|
|
|
TriangulateModifierData *tmd = (TriangulateModifierData *)md;
|
|
|
|
|
|
|
|
/* Enable in editmode by default */
|
|
|
|
md->mode |= eModifierMode_Editmode;
|
2013-10-29 02:42:51 +00:00
|
|
|
tmd->quad_method = MOD_TRIANGULATE_QUAD_SHORTEDGE;
|
|
|
|
tmd->ngon_method = MOD_TRIANGULATE_NGON_BEAUTY;
|
2019-03-22 17:55:51 +01:00
|
|
|
tmd->min_vertices = 4;
|
2012-11-19 20:40:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 08:21:07 +02:00
|
|
|
static Mesh *applyModifier(
|
2018-05-12 08:04:56 +02:00
|
|
|
ModifierData *md,
|
2018-05-12 08:21:07 +02:00
|
|
|
const ModifierEvalContext *UNUSED(ctx),
|
|
|
|
Mesh *mesh)
|
2012-11-19 20:40:08 +00:00
|
|
|
{
|
|
|
|
TriangulateModifierData *tmd = (TriangulateModifierData *)md;
|
2018-05-09 16:00:12 +02:00
|
|
|
Mesh *result;
|
2019-03-22 17:55:51 +01:00
|
|
|
if (!(result = triangulate_mesh(mesh, tmd->quad_method, tmd->ngon_method, tmd->min_vertices, tmd->flag))) {
|
2018-05-09 16:00:12 +02:00
|
|
|
return mesh;
|
2012-11-19 20:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_Triangulate = {
|
|
|
|
/* name */ "Triangulate",
|
|
|
|
/* structName */ "TriangulateModifierData",
|
|
|
|
/* structSize */ sizeof(TriangulateModifierData),
|
|
|
|
/* type */ eModifierTypeType_Constructive,
|
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
2012-11-19 23:52:24 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode |
|
|
|
|
eModifierTypeFlag_SupportsMapping |
|
|
|
|
eModifierTypeFlag_EnableInEditmode |
|
|
|
|
eModifierTypeFlag_AcceptsCVs,
|
2012-11-19 20:40:08 +00:00
|
|
|
|
2018-05-08 15:04:10 +02:00
|
|
|
/* copyData */ modifier_copyData_generic,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2012-11-19 20:40:08 +00:00
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
2018-05-09 16:00:12 +02:00
|
|
|
/* applyModifier */ applyModifier,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2012-11-19 20:40:08 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ NULL, //requiredDataMask,
|
|
|
|
/* 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,
|
2012-11-19 20:40:08 +00:00
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
/* foreachObjectLink */ NULL,
|
|
|
|
/* foreachIDLink */ NULL,
|
2019-03-18 15:56:16 +01:00
|
|
|
/* freeRuntimeData */ NULL,
|
2012-11-19 20:40:08 +00:00
|
|
|
};
|