Blender V5.3
MOD_edgesplit.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
13
14#include "BLI_math_vector_c.hh"
15#include "BLI_utildefines.hh"
16
17#include "BLT_translation.hh"
18
19#include "DNA_mesh_types.h"
20#include "DNA_screen_types.h"
21
22#include "BKE_mesh.hh"
23#include "BKE_modifier.hh"
24
26#include "UI_resources.hh"
27
28#include "RNA_access.hh"
29#include "RNA_prototypes.hh"
30
31#include "bmesh.hh"
32#include "bmesh_tools.hh"
33
34#include "MOD_ui_common.hh"
35
36#include "GEO_randomize.hh"
37
38namespace blender {
39
40/* For edge split modifier node. */
42
44{
45 Mesh *result;
46 BMesh *bm;
47 BMIter iter;
48 BMEdge *e;
49 const float threshold = cosf(emd->split_angle + 0.000000175f);
50 const bool do_split_angle = (emd->flags & MOD_EDGESPLIT_FROMANGLE) != 0 &&
51 emd->split_angle < float(M_PI);
52 const bool do_split_all = do_split_angle && emd->split_angle < FLT_EPSILON;
53 const bool calc_face_normals = do_split_angle && !do_split_all;
54
55 BMeshCreateParams create_params{};
56 BMeshFromMeshParams convert_params{};
57 convert_params.calc_face_normal = calc_face_normals;
58 convert_params.calc_vert_normal = false;
59 convert_params.add_key_index = false;
60 convert_params.use_shapekey = false;
61 convert_params.active_shapekey = 0;
62 convert_params.cd_mask_extra.vmask = CD_MASK_ORIGINDEX;
63 convert_params.cd_mask_extra.emask = CD_MASK_ORIGINDEX;
64 convert_params.cd_mask_extra.pmask = CD_MASK_ORIGINDEX;
65
66 bm = BKE_mesh_to_bmesh_ex(mesh, &create_params, &convert_params);
67
68 if (do_split_angle) {
70 /* check for 1 edge having 2 face users */
71 BMLoop *l1 = e->l;
72 BMLoop *l2 = (e->l) ? e->l->radial_next : nullptr;
73 if (l1 && l2 != l1) {
74 if (/* 3+ faces on this edge, always split */
75 UNLIKELY(l1 != l2->radial_next) ||
76 /* O degree angle setting, we want to split on all edges. */
77 do_split_all ||
78 /* 2 face edge - check angle. */
79 (dot_v3v3(l1->f->no, l2->f->no) < threshold))
80 {
82 }
83 }
84 }
85 }
86
87 if (emd->flags & MOD_EDGESPLIT_FROMFLAG) {
89 /* check for 2 or more edge users */
90 if ((e->l) && (e->l->next != e->l)) {
93 }
94 }
95 }
96 }
97
98 BM_mesh_edgesplit(bm, false, true, false);
99
100 /* Uncomment for troubleshooting. */
101 // BM_mesh_is_valid(bm);
102
105
107
108 return result;
109}
110
111static void init_data(ModifierData *md)
112{
113 EdgeSplitModifierData *emd = reinterpret_cast<EdgeSplitModifierData *>(md);
115}
116
118{
119 Mesh *result;
120 EdgeSplitModifierData *emd = reinterpret_cast<EdgeSplitModifierData *>(md);
121
123 return mesh;
124 }
125
126 result = doEdgeSplit(mesh, emd);
127
128 return result;
129}
130
131static void panel_draw(const bContext * /*C*/, Panel *panel)
132{
133 ui::Layout &layout = *panel->layout;
134
136
137 layout.use_property_split_set(true);
138
139 ui::Layout &row = layout.row(true, IFACE_("Edge Angle"));
140 row.prop(ptr, "use_edge_angle", UI_ITEM_NONE, "", ICON_NONE);
141 ui::Layout &sub = row.row(true);
142 sub.active_set(RNA_boolean_get(ptr, "use_edge_angle"));
143 sub.prop(ptr, "split_angle", UI_ITEM_NONE, "", ICON_NONE);
144
145 layout.prop(ptr, "use_edge_sharp", UI_ITEM_NONE, IFACE_("Sharp Edges"), ICON_NONE);
146
147 modifier_error_message_draw(layout, ptr);
148}
149
150static void panel_register(ARegionType *region_type)
151{
153}
154
156 /*idname*/ "EdgeSplit",
157 /*name*/ N_("EdgeSplit"),
158 /*struct_name*/ "EdgeSplitModifierData",
159 /*struct_size*/ sizeof(EdgeSplitModifierData),
160 /*srna*/ &RNA_EdgeSplitModifier,
165 /*icon*/ ICON_MOD_EDGESPLIT,
166
167 /*copy_data*/ BKE_modifier_copydata_generic,
168
169 /*deform_verts*/ nullptr,
170 /*deform_matrices*/ nullptr,
171 /*deform_verts_EM*/ nullptr,
172 /*deform_matrices_EM*/ nullptr,
173 /*modify_mesh*/ modify_mesh,
174 /*modify_geometry_set*/ nullptr,
175
176 /*init_data*/ init_data,
177 /*required_data_mask*/ nullptr,
178 /*free_data*/ nullptr,
179 /*is_disabled*/ nullptr,
180 /*update_depsgraph*/ nullptr,
181 /*depends_on_time*/ nullptr,
182 /*depends_on_normals*/ nullptr,
183 /*foreach_ID_link*/ nullptr,
184 /*foreach_tex_link*/ nullptr,
185 /*free_runtime_data*/ nullptr,
186 /*panel_register*/ panel_register,
187 /*blend_write*/ nullptr,
188 /*blend_read*/ nullptr,
189 /*foreach_cache*/ nullptr,
190 /*foreach_working_space_color*/ nullptr,
191};
192
193} // namespace blender
#define M_PI
#define IFACE_(msgid)
#define UI_ITEM_NONE
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
#define UNLIKELY(x)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define CD_MASK_ORIGINDEX
#define FLT_EPSILON
void debug_randomize_mesh_order(Mesh *mesh)
Definition randomize.cc:305
BMesh Iterators.
Mesh * doEdgeSplit(const Mesh *mesh, EdgeSplitModifierData *emd)
PointerRNA * modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
static void init_data(ModifierData *md)
void modifier_error_message_draw(ui::Layout &layout, PointerRNA *ptr)
BMesh * BKE_mesh_to_bmesh_ex(const Mesh *mesh, const BMeshCreateParams *create_params, const BMeshFromMeshParams *convert_params)
static void panel_register(ARegionType *region_type)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static Mesh * modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
Definition MOD_array.cc:873
@ eModifierTypeFlag_SupportsMapping
@ eModifierTypeFlag_AcceptsCVs
@ eModifierTypeFlag_EnableInEditmode
@ eModifierTypeFlag_SupportsEditmode
@ eModifierTypeFlag_AcceptsMesh
Mesh * BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra, const Mesh *me_settings)
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
void BM_mesh_edgesplit(BMesh *bm, const bool use_verts, const bool tag_only, const bool copy_select)
static void panel_draw(const bContext *, Panel *panel)
ModifierTypeInfo modifierType_EdgeSplit
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void BKE_modifier_copydata_generic(const ModifierData *md, ModifierData *md_dst, int flag)
#define cosf
struct BMLoop * radial_next
struct BMFace * f
struct CustomData_MeshMasks cd_mask_extra
ui::Layout * layout
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
Layout & row(bool align)
#define N_(msgid)