Blender V5.3
transform_convert_mesh_edge.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "BLI_math_matrix_c.hh"
12#include "BLI_math_vector_c.hh"
13
14#include "BKE_context.hh"
15#include "BKE_customdata.hh"
16#include "BKE_editmesh.hh"
17
18#include "transform.hh"
19#include "transform_convert.hh"
20
21namespace blender::ed::transform {
22
23/* -------------------------------------------------------------------- */
26
27static void createTransEdge(bContext * /*C*/, TransInfo *t)
28{
31 TransData *td = nullptr;
32 BMEdge *eed;
33 BMIter iter;
34 float mtx[3][3], smtx[3][3];
35 int count = 0, countsel = 0;
36 const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
37 const bool is_prop_connected = (t->flag & T_PROP_CONNECTED) != 0;
38 int cd_edge_float_offset;
39
40 BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
43 countsel++;
44 }
45 if (is_prop_edit) {
46 count++;
47 }
48 }
49 }
50
51 if (((is_prop_edit && !is_prop_connected) ? count : countsel) == 0) {
52 tc->data_len = 0;
53 continue;
54 }
55
56 if (is_prop_edit) {
57 tc->data_len = count;
58 }
59 else {
60 tc->data_len = countsel;
61 }
62
63 td = tc->data = MEM_new_array_zeroed<TransData>(tc->data_len, "TransCrease");
64
65 copy_m3_m4(mtx, tc->obedit->object_to_world().ptr());
67
68 /* Create data we need. */
69 if (t->mode == TFM_BWEIGHT) {
70 if (!CustomData_has_layer_named(&bm->edata, CD_PROP_FLOAT, "bevel_weight_edge")) {
71 BM_data_layer_add_named(bm, &bm->edata, CD_PROP_FLOAT, "bevel_weight_edge");
72 }
73 cd_edge_float_offset = CustomData_get_offset_named(
74 &bm->edata, CD_PROP_FLOAT, "bevel_weight_edge");
75 }
76 else { /* `if (t->mode == TFM_EDGE_CREASE) {`. */
78 if (!CustomData_has_layer_named(&bm->edata, CD_PROP_FLOAT, "crease_edge")) {
80 }
81 cd_edge_float_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "crease_edge");
82 }
83
84 BLI_assert(cd_edge_float_offset != -1);
85
86 BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
88 (BM_elem_flag_test(eed, BM_ELEM_SELECT) || is_prop_edit))
89 {
90 float *fl_ptr;
91 /* Need to set center for center calculations. */
92 mid_v3_v3v3(td->center, eed->v1->co, eed->v2->co);
93
94 td->loc = nullptr;
96 td->flag = TD_SELECTED;
97 }
98 else {
99 td->flag = 0;
100 }
101
102 copy_m3_m3(td->smtx, smtx);
103 copy_m3_m3(td->mtx, mtx);
104
105 fl_ptr = static_cast<float *>(BM_ELEM_CD_GET_VOID_P(eed, cd_edge_float_offset));
106 td->val = fl_ptr;
107 td->ival = *fl_ptr;
108
109 td++;
110 }
111 }
112 }
113}
114
116{
118 DEG_id_tag_update(tc->obedit->data, ID_RECALC_GEOMETRY);
119 }
120}
121
123
125 /*flags*/ T_EDIT,
126 /*create_trans_data*/ createTransEdge,
127 /*recalc_data*/ recalcData_mesh_edge,
128 /*special_aftertrans_update*/ nullptr,
129};
130
131} // namespace blender::ed::transform
CustomData interface, see also DNA_customdata_types.h.
#define PSEUDOINVERSE_EPSILON
Read Blender memory allocation and freeing.
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
static void createTransEdge(bContext *, TransInfo *t)
TransConvertTypeInfo TransConvertType_MeshEdge
static void recalcData_mesh_edge(TransInfo *t)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void DEG_id_tag_update(ID *id, unsigned int flags)
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, StringRef name)
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
void pseudoinverse_m3_m3(float inverse[3][3], const float mat[3][3], float epsilon)
void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const StringRef name)
bool CustomData_has_layer_named(const CustomData *data, eCustomDataType type, StringRef name)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
CustomData edata
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:48
conversion and adaptation of different datablocks to a common struct.