Blender V5.3
editmesh_select_similar.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "BLI_bitmap.hh"
12#include "BLI_kdtree.hh"
13#include "BLI_listbase.hh"
14#include "BLI_math_geom_c.hh"
15#include "BLI_math_matrix_c.hh"
16#include "BLI_math_vector_c.hh"
17#include "BLI_set.hh"
18
19#include "BLT_translation.hh"
20
21#include "BKE_context.hh"
22#include "BKE_customdata.hh"
23#include "BKE_deform.hh"
24#include "BKE_editmesh.hh"
25#include "BKE_layer.hh"
26#include "BKE_material.hh"
27#include "BKE_object_types.hh"
28#include "BKE_report.hh"
29
30#include "DNA_mesh_types.h"
31#include "DNA_meshdata_types.h"
32
33#include "WM_api.hh"
34#include "WM_types.hh"
35
36#include "RNA_access.hh"
37#include "RNA_define.hh"
38
39#include "ED_mesh.hh"
40#include "ED_screen.hh"
41#include "ED_select_utils.hh"
42
43#include "mesh_intern.hh" /* own include */
44
45namespace blender {
46
47/* -------------------------------------------------------------------- */
50
52 {SIM_CMP_EQ, "EQUAL", 0, "Equal", ""},
53 {SIM_CMP_GT, "GREATER", 0, "Greater", ""},
54 {SIM_CMP_LT, "LESS", 0, "Less", ""},
55 {0, nullptr, 0, nullptr, nullptr},
56};
57
59 {SIMVERT_NORMAL, "VERT_NORMAL", 0, "Normal", ""},
60 {SIMVERT_FACE, "VERT_FACES", 0, "Amount of Adjacent Faces", ""},
61 {SIMVERT_VGROUP, "VERT_GROUPS", 0, "Vertex Groups", ""},
62 {SIMVERT_EDGE, "VERT_EDGES", 0, "Amount of Connecting Edges", ""},
63 {SIMVERT_CREASE, "VERT_CREASE", 0, "Vertex Crease", ""},
64
65 {SIMEDGE_LENGTH, "EDGE_LENGTH", 0, "Length", ""},
66 {SIMEDGE_DIR, "EDGE_DIR", 0, "Direction", ""},
67 {SIMEDGE_FACE, "EDGE_FACES", 0, "Amount of Faces Around an Edge", ""},
68 {SIMEDGE_FACE_ANGLE, "EDGE_FACE_ANGLE", 0, "Face Angles", ""},
69 {SIMEDGE_CREASE, "EDGE_CREASE", 0, "Crease", ""},
70 {SIMEDGE_BEVEL, "EDGE_BEVEL", 0, "Bevel", ""},
71 {SIMEDGE_SEAM, "EDGE_SEAM", 0, "Seam", ""},
72 {SIMEDGE_SHARP, "EDGE_SHARP", 0, "Sharpness", ""},
73#ifdef WITH_FREESTYLE
74 {SIMEDGE_FREESTYLE, "EDGE_FREESTYLE", 0, "Freestyle Edge Marks", ""},
75#endif
76
77 {SIMFACE_MATERIAL, "FACE_MATERIAL", 0, "Material", ""},
78 {SIMFACE_AREA, "FACE_AREA", 0, "Area", ""},
79 {SIMFACE_SIDES, "FACE_SIDES", 0, "Polygon Sides", ""},
80 {SIMFACE_PERIMETER, "FACE_PERIMETER", 0, "Perimeter", ""},
81 {SIMFACE_NORMAL, "FACE_NORMAL", 0, "Normal", ""},
82 {SIMFACE_COPLANAR, "FACE_COPLANAR", 0, "Coplanar", ""},
83 {SIMFACE_SMOOTH, "FACE_SMOOTH", 0, "Flat/Smooth", ""},
84#ifdef WITH_FREESTYLE
85 {SIMFACE_FREESTYLE, "FACE_FREESTYLE", 0, "Freestyle Face Marks", ""},
86#endif
87
88 {0, nullptr, 0, nullptr, nullptr},
89};
90
91static int mesh_select_similar_compare_int(const int delta, const int compare)
92{
93 switch (compare) {
94 case SIM_CMP_EQ:
95 return (delta == 0);
96 case SIM_CMP_GT:
97 return (delta > 0);
98 case SIM_CMP_LT:
99 return (delta < 0);
100 default:
101 BLI_assert(0);
102 return 0;
103 }
104}
105
107
108/* -------------------------------------------------------------------- */
111
112enum {
117};
118
124static bool face_data_value_set(BMFace *face, const int hflag, int *r_value)
125{
126 if (BM_elem_flag_test(face, hflag)) {
127 *r_value |= SIMFACE_DATA_TRUE;
128 }
129 else {
130 *r_value |= SIMFACE_DATA_FALSE;
131 }
132
133 return *r_value != SIMFACE_DATA_ALL;
134}
135
139static void face_to_plane(const Object *ob, BMFace *face, float r_plane[4])
140{
141 float normal[3], co[3];
142 copy_v3_v3(normal, face->no);
143 mul_transposed_mat3_m4_v3(ob->world_to_object().ptr(), normal);
144 normalize_v3(normal);
145 mul_v3_m4v3(co, ob->object_to_world().ptr(), BM_FACE_FIRST_LOOP(face)->v->co);
146 plane_from_point_normal_v3(r_plane, co, normal);
147}
148
149/* TODO(dfelinto): `types` that should technically be compared in world space but are not:
150 * -SIMFACE_AREA
151 * -SIMFACE_PERIMETER
152 */
154{
155 const Main *bmain = CTX_data_main(C);
156 const Scene *scene = CTX_data_scene(C);
157 ViewLayer *view_layer = CTX_data_view_layer(C);
158
159 const int type = RNA_enum_get(op->ptr, "type");
160 const float thresh = RNA_float_get(op->ptr, "threshold");
161 const float thresh_radians = thresh * float(M_PI);
162 const int compare = RNA_enum_get(op->ptr, "compare");
163
165 *bmain, scene, view_layer, CTX_wm_view3d(C));
166
167 bool any_face_selected = false;
168 for (Object *ob : objects) {
169 const BMesh *bm = BKE_editmesh_bmesh_get(ob);
170 if (bm->totfacesel == 0) {
171 continue;
172 }
173 any_face_selected = true;
174 break;
175 }
176
177 if (!any_face_selected) {
178 BKE_report(op->reports, RPT_ERROR, "No face selected");
179 return OPERATOR_CANCELLED;
180 }
181
182 Map<float, int> points_1d;
183 Map<float3, int> points_3d;
184 Map<float4, int> points_4d;
185
186 KDTree<float> *tree_1d = nullptr;
187 KDTree<float3> *tree_3d = nullptr;
188 KDTree<float4> *tree_4d = nullptr;
189
190 Set<int> sides_set;
191 Set<const Material *> materials_set;
192 int face_data_value = SIMFACE_DATA_NONE;
193
194 int tree_index = 0;
195 for (Object *ob : objects) {
197 Material ***material_array = nullptr;
198 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
199
200 if (bm->totfacesel == 0) {
201 continue;
202 }
203
204 float ob_m3[3][3];
205 copy_m3_m4(ob_m3, ob->object_to_world().ptr());
206
207 int custom_data_offset = -1;
208 switch (type) {
209 case SIMFACE_MATERIAL: {
210 if (ob->totcol == 0) {
211 continue;
212 }
213 material_array = BKE_object_material_array_p(ob);
214 break;
215 }
216 case SIMFACE_FREESTYLE: {
217 custom_data_offset = CustomData_get_offset_named(
218 &bm->pdata, CD_PROP_BOOL, "freestyle_face");
219 if (custom_data_offset == -1) {
220 face_data_value |= SIMFACE_DATA_FALSE;
221 continue;
222 }
223 break;
224 }
225 }
226
227 BMFace *face; /* Mesh face. */
228 BMIter iter; /* Selected faces iterator. */
229
230 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
232 switch (type) {
233 case SIMFACE_SIDES:
234 sides_set.add(face->len);
235 break;
236 case SIMFACE_MATERIAL: {
237 Material *material = (*material_array)[face->mat_nr];
238 if (material != nullptr) {
239 materials_set.add(material);
240 }
241 break;
242 }
243 case SIMFACE_AREA: {
244 float area = BM_face_calc_area_with_mat3(face, ob_m3);
245 points_1d.add(area, tree_index++);
246 break;
247 }
248 case SIMFACE_PERIMETER: {
249 float perimeter = BM_face_calc_perimeter_with_mat3(face, ob_m3);
250 points_1d.add(perimeter, tree_index++);
251 break;
252 }
253 case SIMFACE_NORMAL: {
254 float normal[3];
255 copy_v3_v3(normal, face->no);
256 mul_transposed_mat3_m4_v3(ob->world_to_object().ptr(), normal);
257 normalize_v3(normal);
258 points_3d.add(normal, tree_index++);
259 break;
260 }
261 case SIMFACE_COPLANAR: {
262 float plane[4];
263 face_to_plane(ob, face, plane);
264 points_4d.add(plane, tree_index++);
265 break;
266 }
267 case SIMFACE_SMOOTH: {
268 if (!face_data_value_set(face, BM_ELEM_SMOOTH, &face_data_value)) {
269 goto face_select_all;
270 }
271 break;
272 }
273 case SIMFACE_FREESTYLE: {
274 if (custom_data_offset == -1 || !BM_ELEM_CD_GET_BOOL(face, custom_data_offset)) {
275 face_data_value |= SIMFACE_DATA_FALSE;
276 }
277 else {
278 face_data_value |= SIMFACE_DATA_TRUE;
279 }
280 if (face_data_value == SIMFACE_DATA_ALL) {
281 goto face_select_all;
282 }
283 break;
284 }
285 }
286 }
287 }
288 }
289
290 BLI_assert((type != SIMFACE_FREESTYLE) || (face_data_value != SIMFACE_DATA_NONE));
291
292 switch (type) {
293 case SIMFACE_AREA:
294 case SIMFACE_PERIMETER: {
295 tree_1d = kdtree_new<float>(points_1d.size());
296 for (const auto &[pos, index] : points_1d.items()) {
297 kdtree_insert(tree_1d, index, pos);
298 }
299 kdtree_balance<float>(tree_1d);
300 break;
301 }
302 case SIMFACE_NORMAL: {
303 tree_3d = kdtree_new<float3>(points_3d.size());
304 for (const auto &[pos, index] : points_3d.items()) {
305 kdtree_insert(tree_3d, index, pos);
306 }
307 kdtree_balance<float3>(tree_3d);
308 break;
309 }
310 case SIMFACE_COPLANAR: {
311 tree_4d = kdtree_new<float4>(points_4d.size());
312 for (const auto &[pos, index] : points_4d.items()) {
313 kdtree_insert(tree_4d, index, pos);
314 }
315 kdtree_balance<float4>(tree_4d);
316 break;
317 }
318 case SIMFACE_SIDES:
319 case SIMFACE_MATERIAL:
320 break;
321 }
322
323 for (Object *ob : objects) {
326 bool changed = false;
327 Material ***material_array = nullptr;
328
329 float ob_m3[3][3];
330 copy_m3_m4(ob_m3, ob->object_to_world().ptr());
331
332 int custom_data_offset = -1;
333 switch (type) {
334 case SIMFACE_MATERIAL: {
335 if (ob->totcol == 0) {
336 continue;
337 }
338 material_array = BKE_object_material_array_p(ob);
339 break;
340 }
341 case SIMFACE_FREESTYLE: {
342 custom_data_offset = CustomData_get_offset_named(
343 &bm->pdata, CD_PROP_BOOL, "freestyle_face");
344 if ((face_data_value == SIMFACE_DATA_TRUE) && (custom_data_offset == -1)) {
345 continue;
346 }
347 break;
348 }
349 }
350
351 BMFace *face; /* Mesh face. */
352 BMIter iter; /* Selected faces iterator. */
353
354 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
356 bool select = false;
357 switch (type) {
358 case SIMFACE_SIDES: {
359 const int num_sides = face->len;
360 for (const int num_sides_iter : sides_set) {
361 const int delta_i = num_sides - num_sides_iter;
362 if (mesh_select_similar_compare_int(delta_i, compare)) {
363 select = true;
364 break;
365 }
366 }
367 break;
368 }
369 case SIMFACE_MATERIAL: {
370 const Material *material = (*material_array)[face->mat_nr];
371 if (material == nullptr) {
372 continue;
373 }
374 if (materials_set.contains(material)) {
375 select = true;
376 }
377 break;
378 }
379 case SIMFACE_AREA: {
380 float area = BM_face_calc_area_with_mat3(face, ob_m3);
381 if (ED_select_similar_compare_float_tree(tree_1d, area, thresh, eSimilarCmp(compare)))
382 {
383 select = true;
384 }
385 break;
386 }
387 case SIMFACE_PERIMETER: {
388 float perimeter = BM_face_calc_perimeter_with_mat3(face, ob_m3);
390 tree_1d, perimeter, thresh, eSimilarCmp(compare)))
391 {
392 select = true;
393 }
394 break;
395 }
396 case SIMFACE_NORMAL: {
397 float normal[3];
398 copy_v3_v3(normal, face->no);
399 mul_transposed_mat3_m4_v3(ob->world_to_object().ptr(), normal);
400 normalize_v3(normal);
401
402 /* We are treating the normals as coordinates, the "nearest" one will
403 * also be the one closest to the angle. */
404 KDTreeNearest<float3> nearest;
405 if (kdtree_find_nearest<float3>(tree_3d, normal, &nearest) != -1) {
406 if (angle_normalized_v3v3(normal, nearest.co) <= thresh_radians) {
407 select = true;
408 }
409 }
410 break;
411 }
412 case SIMFACE_COPLANAR: {
413 float plane[4];
414 face_to_plane(ob, face, plane);
415
416 KDTreeNearest<float4> nearest;
417 if (kdtree_find_nearest<float4>(tree_4d, plane, &nearest) != -1) {
418 if (nearest.dist <= thresh) {
419 if ((fabsf(plane[3] - nearest.co[3]) <= thresh) &&
420 (angle_v3v3(plane, nearest.co) <= thresh_radians))
421 {
422 select = true;
423 }
424 }
425 }
426 break;
427 }
428 case SIMFACE_SMOOTH:
429 if ((BM_elem_flag_test(face, BM_ELEM_SMOOTH) != 0) ==
430 ((face_data_value & SIMFACE_DATA_TRUE) != 0))
431 {
432 select = true;
433 }
434 break;
435 case SIMFACE_FREESTYLE: {
436
437 if (custom_data_offset == -1) {
438 BLI_assert(face_data_value == SIMFACE_DATA_FALSE);
439 select = true;
440 break;
441 }
442
443 const bool value = BM_ELEM_CD_GET_BOOL(face, custom_data_offset);
444 if (value == ((face_data_value & SIMFACE_DATA_TRUE) != 0)) {
445 select = true;
446 }
447 break;
448 }
449 }
450
451 if (select) {
452 BM_face_select_set(bm, face, true);
453 changed = true;
454 }
455 }
456 }
457
458 if (changed) {
461
462 EDBMUpdate_Params params{};
463 params.calc_looptris = false;
464 params.calc_normals = false;
465 params.is_destructive = false;
466 EDBM_update(id_cast<Mesh *>(ob->data), &params);
467 }
468 }
469
470 if (false) {
471 face_select_all:
473
474 for (Object *ob : objects) {
477
478 BMFace *face; /* Mesh face. */
479 BMIter iter; /* Selected faces iterator. */
480
481 BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
482 if (!BM_elem_flag_test(face, BM_ELEM_SELECT)) {
483 BM_face_select_set(bm, face, true);
484 }
485 }
488
489 EDBMUpdate_Params params{};
490 params.calc_looptris = false;
491 params.calc_normals = false;
492 params.is_destructive = false;
493 EDBM_update(id_cast<Mesh *>(ob->data), &params);
494 }
495 }
496
497 kdtree_free<float>(tree_1d);
498 kdtree_free<float3>(tree_3d);
499 kdtree_free<float4>(tree_4d);
500
501 return OPERATOR_FINISHED;
502}
503
505
506/* -------------------------------------------------------------------- */
509
510static void edge_pos_direction_worldspace_get(Object *ob, BMEdge *edge, float *r_dir)
511{
512 float v1[3], v2[3];
513 copy_v3_v3(v1, edge->v1->co);
514 copy_v3_v3(v2, edge->v2->co);
515
516 mul_m4_v3(ob->object_to_world().ptr(), v1);
517 mul_m4_v3(ob->object_to_world().ptr(), v2);
518
519 sub_v3_v3v3(r_dir, v1, v2);
520 normalize_v3(r_dir);
521}
522
524{
525 float v1[3], v2[3];
526
527 mul_v3_mat3_m4v3(v1, ob->object_to_world().ptr(), edge->v1->co);
528 mul_v3_mat3_m4v3(v2, ob->object_to_world().ptr(), edge->v2->co);
529
530 return len_squared_v3v3(v1, v2);
531}
532
533enum {
538};
539
545static bool edge_data_value_set(BMEdge *edge, const int hflag, int *r_value)
546{
547 if (BM_elem_flag_test(edge, hflag)) {
548 *r_value |= SIMEDGE_DATA_TRUE;
549 }
550 else {
551 *r_value |= SIMEDGE_DATA_FALSE;
552 }
553
554 return *r_value != SIMEDGE_DATA_ALL;
555}
556
557/* TODO(dfelinto): `types` that should technically be compared in world space but are not:
558 * -SIMEDGE_FACE_ANGLE
559 */
561{
562 const Main *bmain = CTX_data_main(C);
563 const Scene *scene = CTX_data_scene(C);
564 ViewLayer *view_layer = CTX_data_view_layer(C);
565
566 const int type = RNA_enum_get(op->ptr, "type");
567 const float thresh = RNA_float_get(op->ptr, "threshold");
568 const float thresh_radians = thresh * float(M_PI) + FLT_EPSILON;
569 const int compare = RNA_enum_get(op->ptr, "compare");
570
572 *bmain, scene, view_layer, CTX_wm_view3d(C));
573
574 bool any_edge_selected = false;
575 for (Object *ob : objects) {
576 const BMesh *bm = BKE_editmesh_bmesh_get(ob);
577 if (bm->totedgesel == 0) {
578 continue;
579 }
580 any_edge_selected = true;
581 break;
582 }
583
584 if (!any_edge_selected) {
585 BKE_report(op->reports, RPT_ERROR, "No edge selected");
586 return OPERATOR_CANCELLED;
587 }
588
589 Map<float, int> points_1d;
590 Map<float3, int> points_3d;
591
592 KDTree<float> *tree_1d = nullptr;
593 KDTree<float3> *tree_3d = nullptr;
594 Set<int> face_count_set;
595 int edge_data_value = SIMEDGE_DATA_NONE;
596
597 int tree_index = 0;
598 for (Object *ob : objects) {
600 if (bm->totedgesel == 0) {
601 continue;
602 }
603
604 switch (type) {
605 case SIMEDGE_FREESTYLE: {
606 if (!CustomData_has_layer_named(&bm->edata, CD_PROP_BOOL, "freestyle_edge")) {
607 edge_data_value |= SIMEDGE_DATA_FALSE;
608 continue;
609 }
610 break;
611 }
612 case SIMEDGE_CREASE: {
613 if (!CustomData_has_layer_named(&bm->edata, CD_PROP_FLOAT, "crease_edge")) {
614 points_1d.add(0.0f, tree_index++);
615 continue;
616 }
617 break;
618 }
619 case SIMEDGE_BEVEL: {
620 if (!CustomData_has_layer_named(&bm->edata, CD_PROP_FLOAT, "bevel_weight_edge")) {
621 points_1d.add(0.0f, tree_index++);
622 continue;
623 }
624 break;
625 }
626 }
627
628 int custom_data_offset;
629 switch (type) {
630 case SIMEDGE_FREESTYLE: {
631 custom_data_offset = CustomData_get_offset_named(
632 &bm->edata, CD_PROP_BOOL, "freestyle_edge");
633 break;
634 }
635 case SIMEDGE_CREASE:
636 custom_data_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "crease_edge");
637 break;
638 case SIMEDGE_BEVEL:
639 custom_data_offset = CustomData_get_offset_named(
640 &bm->edata, CD_PROP_FLOAT, "bevel_weight_edge");
641 break;
642 }
643
644 float ob_m3[3][3], ob_m3_inv[3][3];
645 copy_m3_m4(ob_m3, ob->object_to_world().ptr());
646 invert_m3_m3(ob_m3_inv, ob_m3);
647
648 BMEdge *edge; /* Mesh edge. */
649 BMIter iter; /* Selected edges iterator. */
650
651 BM_ITER_MESH (edge, &iter, bm, BM_EDGES_OF_MESH) {
653 switch (type) {
654 case SIMEDGE_FACE:
655 face_count_set.add(BM_edge_face_count(edge));
656 break;
657 case SIMEDGE_DIR: {
658 float dir[3], dir_flip[3];
660 points_3d.add(dir, tree_index++);
661 /* Also store the flipped direction so it can be checked regardless of the verts order
662 * of the edges. */
663 negate_v3_v3(dir_flip, dir);
664 points_3d.add(dir_flip, tree_index++);
665 break;
666 }
667 case SIMEDGE_LENGTH: {
669 points_1d.add(length, tree_index++);
670 break;
671 }
672 case SIMEDGE_FACE_ANGLE: {
673 if (BM_edge_face_count_at_most(edge, 2) == 2) {
674 float angle = BM_edge_calc_face_angle_with_imat3(edge, ob_m3_inv);
675 points_1d.add(angle, tree_index++);
676 }
677 break;
678 }
679 case SIMEDGE_SEAM:
680 if (!edge_data_value_set(edge, BM_ELEM_SEAM, &edge_data_value)) {
681 goto edge_select_all;
682 }
683 break;
684 case SIMEDGE_SHARP:
685 if (!edge_data_value_set(edge, BM_ELEM_SMOOTH, &edge_data_value)) {
686 goto edge_select_all;
687 }
688 break;
689 case SIMEDGE_FREESTYLE: {
690 if (custom_data_offset == -1 || !BM_ELEM_CD_GET_BOOL(edge, custom_data_offset)) {
691 edge_data_value |= SIMEDGE_DATA_FALSE;
692 }
693 else {
694 edge_data_value |= SIMEDGE_DATA_TRUE;
695 }
696 if (edge_data_value == SIMEDGE_DATA_ALL) {
697 goto edge_select_all;
698 }
699 break;
700 }
701 case SIMEDGE_CREASE:
702 case SIMEDGE_BEVEL: {
703 const float value = BM_ELEM_CD_GET_FLOAT(edge, custom_data_offset);
704 points_1d.add(value, tree_index++);
705 break;
706 }
707 }
708 }
709 }
710 }
711
712 BLI_assert((type != SIMEDGE_FREESTYLE) || (edge_data_value != SIMEDGE_DATA_NONE));
713
714 switch (type) {
715 case SIMEDGE_CREASE:
716 case SIMEDGE_BEVEL:
718 case SIMEDGE_LENGTH: {
719 tree_1d = kdtree_new<float>(points_1d.size());
720 for (const auto &[pos, index] : points_1d.items()) {
721 kdtree_insert(tree_1d, index, pos);
722 }
723 kdtree_balance<float>(tree_1d);
724 break;
725 }
726 case SIMEDGE_DIR: {
727 tree_3d = kdtree_new<float3>(points_3d.size());
728 for (const auto &[pos, index] : points_3d.items()) {
729 kdtree_insert(tree_3d, index, pos);
730 }
731 kdtree_balance<float3>(tree_3d);
732 break;
733 }
734 case SIMEDGE_FACE:
735 break;
736 }
737
738 for (Object *ob : objects) {
741 bool changed = false;
742
743 bool has_custom_data_layer = false;
744 switch (type) {
745 case SIMEDGE_FREESTYLE: {
746 has_custom_data_layer = CustomData_has_layer_named(
747 &bm->edata, CD_PROP_BOOL, "freestyle_edge");
748 if ((edge_data_value == SIMEDGE_DATA_TRUE) && !has_custom_data_layer) {
749 continue;
750 }
751 break;
752 }
753 case SIMEDGE_CREASE: {
754 has_custom_data_layer = CustomData_has_layer_named(
755 &bm->edata, CD_PROP_FLOAT, "crease_edge");
756 if (!has_custom_data_layer) {
757 /* Proceed only if we have to select all the edges that have custom data value of 0.0f.
758 * In this case we will just select all the edges.
759 * Otherwise continue the for loop. */
760 if (!ED_select_similar_compare_float_tree(tree_1d, 0.0f, thresh, eSimilarCmp(compare))) {
761 continue;
762 }
763 }
764 break;
765 }
766 case SIMEDGE_BEVEL: {
767 has_custom_data_layer = CustomData_has_layer_named(
768 &bm->edata, CD_PROP_FLOAT, "bevel_weight_edge");
769 if (!has_custom_data_layer) {
770 /* Proceed only if we have to select all the edges that have custom data value of 0.0f.
771 * In this case we will just select all the edges.
772 * Otherwise continue the for loop. */
773 if (!ED_select_similar_compare_float_tree(tree_1d, 0.0f, thresh, eSimilarCmp(compare))) {
774 continue;
775 }
776 }
777 break;
778 }
779 }
780
781 float ob_m3[3][3], ob_m3_inv[3][3];
782 copy_m3_m4(ob_m3, ob->object_to_world().ptr());
783 invert_m3_m3(ob_m3_inv, ob_m3);
784
785 int custom_data_offset;
786 switch (type) {
788 custom_data_offset = CustomData_get_offset_named(
789 &bm->edata, CD_PROP_BOOL, "freestyle_edge");
790 break;
791 case SIMEDGE_CREASE:
792 custom_data_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "crease_edge");
793 break;
794 case SIMEDGE_BEVEL:
795 custom_data_offset = CustomData_get_offset_named(
796 &bm->edata, CD_PROP_FLOAT, "bevel_weight_edge");
797 break;
798 }
799
800 BMEdge *edge; /* Mesh edge. */
801 BMIter iter; /* Selected edges iterator. */
802
803 BM_ITER_MESH (edge, &iter, bm, BM_EDGES_OF_MESH) {
805 bool select = false;
806 switch (type) {
807 case SIMEDGE_FACE: {
808 const int num_faces = BM_edge_face_count(edge);
809 for (const int num_faces_iter : face_count_set) {
810 const int delta_i = num_faces - num_faces_iter;
811 if (mesh_select_similar_compare_int(delta_i, compare)) {
812 select = true;
813 break;
814 }
815 }
816 break;
817 }
818 case SIMEDGE_DIR: {
819 float dir[3];
821
822 /* We are treating the direction as coordinates, the "nearest" one will
823 * also be the one closest to the intended direction. */
824 KDTreeNearest<float3> nearest;
825 if (kdtree_find_nearest<float3>(tree_3d, dir, &nearest) != -1) {
826 if (angle_normalized_v3v3(dir, nearest.co) <= thresh_radians) {
827 select = true;
828 }
829 }
830 break;
831 }
832 case SIMEDGE_LENGTH: {
835 tree_1d, length, thresh, eSimilarCmp(compare)))
836 {
837 select = true;
838 }
839 break;
840 }
841 case SIMEDGE_FACE_ANGLE: {
842 if (BM_edge_face_count_at_most(edge, 2) == 2) {
843 float angle = BM_edge_calc_face_angle_with_imat3(edge, ob_m3_inv);
845 select = true;
846 }
847 }
848 break;
849 }
850 case SIMEDGE_SEAM:
851 if ((BM_elem_flag_test(edge, BM_ELEM_SEAM) != 0) ==
852 ((edge_data_value & SIMEDGE_DATA_TRUE) != 0))
853 {
854 select = true;
855 }
856 break;
857 case SIMEDGE_SHARP:
858 if ((BM_elem_flag_test(edge, BM_ELEM_SMOOTH) != 0) ==
859 ((edge_data_value & SIMEDGE_DATA_TRUE) != 0))
860 {
861 select = true;
862 }
863 break;
864 case SIMEDGE_FREESTYLE: {
865 if (!has_custom_data_layer) {
866 BLI_assert(edge_data_value == SIMEDGE_DATA_FALSE);
867 select = true;
868 break;
869 }
870
871 const bool value = BM_ELEM_CD_GET_BOOL(edge, custom_data_offset);
872 if (value == ((edge_data_value & SIMEDGE_DATA_TRUE) != 0)) {
873 select = true;
874 }
875 break;
876 }
877 case SIMEDGE_CREASE:
878 case SIMEDGE_BEVEL: {
879 if (!has_custom_data_layer) {
880 select = true;
881 break;
882 }
883
884 const float *value = BM_ELEM_CD_GET_FLOAT_P(edge, custom_data_offset);
886 tree_1d, *value, thresh, eSimilarCmp(compare)))
887 {
888 select = true;
889 }
890 break;
891 }
892 }
893
894 if (select) {
895 BM_edge_select_set(bm, edge, true);
896 changed = true;
897 }
898 }
899 }
900
901 if (changed) {
904
905 EDBMUpdate_Params params{};
906 params.calc_looptris = false;
907 params.calc_normals = false;
908 params.is_destructive = false;
909 EDBM_update(id_cast<Mesh *>(ob->data), &params);
910 }
911 }
912
913 if (false) {
914 edge_select_all:
916
917 for (Object *ob : objects) {
920
921 BMEdge *edge; /* Mesh edge. */
922 BMIter iter; /* Selected edges iterator. */
923
924 BM_ITER_MESH (edge, &iter, bm, BM_EDGES_OF_MESH) {
925 if (!BM_elem_flag_test(edge, BM_ELEM_SELECT)) {
926 BM_edge_select_set(bm, edge, true);
927 }
928 }
931
932 EDBMUpdate_Params params{};
933 params.calc_looptris = false;
934 params.calc_normals = false;
935 params.is_destructive = false;
936 EDBM_update(id_cast<Mesh *>(ob->data), &params);
937 }
938 }
939
940 kdtree_free<float>(tree_1d);
941 kdtree_free<float3>(tree_3d);
942
943 return OPERATOR_FINISHED;
944}
945
947
948/* -------------------------------------------------------------------- */
951
953{
954 const Main *bmain = CTX_data_main(C);
955 const Scene *scene = CTX_data_scene(C);
956 ViewLayer *view_layer = CTX_data_view_layer(C);
957
958 /* get the type from RNA */
959 const int type = RNA_enum_get(op->ptr, "type");
960 const float thresh = RNA_float_get(op->ptr, "threshold");
961 const float thresh_radians = thresh * float(M_PI) + FLT_EPSILON;
962 const int compare = RNA_enum_get(op->ptr, "compare");
963
965 *bmain, scene, view_layer, CTX_wm_view3d(C));
966
967 bool any_vert_selected = false;
968 for (Object *ob : objects) {
969 const BMesh *bm = BKE_editmesh_bmesh_get(ob);
970 if (bm->totvertsel == 0) {
971 continue;
972 }
973 any_vert_selected = true;
974 break;
975 }
976
977 if (!any_vert_selected) {
978 BKE_report(op->reports, RPT_ERROR, "No vertex selected");
979 return OPERATOR_CANCELLED;
980 }
981
982 Map<float, int> points_1d;
983 Map<float3, int> points_3d;
984
985 KDTree<float3> *tree_3d = nullptr;
986 KDTree<float> *tree_1d = nullptr;
987 Set<StringRef> selected_vertex_groups;
988 Set<int> connected_elems_num_set;
989
990 int normal_tree_index = 0;
991 int tree_1d_index = 0;
992 for (Object *ob : objects) {
994 int cd_dvert_offset = -1;
995 int cd_crease_offset = -1;
996 BLI_bitmap *defbase_selected = nullptr;
997 int defbase_len = 0;
998
999 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
1000
1001 if (bm->totvertsel == 0) {
1002 continue;
1003 }
1004
1005 if (type == SIMVERT_VGROUP) {
1006 cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT);
1007 if (cd_dvert_offset == -1) {
1008 continue;
1009 }
1010 defbase_len = BKE_object_defgroup_count(ob);
1011 if (defbase_len == 0) {
1012 continue;
1013 }
1014 defbase_selected = BLI_BITMAP_NEW(defbase_len, __func__);
1015 }
1016 else if (type == SIMVERT_CREASE) {
1017 if (!CustomData_has_layer_named(&bm->vdata, CD_PROP_FLOAT, "crease_vert")) {
1018 points_1d.add(0.0f, tree_1d_index++);
1019 continue;
1020 }
1021 cd_crease_offset = CustomData_get_offset_named(&bm->vdata, CD_PROP_FLOAT, "crease_vert");
1022 }
1023
1024 BMVert *vert; /* Mesh vertex. */
1025 BMIter iter; /* Selected verts iterator. */
1026
1027 BM_ITER_MESH (vert, &iter, bm, BM_VERTS_OF_MESH) {
1028 if (BM_elem_flag_test(vert, BM_ELEM_SELECT)) {
1029 switch (type) {
1030 case SIMVERT_FACE:
1031 connected_elems_num_set.add(BM_vert_face_count(vert));
1032 break;
1033 case SIMVERT_EDGE:
1034 connected_elems_num_set.add(BM_vert_edge_count(vert));
1035 break;
1036 case SIMVERT_NORMAL: {
1037 float normal[3];
1038 copy_v3_v3(normal, vert->no);
1039 mul_transposed_mat3_m4_v3(ob->world_to_object().ptr(), normal);
1040 normalize_v3(normal);
1041
1042 points_3d.add(normal, normal_tree_index++);
1043 break;
1044 }
1045 case SIMVERT_VGROUP: {
1046 MDeformVert *dvert = static_cast<MDeformVert *>(
1047 BM_ELEM_CD_GET_VOID_P(vert, cd_dvert_offset));
1048 MDeformWeight *dw = dvert->dw;
1049
1050 for (int i = 0; i < dvert->totweight; i++, dw++) {
1051 if (dw->weight > 0.0f) {
1052 if (dw->def_nr < defbase_len) [[likely]] {
1053 BLI_BITMAP_ENABLE(defbase_selected, dw->def_nr);
1054 }
1055 }
1056 }
1057 break;
1058 }
1059 case SIMVERT_CREASE: {
1060 const float value = BM_ELEM_CD_GET_FLOAT(vert, cd_crease_offset);
1061 points_1d.add(value, tree_1d_index++);
1062 break;
1063 }
1064 }
1065 }
1066 }
1067
1068 if (type == SIMVERT_VGROUP) {
1069 /* We store the names of the vertex groups, so we can select
1070 * vertex groups with the same name in different objects. */
1071
1072 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
1073
1074 int i = 0;
1075 for (bDeformGroup &dg : *defbase) {
1076 if (BLI_BITMAP_TEST(defbase_selected, i)) {
1077 selected_vertex_groups.add_as(dg.name);
1078 }
1079 i += 1;
1080 }
1081 MEM_delete(defbase_selected);
1082 }
1083 }
1084
1085 if (type == SIMVERT_VGROUP) {
1086 if (selected_vertex_groups.is_empty()) {
1087 BKE_report(op->reports, RPT_INFO, "No vertex group among the selected vertices");
1088 }
1089 }
1090
1091 switch (type) {
1092 case SIMVERT_NORMAL: {
1093 tree_3d = kdtree_new<float3>(points_3d.size());
1094 for (const auto &[pos, index] : points_3d.items()) {
1095 kdtree_insert(tree_3d, index, pos);
1096 }
1097 kdtree_balance<float3>(tree_3d);
1098 break;
1099 }
1100 case SIMVERT_CREASE: {
1101 tree_1d = kdtree_new<float>(points_1d.size());
1102 for (const auto &[pos, index] : points_1d.items()) {
1103 kdtree_insert(tree_1d, index, pos);
1104 }
1105 kdtree_balance<float>(tree_1d);
1106 break;
1107 }
1108 case SIMVERT_EDGE:
1109 case SIMVERT_FACE:
1110 case SIMVERT_VGROUP:
1111 break;
1112 }
1113
1114 /* Run the matching operations. */
1115 for (Object *ob : objects) {
1118 bool changed = false;
1119 bool has_crease_layer = false;
1120 int cd_dvert_offset = -1;
1121 int cd_crease_offset = -1;
1122 BLI_bitmap *defbase_selected = nullptr;
1123 int defbase_len = 0;
1124
1125 if (type == SIMVERT_VGROUP) {
1126 cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT);
1127 if (cd_dvert_offset == -1) {
1128 continue;
1129 }
1130 const ListBaseT<bDeformGroup> *defbase = BKE_object_defgroup_list(ob);
1131 defbase_len = defbase->count();
1132 if (defbase_len == 0) {
1133 continue;
1134 }
1135
1136 /* We map back the names of the vertex groups to their corresponding indices
1137 * for this object. This is fast, and keep the logic for each vertex very simple. */
1138
1139 defbase_selected = BLI_BITMAP_NEW(defbase_len, __func__);
1140 bool found_any = false;
1141 for (const StringRef name : selected_vertex_groups) {
1142 int vgroup_id = BKE_defgroup_name_index(defbase, name);
1143 if (vgroup_id != -1) {
1144 BLI_BITMAP_ENABLE(defbase_selected, vgroup_id);
1145 found_any = true;
1146 }
1147 }
1148 if (found_any == false) {
1149 MEM_delete(defbase_selected);
1150 continue;
1151 }
1152 }
1153 else if (type == SIMVERT_CREASE) {
1154 cd_crease_offset = CustomData_get_offset_named(&bm->vdata, CD_PROP_FLOAT, "crease_vert");
1155 has_crease_layer = CustomData_has_layer_named(&bm->vdata, CD_PROP_FLOAT, "crease_vert");
1156 if (!has_crease_layer) {
1157 /* Proceed only if we have to select all the vertices that have custom data value of 0.0f.
1158 * In this case we will just select all the vertices.
1159 * Otherwise continue the for loop. */
1160 if (!ED_select_similar_compare_float_tree(tree_1d, 0.0f, thresh, eSimilarCmp(compare))) {
1161 continue;
1162 }
1163 }
1164 }
1165
1166 BMVert *vert; /* Mesh vertex. */
1167 BMIter iter; /* Selected verts iterator. */
1168
1169 BM_ITER_MESH (vert, &iter, bm, BM_VERTS_OF_MESH) {
1171 bool select = false;
1172 switch (type) {
1173 case SIMVERT_EDGE: {
1174 const int num_edges = BM_vert_edge_count(vert);
1175 for (const int num_edges_iter : connected_elems_num_set) {
1176 const int delta_i = num_edges - num_edges_iter;
1177 if (mesh_select_similar_compare_int(delta_i, compare)) {
1178 select = true;
1179 break;
1180 }
1181 }
1182 break;
1183 }
1184 case SIMVERT_FACE: {
1185 const int num_faces = BM_vert_face_count(vert);
1186 for (const int num_faces_iter : connected_elems_num_set) {
1187 const int delta_i = num_faces - num_faces_iter;
1188 if (mesh_select_similar_compare_int(delta_i, compare)) {
1189 select = true;
1190 break;
1191 }
1192 }
1193 break;
1194 }
1195 case SIMVERT_NORMAL: {
1196 float normal[3];
1197 copy_v3_v3(normal, vert->no);
1198 mul_transposed_mat3_m4_v3(ob->world_to_object().ptr(), normal);
1199 normalize_v3(normal);
1200
1201 /* We are treating the normals as coordinates, the "nearest" one will
1202 * also be the one closest to the angle. */
1203 KDTreeNearest<float3> nearest;
1204 if (kdtree_find_nearest<float3>(tree_3d, normal, &nearest) != -1) {
1205 if (angle_normalized_v3v3(normal, nearest.co) <= thresh_radians) {
1206 select = true;
1207 }
1208 }
1209 break;
1210 }
1211 case SIMVERT_VGROUP: {
1212 MDeformVert *dvert = static_cast<MDeformVert *>(
1213 BM_ELEM_CD_GET_VOID_P(vert, cd_dvert_offset));
1214 MDeformWeight *dw = dvert->dw;
1215
1216 for (int i = 0; i < dvert->totweight; i++, dw++) {
1217 if (dw->weight > 0.0f) {
1218 if (dw->def_nr < defbase_len) [[likely]] {
1219 if (BLI_BITMAP_TEST(defbase_selected, dw->def_nr)) {
1220 select = true;
1221 break;
1222 }
1223 }
1224 }
1225 }
1226 break;
1227 }
1228 case SIMVERT_CREASE: {
1229 if (!has_crease_layer) {
1230 select = true;
1231 break;
1232 }
1233 const float *value = BM_ELEM_CD_GET_FLOAT_P(vert, cd_crease_offset);
1235 tree_1d, *value, thresh, eSimilarCmp(compare)))
1236 {
1237 select = true;
1238 }
1239 break;
1240 }
1241 }
1242
1243 if (select) {
1244 BM_vert_select_set(bm, vert, true);
1245 changed = true;
1246 }
1247 }
1248 }
1249
1250 if (type == SIMVERT_VGROUP) {
1251 MEM_delete(defbase_selected);
1252 }
1253
1254 if (changed) {
1257 EDBMUpdate_Params params{};
1258 params.calc_looptris = false;
1259 params.calc_normals = false;
1260 params.is_destructive = false;
1261 EDBM_update(id_cast<Mesh *>(ob->data), &params);
1262 }
1263 }
1264
1265 kdtree_free<float>(tree_1d);
1266 kdtree_free<float3>(tree_3d);
1267
1268 return OPERATOR_FINISHED;
1269}
1270
1272
1273/* -------------------------------------------------------------------- */
1276
1278{
1280 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "threshold");
1281
1282 const int type = RNA_enum_get(op->ptr, "type");
1283
1284 if (!RNA_property_is_set(op->ptr, prop)) {
1286 }
1287 else {
1288 ts->select_thresh = RNA_property_float_get(op->ptr, prop);
1289 }
1290
1291 if (type < 100) {
1292 return similar_vert_select_exec(C, op);
1293 }
1294 if (type < 200) {
1295 return similar_edge_select_exec(C, op);
1296 }
1297 return similar_face_select_exec(C, op);
1298}
1299
1301 PointerRNA * /*ptr*/,
1302 PropertyRNA * /*prop*/,
1303 bool *r_free)
1304{
1305 Object *obedit;
1306
1307 if (!C) { /* needed for docs and i18n tools */
1308 return prop_similar_types;
1309 }
1310
1311 obedit = CTX_data_edit_object(C);
1312
1313 if (obedit && obedit->type == OB_MESH) {
1314 EnumPropertyItem *item = nullptr;
1315 int a, totitem = 0;
1317
1318 if (em->selectmode & SCE_SELECT_VERTEX) {
1319 for (a = SIMVERT_NORMAL; a < SIMEDGE_LENGTH; a++) {
1320 RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a);
1321 }
1322 }
1323 else if (em->selectmode & SCE_SELECT_EDGE) {
1324 for (a = SIMEDGE_LENGTH; a < SIMFACE_MATERIAL; a++) {
1325 RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a);
1326 }
1327 }
1328 else if (em->selectmode & SCE_SELECT_FACE) {
1329#ifdef WITH_FREESTYLE
1330 const int a_end = SIMFACE_FREESTYLE;
1331#else
1332 const int a_end = SIMFACE_SMOOTH;
1333#endif
1334 for (a = SIMFACE_MATERIAL; a <= a_end; a++) {
1335 RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a);
1336 }
1337 }
1338 RNA_enum_item_end(&item, &totitem);
1339
1340 *r_free = true;
1341
1342 return item;
1343 }
1344
1345 return prop_similar_types;
1346}
1347
1349 wmOperator *op,
1350 const PropertyRNA *prop)
1351{
1352 const char *prop_id = RNA_property_identifier(prop);
1353 const int type = RNA_enum_get(op->ptr, "type");
1354
1355 /* Only show compare when it is used. */
1356 if (STREQ(prop_id, "compare")) {
1357 if (type == SIMVERT_VGROUP) {
1358 return false;
1359 }
1360 }
1361 /* Only show threshold when it is used. */
1362 else if (STREQ(prop_id, "threshold")) {
1363 if (!ELEM(type,
1374 {
1375 return false;
1376 }
1377 }
1378
1379 return true;
1380}
1381
1383{
1384 PropertyRNA *prop;
1385
1386 /* identifiers */
1387 ot->name = "Select Similar";
1388 ot->idname = "MESH_OT_select_similar";
1389 ot->description = "Select similar vertices, edges or faces by property types";
1390
1391 /* API callbacks. */
1392 ot->invoke = WM_menu_invoke;
1396
1397 /* flags */
1399
1400 /* properties */
1401 prop = ot->prop = RNA_def_enum(ot->srna, "type", prop_similar_types, SIMVERT_NORMAL, "Type", "");
1404
1405 RNA_def_enum(ot->srna, "compare", prop_similar_compare_types, SIM_CMP_EQ, "Compare", "");
1406
1407 prop = RNA_def_float(ot->srna, "threshold", 0.0f, 0.0f, 100000.0f, "Threshold", "", 0.0f, 1.0f);
1408 /* Very small values are needed sometimes, similar area of small faces for e.g: see #87823 */
1409 RNA_def_property_ui_range(prop, 0.0, 1.0, 0.01, 5);
1410}
1411
1413
1414} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
support for deformation groups and hooks.
General operations, lookup, etc. for materials.
#define BLI_BITMAP_NEW(_num, _alloc_string)
Definition BLI_bitmap.hh:39
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition BLI_bitmap.hh:63
#define BLI_BITMAP_ENABLE(_bitmap, _index)
Definition BLI_bitmap.hh:80
A KD-tree for nearest neighbor search.
#define M_PI
#define BLT_I18NCONTEXT_ID_MESH
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ELEM(...)
#define STREQ(a, b)
#define BM_ELEM_CD_GET_BOOL(ele, offset)
#define BM_ELEM_CD_GET_FLOAT(ele, offset)
#define BM_FACE_FIRST_LOOP(p)
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
int64_t size() const
Definition BLI_map.hh:976
ItemIterator items() const &
Definition BLI_map.hh:902
bool add_as(ForwardKey &&key)
Definition BLI_set.hh:256
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_set.hh:614
#define FLT_EPSILON
float length(VecOp< float, D >) RET
BMesh Iterators.
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void negate_v3_v3(float r[3], const float a[3])
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
void kdtree_balance(KDTree< CoordT > *tree)
static wmOperatorStatus similar_vert_select_exec(bContext *C, wmOperator *op)
float angle_normalized_v3v3(const float v1[3], const float v2[3]) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
int BM_edge_face_count(const BMEdge *e)
static wmOperatorStatus edbm_select_similar_exec(bContext *C, wmOperator *op)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void EDBM_selectmode_flush(BMesh *bm, short selectmode)
const ListBaseT< bDeformGroup > * BKE_object_defgroup_list(const Object *ob)
Definition deform.cc:591
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
MINLINE void copy_v3_v3(float r[3], const float a[3])
float BM_face_calc_perimeter_with_mat3(const BMFace *f, const float mat3[3][3])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
int BKE_object_defgroup_count(const Object *ob)
Definition deform.cc:608
Material *** BKE_object_material_array_p(Object *ob)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
static float edge_length_squared_worldspace_get(Object *ob, BMEdge *edge)
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
const char * RNA_property_identifier(const PropertyRNA *prop)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void EDBM_update(Mesh *mesh, const EDBMUpdate_Params *params)
float angle_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
static const EnumPropertyItem prop_similar_compare_types[]
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static int mesh_select_similar_compare_int(const int delta, const int compare)
void mul_v3_mat3_m4v3(float r[3], const float mat[4][4], const float vec[3])
int BM_edge_face_count_at_most(const BMEdge *e, const int count_max)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
Definition math_geom.cc:225
int BKE_defgroup_name_index(const ListBaseT< bDeformGroup > *defbase, StringRef name)
Definition deform.cc:544
static const EnumPropertyItem prop_similar_types[]
ViewLayer * CTX_data_view_layer(const bContext *C)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
KDTree< CoordT > * kdtree_new(uint nodes_len_capacity)
Definition BLI_kdtree.hh:65
void mul_m4_v3(const float M[4][4], float r[3])
bool ED_operator_editmesh(bContext *C)
static const EnumPropertyItem * select_similar_type_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
static void edge_pos_direction_worldspace_get(Object *ob, BMEdge *edge, float *r_dir)
int BM_vert_face_count(const BMVert *v)
bool ED_select_similar_compare_float_tree(const KDTree< float > *tree, float length, float thresh, eSimilarCmp compare)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
static bool edge_data_value_set(BMEdge *edge, const int hflag, int *r_value)
Object * CTX_data_edit_object(const bContext *C)
static bool face_data_value_set(BMFace *face, const int hflag, int *r_value)
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, StringRef name)
void kdtree_insert(KDTree< CoordT > *tree, int index, const CoordT &co)
Definition BLI_kdtree.hh:96
void BM_face_select_set(BMesh *bm, BMFace *f, const bool select)
Select Face.
int kdtree_find_nearest(const KDTree< CoordT > *tree, const CoordT &co, KDTreeNearest< CoordT > *r_nearest)
static wmOperatorStatus similar_edge_select_exec(bContext *C, wmOperator *op)
void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item, int value)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
ToolSettings * CTX_data_tool_settings(const bContext *C)
void MESH_OT_select_similar(wmOperatorType *ot)
void BM_vert_select_set(BMesh *bm, BMVert *v, const bool select)
Select Vert.
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
MINLINE float normalize_v3(float n[3])
void kdtree_free(KDTree< CoordT > *tree)
Definition BLI_kdtree.hh:84
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
unsigned int BLI_bitmap
Definition BLI_bitmap.hh:15
Main * CTX_data_main(const bContext *C)
static bool edbm_select_similar_poll_property(const bContext *, wmOperator *op, const PropertyRNA *prop)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
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)
const BMesh * BKE_editmesh_bmesh_get(const Object *ob)
Definition editmesh.cc:65
float BM_edge_calc_face_angle_with_imat3(const BMEdge *e, const float imat3[3][3])
bool EDBM_uvselect_clear(BMesh *bm)
static void face_to_plane(const Object *ob, BMFace *face, float r_plane[4])
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
bool CustomData_has_layer_named(const CustomData *data, eCustomDataType type, StringRef name)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
View3D * CTX_wm_view3d(const bContext *C)
int BM_vert_edge_count(const BMVert *v)
float BM_face_calc_area_with_mat3(const BMFace *f, const float mat3[3][3])
static wmOperatorStatus similar_face_select_exec(bContext *C, wmOperator *op)
void mul_transposed_mat3_m4_v3(const float M[4][4], float r[3])
void BM_edge_select_set(BMesh *bm, BMEdge *e, const bool select)
Select Edge.
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct MDeformWeight * dw
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) poll_property(const bContext *C, wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1171
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports