Blender V5.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
8
9#include "DNA_curve_types.h"
10#include "DNA_object_types.h"
11
12#include "BLI_array.hh"
13#include "BLI_listbase.hh"
15#include "BLI_vector.hh"
16
17#include "BKE_context.hh"
18#include "BKE_curve.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_report.hh"
25
26#include "DEG_depsgraph.hh"
28
29#include "RNA_access.hh"
30#include "RNA_define.hh"
31
32#include "WM_types.hh"
33
34#include "ED_mesh.hh"
35#include "ED_screen.hh"
36#include "ED_view3d.hh"
37
38#include "mesh_intern.hh" /* own include */
39
40namespace blender {
41
43 Object *ob,
44 Vector<Array<float2>> &polys)
45{
46 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
47 ARegion *region = CTX_wm_region(C);
48 const Mesh *mesh_eval;
49 bool mesh_eval_needs_free;
50
51 if (ob->type == OB_MESH || ob->runtime->data_eval) {
52 const Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
53 mesh_eval = BKE_object_get_evaluated_mesh(ob_eval);
54 mesh_eval_needs_free = false;
55 }
56 else if (ELEM(ob->type, OB_FONT, OB_CURVES_LEGACY, OB_SURF)) {
57 const Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
58 mesh_eval = BKE_mesh_new_nomain_from_curve(ob_eval);
59 mesh_eval_needs_free = true;
60 }
61 else {
62 mesh_eval = nullptr;
63 }
64
65 if (mesh_eval) {
66 ListBaseT<Nurb> nurbslist = {nullptr, nullptr};
67
68 BKE_mesh_to_curve_nurblist(mesh_eval, &nurbslist, 0); /* wire */
69 BKE_mesh_to_curve_nurblist(mesh_eval, &nurbslist, 1); /* boundary */
70
72 static_cast<RegionView3D *>(region->regiondata), ob);
73
74 if (nurbslist.first_) {
75 for (Nurb &nu : nurbslist) {
76 if (nu.bp) {
77 int a;
78 BPoint *bp;
79 bool is_cyclic = (nu.flagu & CU_NURB_CYCLIC) != 0;
80 Array<float2> mval(nu.pntsu + is_cyclic);
81
82 for (bp = nu.bp, a = 0; a < nu.pntsu; a++, bp++) {
83 mval[a] = ED_view3d_project_float_v2_m4(region, bp->vec, projmat);
84 }
85 if (is_cyclic) {
86 mval[a] = mval[0];
87 }
88
89 polys.append(std::move(mval));
90 }
91 }
92 }
93
94 BKE_nurbList_free(&nurbslist);
95
96 if (mesh_eval_needs_free) {
97 BKE_id_free(nullptr, id_cast<ID *>(const_cast<Mesh *>(mesh_eval)));
98 }
99 }
100}
101
103{
104 Scene *scene = CTX_data_scene(C);
105 const bool cut_through = RNA_boolean_get(op->ptr, "cut_through");
106
108
109 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
111 continue;
112 }
114 }
116
117 if (polys.is_empty()) {
119 RPT_ERROR,
120 "No other selected objects have wire or boundary edges to use for projection");
121 return OPERATOR_CANCELLED;
122 }
123
125
127 *vc.bmain, vc.scene, vc.view_layer, vc.v3d);
128
129 EDBM_mesh_knife(&vc, objects, polys, true, cut_through);
130
131 for (Object *obedit : objects) {
135
136 /* select only tagged faces */
138
140
142
144 }
145
146 return OPERATOR_FINISHED;
147}
148
150{
151 /* description */
152 ot->name = "Knife Project";
153 ot->idname = "MESH_OT_knife_project";
154 ot->description = "Use other objects outlines and boundaries to project knife cuts";
155
156 /* callbacks */
159
160 /* flags */
162
163 /* parameters */
165 "cut_through",
166 false,
167 "Cut Through",
168 "Cut through all faces, not just visible ones");
169}
170
171} // namespace blender
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
General operations, lookup, etc. for blender objects.
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
#define ELEM(...)
bool is_empty() const
BMesh Iterators.
void BKE_mesh_to_curve_nurblist(const Mesh *mesh, ListBaseT< Nurb > *nurblist, int edge_users_test)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
float4x4 ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob)
bool EDBM_selectmode_disable(Scene *scene, BMEditMesh *em, BMesh *bm, short selectmode_disable, short selectmode_fallback)
void BKE_nurbList_free(ListBaseT< Nurb > *lb)
Definition curve.cc:619
float2 ED_view3d_project_float_v2_m4(const ARegion *region, const float co[3], const float4x4 &mat)
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
MatBase< float, 4, 4 > float4x4
void BM_mesh_select_mode_flush(BMesh *bm)
void ED_view3d_viewcontext_init_object(ViewContext *vc, Object *obact)
void EDBM_mesh_knife(ViewContext *vc, const Span< Object * > objects, const Span< Array< float2 > > polys, bool use_tag, bool cut_through)
void MESH_OT_knife_project(wmOperatorType *ot)
Mesh * BKE_mesh_new_nomain_from_curve(const Object *ob)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
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)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void BKE_id_free(Main *bmain, void *idv)
static wmOperatorStatus knifeproject_exec(bContext *C, wmOperator *op)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
ViewContext em_setup_viewcontext(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)
bool ED_operator_editmesh_region_view3d(bContext *C)
Scene * CTX_data_scene(const bContext *C)
static void knifeproject_poly_from_object(const bContext *C, Object *ob, Vector< Array< float2 > > &polys)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
ARegion * CTX_wm_region(const bContext *C)
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Definition object.cc:4436
bke::ObjectRuntime * runtime
ViewLayer * view_layer
Definition ED_view3d.hh:80
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