2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2013-08-22 17:56:08 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bmesh
|
2013-08-22 17:56:08 +00:00
|
|
|
*
|
|
|
|
|
* Wrapper around #BM_mesh_bisect_plane
|
|
|
|
|
*/
|
|
|
|
|
|
2013-08-23 11:11:59 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
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_geom.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2013-08-22 17:56:08 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2017-09-19 20:16:05 +10:00
|
|
|
#include "BLI_utildefines_stack.h"
|
2013-08-22 17:56:08 +00:00
|
|
|
|
|
|
|
|
#include "bmesh.h"
|
2013-08-23 04:22:07 +00:00
|
|
|
#include "bmesh_tools.h"
|
2013-08-22 17:56:08 +00:00
|
|
|
|
|
|
|
|
#include "intern/bmesh_operators_private.h" /* own include */
|
|
|
|
|
|
|
|
|
|
#define ELE_NEW 1
|
2017-03-13 09:22:11 -03:00
|
|
|
#define ELE_CUT 2
|
|
|
|
|
#define ELE_INPUT 4
|
2013-08-22 17:56:08 +00:00
|
|
|
|
|
|
|
|
void bmo_bisect_plane_exec(BMesh *bm, BMOperator *op)
|
|
|
|
|
{
|
|
|
|
|
const float dist = BMO_slot_float_get(op->slots_in, "dist");
|
2013-08-23 05:32:43 +00:00
|
|
|
const bool use_snap_center = BMO_slot_bool_get(op->slots_in, "use_snap_center");
|
2013-08-22 17:56:08 +00:00
|
|
|
const bool clear_outer = BMO_slot_bool_get(op->slots_in, "clear_outer");
|
|
|
|
|
const bool clear_inner = BMO_slot_bool_get(op->slots_in, "clear_inner");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-22 17:56:08 +00:00
|
|
|
float plane_co[3];
|
|
|
|
|
float plane_no[3];
|
|
|
|
|
float plane[4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-22 17:56:08 +00:00
|
|
|
BMO_slot_vec_get(op->slots_in, "plane_co", plane_co);
|
|
|
|
|
BMO_slot_vec_get(op->slots_in, "plane_no", plane_no);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-22 17:56:08 +00:00
|
|
|
if (is_zero_v3(plane_no)) {
|
2021-07-02 12:46:08 +10:00
|
|
|
BMO_error_raise(bm, op, BMO_ERROR_CANCEL, "Zero normal given");
|
2013-08-22 17:56:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-22 17:56:08 +00:00
|
|
|
plane_from_point_normal_v3(plane, plane_co, plane_no);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-22 17:56:08 +00:00
|
|
|
/* tag geometry to bisect */
|
|
|
|
|
BM_mesh_elem_hflag_disable_all(bm, BM_EDGE | BM_FACE, BM_ELEM_TAG, false);
|
|
|
|
|
BMO_slot_buffer_hflag_enable(bm, op->slots_in, "geom", BM_EDGE | BM_FACE, BM_ELEM_TAG, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-22 17:56:08 +00:00
|
|
|
BMO_slot_buffer_flag_enable(bm, op->slots_in, "geom", BM_ALL_NOLOOP, ELE_INPUT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-23 05:32:43 +00:00
|
|
|
BM_mesh_bisect_plane(bm, plane, use_snap_center, true, ELE_CUT, ELE_NEW, dist);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-22 17:56:08 +00:00
|
|
|
if (clear_outer || clear_inner) {
|
2020-09-10 09:45:25 +10:00
|
|
|
/* Use an array of vertices because 'geom' contains both verts and edges that may use them.
|
|
|
|
|
* Removing a vert may remove and edge which is later checked by #BMO_ITER.
|
|
|
|
|
* over-allocate the total possible vert count. */
|
2021-07-06 12:05:27 +10:00
|
|
|
const int vert_arr_max = min_ii(bm->totvert, BMO_slot_buffer_len(op->slots_in, "geom"));
|
2023-07-26 16:12:55 +02:00
|
|
|
BMVert **vert_arr = static_cast<BMVert **>(
|
2023-07-27 11:23:35 +10:00
|
|
|
MEM_mallocN(sizeof(*vert_arr) * size_t(vert_arr_max), __func__));
|
2013-08-22 17:56:08 +00:00
|
|
|
BMOIter siter;
|
|
|
|
|
BMVert *v;
|
2013-08-23 10:19:58 +00:00
|
|
|
float plane_inner[4];
|
|
|
|
|
float plane_outer[4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-23 11:11:59 +00:00
|
|
|
STACK_DECLARE(vert_arr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-23 10:19:58 +00:00
|
|
|
copy_v3_v3(plane_outer, plane);
|
|
|
|
|
copy_v3_v3(plane_inner, plane);
|
|
|
|
|
plane_outer[3] = plane[3] - dist;
|
|
|
|
|
plane_inner[3] = plane[3] + dist;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-06-29 05:06:22 +10:00
|
|
|
STACK_INIT(vert_arr, vert_arr_max);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-23 10:19:58 +00:00
|
|
|
BMO_ITER (v, &siter, op->slots_in, "geom", BM_VERT) {
|
|
|
|
|
if ((clear_outer && plane_point_side_v3(plane_outer, v->co) > 0.0f) ||
|
|
|
|
|
(clear_inner && plane_point_side_v3(plane_inner, v->co) < 0.0f))
|
|
|
|
|
{
|
2013-08-23 11:11:59 +00:00
|
|
|
STACK_PUSH(vert_arr, v);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-08-22 17:56:08 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-23 11:11:59 +00:00
|
|
|
while ((v = STACK_POP(vert_arr))) {
|
|
|
|
|
BM_vert_kill(bm, v);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-23 11:11:59 +00:00
|
|
|
MEM_freeN(vert_arr);
|
2013-08-22 17:56:08 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-22 17:56:08 +00:00
|
|
|
BMO_slot_buffer_from_enabled_flag(
|
|
|
|
|
bm, op, op->slots_out, "geom.out", BM_ALL_NOLOOP, ELE_NEW | ELE_INPUT);
|
2017-03-13 09:22:11 -03:00
|
|
|
BMO_slot_buffer_from_enabled_flag(
|
|
|
|
|
bm, op, op->slots_out, "geom_cut.out", BM_VERT | BM_EDGE, ELE_CUT);
|
2013-08-22 17:56:08 +00:00
|
|
|
}
|