Blender V4.3
editmesh_knife_project.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "DNA_curve_types.h"
10#include "DNA_object_types.h"
11
12#include "BLI_linklist.h"
13#include "BLI_listbase.h"
14#include "BLI_math_vector.h"
15
16#include "BKE_context.hh"
17#include "BKE_curve.hh"
18#include "BKE_customdata.hh"
19#include "BKE_editmesh.hh"
20#include "BKE_layer.hh"
21#include "BKE_lib_id.hh"
22#include "BKE_mesh.hh"
23#include "BKE_object.hh"
24#include "BKE_object_types.hh"
25#include "BKE_report.hh"
26
27#include "DEG_depsgraph.hh"
29
30#include "RNA_access.hh"
31#include "RNA_define.hh"
32
33#include "MEM_guardedalloc.h"
34
35#include "WM_types.hh"
36
37#include "ED_mesh.hh"
38#include "ED_screen.hh"
39#include "ED_view3d.hh"
40
41#include "mesh_intern.hh" /* own include */
42
43using blender::Vector;
44
46{
48 ARegion *region = CTX_wm_region(C);
49 const Mesh *mesh_eval;
50 bool mesh_eval_needs_free;
51
52 if (ob->type == OB_MESH || ob->runtime->data_eval) {
53 const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
54 mesh_eval = BKE_object_get_evaluated_mesh(ob_eval);
55 mesh_eval_needs_free = false;
56 }
57 else if (ELEM(ob->type, OB_FONT, OB_CURVES_LEGACY, OB_SURF)) {
58 const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
59 mesh_eval = BKE_mesh_new_nomain_from_curve(ob_eval);
60 mesh_eval_needs_free = true;
61 }
62 else {
63 mesh_eval = nullptr;
64 }
65
66 if (mesh_eval) {
67 ListBase nurbslist = {nullptr, nullptr};
68
69 BKE_mesh_to_curve_nurblist(mesh_eval, &nurbslist, 0); /* wire */
70 BKE_mesh_to_curve_nurblist(mesh_eval, &nurbslist, 1); /* boundary */
71
73 static_cast<RegionView3D *>(region->regiondata), ob);
74
75 if (nurbslist.first) {
76 LISTBASE_FOREACH (Nurb *, nu, &nurbslist) {
77 if (nu->bp) {
78 int a;
79 BPoint *bp;
80 bool is_cyclic = (nu->flagu & CU_NURB_CYCLIC) != 0;
81 float(*mval)[2] = static_cast<float(*)[2]>(
82 MEM_mallocN(sizeof(*mval) * (nu->pntsu + is_cyclic), __func__));
83
84 for (bp = nu->bp, a = 0; a < nu->pntsu; a++, bp++) {
85 copy_v2_v2(mval[a], ED_view3d_project_float_v2_m4(region, bp->vec, projmat));
86 }
87 if (is_cyclic) {
88 copy_v2_v2(mval[a], mval[0]);
89 }
90
91 BLI_linklist_prepend(&polys, mval);
92 }
93 }
94 }
95
96 BKE_nurbList_free(&nurbslist);
97
98 if (mesh_eval_needs_free) {
99 BKE_id_free(nullptr, (ID *)mesh_eval);
100 }
101 }
102
103 return polys;
104}
105
107{
108 Scene *scene = CTX_data_scene(C);
109 const bool cut_through = RNA_boolean_get(op->ptr, "cut_through");
110
111 LinkNode *polys = nullptr;
112
113 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
115 continue;
116 }
117 polys = knifeproject_poly_from_object(C, ob, polys);
118 }
120
121 if (polys == nullptr) {
123 RPT_ERROR,
124 "No other selected objects have wire or boundary edges to use for projection");
125 return OPERATOR_CANCELLED;
126 }
127
129
131 vc.scene, vc.view_layer, vc.v3d);
132
133 EDBM_mesh_knife(&vc, objects, polys, true, cut_through);
134
135 for (Object *obedit : objects) {
138
139 /* select only tagged faces */
141
143
145
147 }
148
149 BLI_linklist_freeN(polys);
150
151 return OPERATOR_FINISHED;
152}
153
155{
156 /* description */
157 ot->name = "Knife Project";
158 ot->idname = "MESH_OT_knife_project";
159 ot->description = "Use other objects outlines and boundaries to project knife cuts";
160
161 /* callbacks */
164
165 /* flags */
167
168 /* parameters */
170 "cut_through",
171 false,
172 "Cut Through",
173 "Cut through all faces, not just visible ones");
174}
#define CTX_DATA_BEGIN(C, Type, instance, member)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
#define CTX_DATA_END
void BKE_nurbList_free(ListBase *lb)
Definition curve.cc:596
CustomData interface, see also DNA_customdata_types.h.
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:63
blender::Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
void BKE_id_free(Main *bmain, void *idv)
Mesh * BKE_mesh_new_nomain_from_curve(const Object *ob)
void BKE_mesh_to_curve_nurblist(const Mesh *mesh, ListBase *nurblist, int edge_users_test)
General operations, lookup, etc. for blender objects.
bool BKE_object_is_in_editmode(const Object *ob)
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
#define LISTBASE_FOREACH(type, var, list)
MINLINE void copy_v2_v2(float r[2], const float a[2])
#define ELEM(...)
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
@ CU_NURB_CYCLIC
Object is a sort of wrapper for general info.
@ OB_SURF
@ OB_FONT
@ OB_MESH
@ OB_CURVES_LEGACY
@ SCE_SELECT_VERTEX
@ SCE_SELECT_EDGE
bool EDBM_selectmode_disable(Scene *scene, BMEditMesh *em, short selectmode_disable, short selectmode_fallback)
ViewContext em_setup_viewcontext(bContext *C)
bool ED_operator_editmesh_region_view3d(bContext *C)
blender::float2 ED_view3d_project_float_v2_m4(const ARegion *region, const float co[3], const blender::float4x4 &mat)
blender::float4x4 ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob)
void ED_view3d_viewcontext_init_object(ViewContext *vc, Object *obact)
Read Guarded memory(de)allocation.
@ OPTYPE_BLOCKING
Definition WM_types.hh:164
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
@ BM_ELEM_SELECT
@ BM_ELEM_TAG
void BM_mesh_select_mode_flush(BMesh *bm)
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
void BM_mesh_elem_hflag_enable_test(BMesh *bm, const char htype, const char hflag, const bool respecthide, const bool overwrite, const char hflag_test)
#define BM_FACE
#define BM_EDGE
#define BM_VERT
const Depsgraph * depsgraph
static bool is_cyclic(const Nurb *nu)
void EDBM_mesh_knife(ViewContext *vc, const Span< Object * > objects, LinkNode *polys, bool use_tag, bool cut_through)
static LinkNode * knifeproject_poly_from_object(const bContext *C, Object *ob, LinkNode *polys)
void MESH_OT_knife_project(wmOperatorType *ot)
static int knifeproject_exec(bContext *C, wmOperator *op)
draw_view in_light_buf[] float
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
float vec[4]
Definition DNA_ID.h:413
void * first
ObjectRuntimeHandle * runtime
Scene * scene
Definition ED_view3d.hh:69
ViewLayer * view_layer
Definition ED_view3d.hh:70
View3D * v3d
Definition ED_view3d.hh:74
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
StructRNA * srna
Definition WM_types.hh:1080
struct ReportList * reports
struct PointerRNA * ptr
wmOperatorType * ot
Definition wm_files.cc:4125