2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2012-12-12 12:57:27 +00:00
|
|
|
*
|
2021-10-24 19:31:08 +11:00
|
|
|
* Edge Split modifier
|
2012-12-12 12:57:27 +00:00
|
|
|
*
|
|
|
|
|
* Splits edges in the mesh according to sharpness flag
|
2021-10-24 19:31:08 +11:00
|
|
|
* or edge angle (can be used to achieve auto-smoothing)
|
2011-02-25 13:57:17 +00:00
|
|
|
*/
|
|
|
|
|
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_vector.h"
|
2011-05-09 04:06:48 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2019-02-25 11:56:24 +01:00
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2019-02-25 11:56:24 +01:00
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh.hh"
|
2023-11-14 09:30:40 +01:00
|
|
|
#include "BKE_modifier.hh"
|
2023-09-25 17:48:21 -04:00
|
|
|
#include "BKE_screen.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
#include "UI_resources.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-12-05 23:01:12 +01:00
|
|
|
#include "bmesh.hh"
|
|
|
|
|
#include "bmesh_tools.hh"
|
2012-10-24 07:24:11 +00:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_modifiertypes.hh"
|
|
|
|
|
#include "MOD_ui_common.hh"
|
2010-07-19 04:44:37 +00:00
|
|
|
|
Geometry: add utility to check for bad geometry element index dependence
Sometimes .blend files have compatibility issues between Blender versions,
because .blend files depended on the specific order of geometry elements
generated by some nodes/modifiers (#112746, #113018). While we make
guarantees about the order in some places, that is relatively rare, because it
makes future improvements much harder. The functionality in this patch
makes it easier for users to notice when they depend on things that are not
expected to be stable between Blender builds.
This is achieved by adding a new global flag which indicates whether some
algorithms should randomize their output. The functionality can be toggled
on or off by searching for `Set Geometry Randomization`. If there are no
differences (or acceptable minor ones) when the flag is on or off, one can
be reasonably sure that one does not on unspecified behavior (can't be 100%
sure though, because randomization might be missing in some places). If
there are big differences, one should consider fixing the file before it comes
to an actual breakage in the next Blender version.
Currently, the setting is only available when `Developer Extras` is turned on,
because the setting is in no menu.
With this patch, if we get bug reports with compatibility issues caused by
depending on indices, one of the following three cases should always apply:
* We actually accidentally broke something, which requires a fix commit.
* Turning on geometry randomization shows that the .blend file depends on
things it shouldn't depend on. In this case the user has to fix the file.
* We are missing geometry randomization somewhere, which requires a fix
commit.
Pull Request: https://projects.blender.org/blender/blender/pulls/113030
2023-09-29 21:44:36 +02:00
|
|
|
#include "GEO_randomize.hh"
|
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
/* For edge split modifier node. */
|
|
|
|
|
Mesh *doEdgeSplit(const Mesh *mesh, EdgeSplitModifierData *emd);
|
|
|
|
|
|
|
|
|
|
Mesh *doEdgeSplit(const Mesh *mesh, EdgeSplitModifierData *emd)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-07 12:26:42 +02:00
|
|
|
Mesh *result;
|
2011-06-01 19:47:21 +00:00
|
|
|
BMesh *bm;
|
2011-11-28 03:41:14 +00:00
|
|
|
BMIter iter;
|
2011-06-01 19:47:21 +00:00
|
|
|
BMEdge *e;
|
2018-12-04 10:48:48 +01:00
|
|
|
const float threshold = cosf(emd->split_angle + 0.000000175f);
|
|
|
|
|
const bool do_split_angle = (emd->flags & MOD_EDGESPLIT_FROMANGLE) != 0 &&
|
2023-05-04 18:35:37 +02:00
|
|
|
emd->split_angle < float(M_PI);
|
2018-12-04 10:48:48 +01:00
|
|
|
const bool do_split_all = do_split_angle && emd->split_angle < FLT_EPSILON;
|
|
|
|
|
const bool calc_face_normals = do_split_angle && !do_split_all;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
BMeshCreateParams create_params{};
|
|
|
|
|
BMeshFromMeshParams convert_params{};
|
|
|
|
|
convert_params.calc_face_normal = calc_face_normals;
|
|
|
|
|
convert_params.calc_vert_normal = false;
|
|
|
|
|
convert_params.add_key_index = false;
|
|
|
|
|
convert_params.use_shapekey = false;
|
|
|
|
|
convert_params.active_shapekey = 0;
|
|
|
|
|
convert_params.cd_mask_extra.vmask = CD_MASK_ORIGINDEX;
|
|
|
|
|
convert_params.cd_mask_extra.emask = CD_MASK_ORIGINDEX;
|
|
|
|
|
convert_params.cd_mask_extra.pmask = CD_MASK_ORIGINDEX;
|
|
|
|
|
|
|
|
|
|
bm = BKE_mesh_to_bmesh_ex(mesh, &create_params, &convert_params);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-04 10:48:48 +01:00
|
|
|
if (do_split_angle) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
2011-11-28 03:41:14 +00:00
|
|
|
/* check for 1 edge having 2 face users */
|
|
|
|
|
BMLoop *l1, *l2;
|
2012-05-06 13:38:33 +00:00
|
|
|
if ((l1 = e->l) && (l2 = e->l->radial_next) != l1) {
|
2012-07-17 17:55:23 +00:00
|
|
|
if (/* 3+ faces on this edge, always split */
|
2012-06-05 19:24:01 +00:00
|
|
|
UNLIKELY(l1 != l2->radial_next) ||
|
2023-07-16 21:51:08 +10:00
|
|
|
/* O degree angle setting, we want to split on all edges. */
|
2018-12-04 10:48:48 +01:00
|
|
|
do_split_all ||
|
2021-06-26 21:35:18 +10:00
|
|
|
/* 2 face edge - check angle. */
|
2012-06-05 19:24:01 +00:00
|
|
|
(dot_v3v3(l1->f->no, l2->f->no) < threshold))
|
|
|
|
|
{
|
2012-12-12 12:57:27 +00:00
|
|
|
BM_elem_flag_enable(e, BM_ELEM_TAG);
|
2011-06-01 19:30:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2011-06-05 00:54:14 +00:00
|
|
|
if (emd->flags & MOD_EDGESPLIT_FROMFLAG) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
2012-03-05 21:17:24 +00:00
|
|
|
/* check for 2 or more edge users */
|
|
|
|
|
if ((e->l) && (e->l->next != e->l)) {
|
|
|
|
|
if (!BM_elem_flag_test(e, BM_ELEM_SMOOTH)) {
|
2012-12-12 12:57:27 +00:00
|
|
|
BM_elem_flag_enable(e, BM_ELEM_TAG);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-03-05 21:17:24 +00:00
|
|
|
}
|
2012-02-18 11:44:30 +00:00
|
|
|
}
|
2011-06-05 00:54:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-02 16:05:32 +10:00
|
|
|
BM_mesh_edgesplit(bm, false, true, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-08 13:48:31 +11:00
|
|
|
/* Uncomment for troubleshooting. */
|
|
|
|
|
// BM_mesh_validate(bm);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, nullptr, mesh);
|
2012-10-24 07:24:11 +00:00
|
|
|
BM_mesh_free(bm);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Geometry: add utility to check for bad geometry element index dependence
Sometimes .blend files have compatibility issues between Blender versions,
because .blend files depended on the specific order of geometry elements
generated by some nodes/modifiers (#112746, #113018). While we make
guarantees about the order in some places, that is relatively rare, because it
makes future improvements much harder. The functionality in this patch
makes it easier for users to notice when they depend on things that are not
expected to be stable between Blender builds.
This is achieved by adding a new global flag which indicates whether some
algorithms should randomize their output. The functionality can be toggled
on or off by searching for `Set Geometry Randomization`. If there are no
differences (or acceptable minor ones) when the flag is on or off, one can
be reasonably sure that one does not on unspecified behavior (can't be 100%
sure though, because randomization might be missing in some places). If
there are big differences, one should consider fixing the file before it comes
to an actual breakage in the next Blender version.
Currently, the setting is only available when `Developer Extras` is turned on,
because the setting is in no menu.
With this patch, if we get bug reports with compatibility issues caused by
depending on indices, one of the following three cases should always apply:
* We actually accidentally broke something, which requires a fix commit.
* Turning on geometry randomization shows that the .blend file depends on
things it shouldn't depend on. In this case the user has to fix the file.
* We are missing geometry randomization somewhere, which requires a fix
commit.
Pull Request: https://projects.blender.org/blender/blender/pulls/113030
2023-09-29 21:44:36 +02:00
|
|
|
blender::geometry::debug_randomize_mesh_order(result);
|
|
|
|
|
|
2012-02-12 15:02:33 +00:00
|
|
|
return result;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
EdgeSplitModifierData *emd = (EdgeSplitModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(emd, modifier));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(emd, DNA_struct_default_get(EdgeSplitModifierData), modifier);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext * /*ctx*/, Mesh *mesh)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-07 12:26:42 +02:00
|
|
|
Mesh *result;
|
2012-05-06 13:38:33 +00:00
|
|
|
EdgeSplitModifierData *emd = (EdgeSplitModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (!(emd->flags & (MOD_EDGESPLIT_FROMANGLE | MOD_EDGESPLIT_FROMFLAG))) {
|
2018-05-07 12:26:42 +02:00
|
|
|
return mesh;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-01-30 11:02:06 +01:00
|
|
|
result = doEdgeSplit(mesh, emd);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *row, *sub;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, nullptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
|
|
|
|
row = uiLayoutRowWithHeading(layout, true, IFACE_("Edge Angle"));
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(row, ptr, "use_edge_angle", UI_ITEM_NONE, "", ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
sub = uiLayoutRow(row, true);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_edge_angle"));
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(sub, ptr, "split_angle", UI_ITEM_NONE, "", ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "use_edge_sharp", UI_ITEM_NONE, IFACE_("Sharp Edges"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
modifier_panel_end(layout, ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void panel_register(ARegionType *region_type)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
modifier_panel_register(region_type, eModifierType_EdgeSplit, panel_draw);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
ModifierTypeInfo modifierType_EdgeSplit = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "EdgeSplit",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("EdgeSplit"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "EdgeSplitModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(EdgeSplitModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_EdgeSplitModifier,
|
2023-11-14 10:03:56 +01:00
|
|
|
/*type*/ ModifierTypeType::Constructive,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_AcceptsCVs |
|
2012-05-06 13:38:33 +00:00
|
|
|
eModifierTypeFlag_SupportsMapping | eModifierTypeFlag_SupportsEditmode |
|
|
|
|
|
eModifierTypeFlag_EnableInEditmode,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_MOD_EDGESPLIT,
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
/*copy_data*/ BKE_modifier_copydata_generic,
|
|
|
|
|
|
|
|
|
|
/*deform_verts*/ nullptr,
|
|
|
|
|
/*deform_matrices*/ nullptr,
|
|
|
|
|
/*deform_verts_EM*/ nullptr,
|
|
|
|
|
/*deform_matrices_EM*/ nullptr,
|
|
|
|
|
/*modify_mesh*/ modify_mesh,
|
|
|
|
|
/*modify_geometry_set*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ init_data,
|
|
|
|
|
/*required_data_mask*/ nullptr,
|
|
|
|
|
/*free_data*/ nullptr,
|
|
|
|
|
/*is_disabled*/ nullptr,
|
|
|
|
|
/*update_depsgraph*/ nullptr,
|
|
|
|
|
/*depends_on_time*/ nullptr,
|
|
|
|
|
/*depends_on_normals*/ nullptr,
|
|
|
|
|
/*foreach_ID_link*/ nullptr,
|
|
|
|
|
/*foreach_tex_link*/ nullptr,
|
|
|
|
|
/*free_runtime_data*/ nullptr,
|
|
|
|
|
/*panel_register*/ panel_register,
|
|
|
|
|
/*blend_write*/ nullptr,
|
|
|
|
|
/*blend_read*/ nullptr,
|
2024-01-18 22:51:30 +01:00
|
|
|
/*foreach_cache*/ nullptr,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|