Blender V5.3
editmesh_relax_edge_loops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_context.hh"
10#include "BKE_editmesh.hh"
11#include "BKE_layer.hh"
12
13#include "DNA_mesh_types.h"
14#include "DNA_object_types.h"
15
16#include "ED_mesh.hh"
17#include "ED_screen.hh"
18
19#include "RNA_access.hh"
20#include "RNA_define.hh"
21
22#include "UI_interface.hh"
24
25#include "mesh_intern.hh" /* own include */
26
27namespace blender {
28
30 {RELAX_EDGE_LOOPS_INTERP_CUBIC, "CUBIC", 0, "Cubic", "Natural cubic spline, smooth results"},
32 "LINEAR",
33 0,
34 "Linear",
35 "Relax edge loops using linear interpolation"},
36 {0, nullptr},
37};
38
40{
41 const Main *bmain = CTX_data_main(C);
42 const Scene *scene = CTX_data_scene(C);
43 ViewLayer *view_layer = CTX_data_view_layer(C);
45 *bmain, scene, view_layer, CTX_wm_view3d(C));
46
47 const int interpolation = RNA_enum_get(op->ptr, "interpolation");
48 const int iterations = RNA_int_get(op->ptr, "iterations");
49 const bool even_spacing = RNA_boolean_get(op->ptr, "even_spacing");
50 bool changed_multi = false;
51 bool has_edges_selected = false;
52 bool has_faces_selected = false;
53
54 for (Object *obedit : objects) {
56 if (bm->totedgesel > 0) {
57 has_edges_selected = true;
58 }
59
60 if (bm->totfacesel > 0) {
61 has_faces_selected = true;
62 continue;
63 }
64
65 if (bm->totedgesel < 2) {
66 continue;
67 }
68
69 if (!EDBM_op_callf(bm,
70 op,
71 "relax_edge_loops geom=%he interpolation=%i iterations=%i even_spacing=%b",
73 interpolation,
74 iterations,
75 even_spacing))
76 {
77 continue;
78 }
79
80 changed_multi = true;
81 EDBMUpdate_Params params{};
82 params.calc_looptris = true;
83 params.calc_normals = true;
84 EDBM_update(id_cast<Mesh *>(obedit->data), &params);
85 }
86
87 if (!changed_multi) {
88 if (has_faces_selected) {
90 op->reports, RPT_WARNING, "Operator requires separate edge loops, selected faces found");
91 }
92 else if (!has_edges_selected) {
93 BKE_report(op->reports, RPT_WARNING, "No edges selected");
94 }
95 else {
96 BKE_report(op->reports, RPT_WARNING, "No edge loops found containing 2 or more edges");
97 }
98 }
99
100 return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
101}
102
104{
105 ot->name = "Relax Edge Loops";
106 ot->description = "Relax the loop, so it is smoother";
107 ot->idname = "MESH_OT_relax_edge_loops";
108
111
113 RNA_def_int(ot->srna,
114 "iterations",
115 1,
116 1,
117 25,
118 "Iterations",
119 "Number of times the loop is relaxed",
120 1,
121 25);
123 "even_spacing",
124 true,
125 "Space Evenly",
126 "Distribute vertices at constant distances along the loop");
127 RNA_def_enum(ot->srna,
128 "interpolation",
130 0,
131 "Interpolation",
132 "Algorithm used for interpolation");
133}
134
135} // namespace blender
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
BMesh Iterators.
static const EnumPropertyItem prop_interpolation_items[]
int RNA_enum_get(PointerRNA *ptr, const char *name)
@ RPT_WARNING
Definition BKE_report.hh:40
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
static wmOperatorStatus edbm_relax_edge_loops_exec(bContext *C, wmOperator *op)
void EDBM_update(Mesh *mesh, const EDBMUpdate_Params *params)
bool EDBM_op_callf(BMesh *bm, wmOperator *op, const char *fmt,...)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
int RNA_int_get(PointerRNA *ptr, const char *name)
@ RELAX_EDGE_LOOPS_INTERP_LINEAR
@ RELAX_EDGE_LOOPS_INTERP_CUBIC
ViewLayer * CTX_data_view_layer(const bContext *C)
bool ED_operator_editmesh(bContext *C)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
Main * CTX_data_main(const bContext *C)
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void MESH_OT_relax_edge_loops(wmOperatorType *ot)
View3D * CTX_wm_view3d(const bContext *C)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
struct ReportList * reports