Blender V5.3
mesh_convert.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "CLG_log.h"
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_curve_types.h"
14#include "DNA_key_types.h"
15#include "DNA_material_types.h"
16#include "DNA_object_types.h"
18#include "DNA_scene_types.h"
19
20#include "BLI_index_range.hh"
21#include "BLI_listbase.hh"
22#include "BLI_span.hh"
23#include "BLI_string.hh"
24#include "BLI_utildefines.hh"
25
26#include "BLT_translation.hh"
27
28#include "BKE_curves.hh"
29#include "BKE_deform.hh"
30#include "BKE_displist.h"
31#include "BKE_editmesh.hh"
32#include "BKE_geometry_set.hh"
34#include "BKE_key.hh"
35#include "BKE_lib_id.hh"
36#include "BKE_lib_query.hh"
37#include "BKE_main.hh"
38#include "BKE_material.hh"
39#include "BKE_mball.hh"
40#include "BKE_mesh.hh"
41#include "BKE_mesh_runtime.hh"
42#include "BKE_mesh_wrapper.hh"
43#include "BKE_modifier.hh"
44#include "BKE_object_types.hh"
45/* these 2 are only used by conversion functions */
46#include "BKE_curve.hh"
47/* -- */
48#include "BKE_object.hh"
49/* -- */
50#include "BKE_pointcloud.hh"
51
52#include "BKE_curve_to_mesh.hh"
53
54#include "DEG_depsgraph.hh"
56
57namespace blender {
58
59static CLG_LogRef LOG = {"geom.mesh.convert"};
60
61static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBaseT<DispList> *dispbase)
62{
63 using namespace blender::bke;
64 int a, b, ofs;
65 const bool conv_polys = (
66 /* 2D polys are filled with #DispList.type == #DL_INDEX3. */
67 (CU_DO_2DFILL(cu) == false) ||
68 /* surf polys are never filled */
69 (cu->ob_type == OB_SURF));
70
71 /* count */
72 int totvert = 0;
73 int totedge = 0;
74 int faces_num = 0;
75 int totloop = 0;
76 for (const DispList &dl : *dispbase) {
77 if (dl.type == DL_SEGM) {
78 totvert += dl.parts * dl.nr;
79 totedge += dl.parts * (dl.nr - 1);
80 }
81 else if (dl.type == DL_POLY) {
82 if (conv_polys) {
83 totvert += dl.parts * dl.nr;
84 totedge += dl.parts * dl.nr;
85 }
86 }
87 else if (dl.type == DL_SURF) {
88 if (dl.parts != 0) {
89 int tot;
90 totvert += dl.parts * dl.nr;
91 tot = (((dl.flag & DL_CYCL_U) ? 1 : 0) + (dl.nr - 1)) *
92 (((dl.flag & DL_CYCL_V) ? 1 : 0) + (dl.parts - 1));
93 faces_num += tot;
94 totloop += tot * 4;
95 }
96 }
97 else if (dl.type == DL_INDEX3) {
98 int tot;
99 totvert += dl.nr;
100 tot = dl.parts;
101 faces_num += tot;
102 totloop += tot * 3;
103 }
104 }
105
106 if (totvert == 0) {
107 return BKE_mesh_new_nomain(0, 0, 0, 0);
108 }
109
110 Mesh *mesh = BKE_mesh_new_nomain(totvert, totedge, faces_num, totloop);
111 MutableSpan<float3> positions = mesh->vert_positions_for_write();
112 MutableSpan<int2> edges = mesh->edges_for_write();
113 MutableSpan<int> face_offsets = mesh->face_offsets_for_write();
114 MutableSpan<int> corner_verts = mesh->corner_verts_for_write();
115
116 MutableAttributeAccessor attributes = mesh->attributes_for_write();
117 SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_only_span<int>(
118 "material_index", AttrDomain::Face);
119 SpanAttributeWriter<bool> sharp_faces = attributes.lookup_or_add_for_write_span<bool>(
120 "sharp_face", AttrDomain::Face);
121 const StringRef uv_name = DATA_("UVMap");
123 uv_name, AttrDomain::Corner);
124 mesh->uv_maps_active_set(uv_name);
125 mesh->uv_maps_default_set(uv_name);
126 MutableSpan<float2> uv_map = uv_attribute.span;
127
128 int dst_vert = 0;
129 int dst_edge = 0;
130 int dst_poly = 0;
131 int dst_loop = 0;
132 for (const DispList &dl : *dispbase) {
133 const bool is_smooth = (dl.rt & CU_SMOOTH) != 0;
134
135 if (dl.type == DL_SEGM) {
136 const int startvert = dst_vert;
137 a = dl.parts * dl.nr;
138 const float *data = dl.verts;
139 while (a--) {
140 copy_v3_v3(positions[dst_vert], data);
141 data += 3;
142 dst_vert++;
143 }
144
145 for (a = 0; a < dl.parts; a++) {
146 ofs = a * dl.nr;
147 for (b = 1; b < dl.nr; b++) {
148 edges[dst_edge][0] = startvert + ofs + b - 1;
149 edges[dst_edge][1] = startvert + ofs + b;
150
151 dst_edge++;
152 }
153 }
154 }
155 else if (dl.type == DL_POLY) {
156 if (conv_polys) {
157 const int startvert = dst_vert;
158 a = dl.parts * dl.nr;
159 const float *data = dl.verts;
160 while (a--) {
161 copy_v3_v3(positions[dst_vert], data);
162 data += 3;
163 dst_vert++;
164 }
165
166 for (a = 0; a < dl.parts; a++) {
167 ofs = a * dl.nr;
168 for (b = 0; b < dl.nr; b++) {
169 edges[dst_edge][0] = startvert + ofs + b;
170 if (b == dl.nr - 1) {
171 edges[dst_edge][1] = startvert + ofs;
172 }
173 else {
174 edges[dst_edge][1] = startvert + ofs + b + 1;
175 }
176 dst_edge++;
177 }
178 }
179 }
180 }
181 else if (dl.type == DL_INDEX3) {
182 const int startvert = dst_vert;
183 a = dl.nr;
184 const float *data = dl.verts;
185 while (a--) {
186 copy_v3_v3(positions[dst_vert], data);
187 data += 3;
188 dst_vert++;
189 }
190
191 a = dl.parts;
192 const int *index = dl.index;
193 while (a--) {
194 corner_verts[dst_loop + 0] = startvert + index[0];
195 corner_verts[dst_loop + 1] = startvert + index[2];
196 corner_verts[dst_loop + 2] = startvert + index[1];
197 face_offsets[dst_poly] = dst_loop;
198 material_indices.span[dst_poly] = dl.col;
199
200 for (int i = 0; i < 3; i++) {
201 uv_map[dst_loop + i][0] = (corner_verts[dst_loop + i] - startvert) / float(dl.nr - 1);
202 uv_map[dst_loop + i][1] = 0.0f;
203 }
204
205 sharp_faces.span[dst_poly] = !is_smooth;
206 dst_poly++;
207 dst_loop += 3;
208 index += 3;
209 }
210 }
211 else if (dl.type == DL_SURF) {
212 const int startvert = dst_vert;
213 a = dl.parts * dl.nr;
214 const float *data = dl.verts;
215 while (a--) {
216 copy_v3_v3(positions[dst_vert], data);
217 data += 3;
218 dst_vert++;
219 }
220
221 for (a = 0; a < dl.parts; a++) {
222
223 if ((dl.flag & DL_CYCL_V) == 0 && a == dl.parts - 1) {
224 break;
225 }
226
227 int p1, p2, p3, p4;
228 if (dl.flag & DL_CYCL_U) { /* p2 -> p1 -> */
229 p1 = startvert + dl.nr * a; /* p4 -> p3 -> */
230 p2 = p1 + dl.nr - 1; /* -----> next row */
231 p3 = p1 + dl.nr;
232 p4 = p2 + dl.nr;
233 b = 0;
234 }
235 else {
236 p2 = startvert + dl.nr * a;
237 p1 = p2 + 1;
238 p4 = p2 + dl.nr;
239 p3 = p1 + dl.nr;
240 b = 1;
241 }
242 if ((dl.flag & DL_CYCL_V) && a == dl.parts - 1) {
243 p3 -= dl.parts * dl.nr;
244 p4 -= dl.parts * dl.nr;
245 }
246
247 for (; b < dl.nr; b++) {
248 corner_verts[dst_loop + 0] = p1;
249 corner_verts[dst_loop + 1] = p3;
250 corner_verts[dst_loop + 2] = p4;
251 corner_verts[dst_loop + 3] = p2;
252 face_offsets[dst_poly] = dst_loop;
253 material_indices.span[dst_poly] = dl.col;
254
255 int orco_sizeu = dl.nr - 1;
256 int orco_sizev = dl.parts - 1;
257
258 /* exception as handled in convertblender.c too */
259 if (dl.flag & DL_CYCL_U) {
260 orco_sizeu++;
261 if (dl.flag & DL_CYCL_V) {
262 orco_sizev++;
263 }
264 }
265 else if (dl.flag & DL_CYCL_V) {
266 orco_sizev++;
267 }
268
269 for (int i = 0; i < 4; i++) {
270 /* find uv based on vertex index into grid array */
271 int v = corner_verts[dst_loop + i] - startvert;
272
273 uv_map[dst_loop + i][0] = (v / dl.nr) / float(orco_sizev);
274 uv_map[dst_loop + i][1] = (v % dl.nr) / float(orco_sizeu);
275
276 /* cyclic correction */
277 if (ELEM(i, 1, 2) && uv_map[dst_loop + i][0] == 0.0f) {
278 uv_map[dst_loop + i][0] = 1.0f;
279 }
280 if (ELEM(i, 0, 1) && uv_map[dst_loop + i][1] == 0.0f) {
281 uv_map[dst_loop + i][1] = 1.0f;
282 }
283 }
284
285 sharp_faces.span[dst_poly] = !is_smooth;
286 dst_poly++;
287 dst_loop += 4;
288
289 p4 = p3;
290 p3++;
291 p2 = p1;
292 p1++;
293 }
294 }
295 }
296 }
297
298 if (faces_num) {
299 mesh_calc_edges(*mesh, true, false);
300 }
301
302 material_indices.finish();
303 sharp_faces.finish();
304 uv_attribute.finish();
305
306 return mesh;
307}
308
317{
319 copy_v3_v3(mesh->texspace_location, cu->texspace_location);
320 copy_v3_v3(mesh->texspace_size, cu->texspace_size);
322}
323
325 const ListBaseT<DispList> *dispbase)
326{
327 const Curve *cu = id_cast<const Curve *>(ob->data);
328
329 Mesh *mesh = mesh_nurbs_displist_to_mesh(cu, dispbase);
331 mesh->mat = MEM_dupalloc(cu->mat);
332 mesh->totcol = cu->totcol;
333
334 return mesh;
335}
336
338{
339 ListBaseT<DispList> disp = {nullptr, nullptr};
340
341 if (ob->runtime->curve_cache) {
342 disp = ob->runtime->curve_cache->disp;
343 }
344
346}
347
348struct EdgeLink {
350 const void *edge;
351};
352
357
358static void prependPolyLineVert(ListBaseT<VertLink> *lb, uint index)
359{
360 VertLink *vl = MEM_new_zeroed<VertLink>("VertLink");
361 vl->index = index;
362 BLI_addhead(lb, vl);
363}
364
365static void appendPolyLineVert(ListBaseT<VertLink> *lb, uint index)
366{
367 VertLink *vl = MEM_new_zeroed<VertLink>("VertLink");
368 vl->index = index;
369 BLI_addtail(lb, vl);
370}
371
373 ListBaseT<Nurb> *nurblist,
374 const int edge_users_test)
375{
376 const Span<float3> positions = mesh->vert_positions();
377 const Span<int2> mesh_edges = mesh->edges();
378 const OffsetIndices polys = mesh->faces();
379 const Span<int> corner_edges = mesh->corner_edges();
380
381 /* only to detect edge polylines */
382 int *edge_users;
383
384 ListBaseT<EdgeLink> edges = {nullptr, nullptr};
385
386 /* get boundary edges */
387 edge_users = MEM_new_array_zeroed<int>(mesh_edges.size(), __func__);
388 for (const int i : polys.index_range()) {
389 for (const int edge : corner_edges.slice(polys[i])) {
390 edge_users[edge]++;
391 }
392 }
393
394 /* create edges from all faces (so as to find edges not in any faces) */
395 for (const int i : mesh_edges.index_range()) {
396 if (edge_users[i] == edge_users_test) {
397 EdgeLink *edl = MEM_new_zeroed<EdgeLink>("EdgeLink");
398 edl->edge = &mesh_edges[i];
399
400 BLI_addtail(&edges, edl);
401 }
402 }
403 MEM_delete(edge_users);
404
405 if (edges.first()) {
406 while (edges.first()) {
407 /* each iteration find a polyline and add this as a nurbs poly spline */
408
409 ListBaseT<VertLink> polyline = {nullptr, nullptr}; /* store a list of VertLink's */
410 bool closed = false;
411 int faces_num = 0;
412 int2 &edge_current = *static_cast<int2 *>(const_cast<void *>((edges.last())->edge));
413 uint startVert = edge_current[0];
414 uint endVert = edge_current[1];
415 bool ok = true;
416
417 appendPolyLineVert(&polyline, startVert);
418 faces_num++;
419 appendPolyLineVert(&polyline, endVert);
420 faces_num++;
421 BLI_freelinkN(&edges, edges.last());
422
423 while (ok) { /* while connected edges are found... */
424 EdgeLink *edl = edges.last();
425 ok = false;
426 while (edl) {
427 EdgeLink *edl_prev = edl->prev;
428
429 const int2 &edge = *static_cast<int2 *>(const_cast<void *>(edl->edge));
430
431 if (edge[0] == endVert) {
432 endVert = edge[1];
433 appendPolyLineVert(&polyline, endVert);
434 faces_num++;
435 BLI_freelinkN(&edges, edl);
436 ok = true;
437 }
438 else if (edge[1] == endVert) {
439 endVert = edge[0];
440 appendPolyLineVert(&polyline, endVert);
441 faces_num++;
442 BLI_freelinkN(&edges, edl);
443 ok = true;
444 }
445 else if (edge[0] == startVert) {
446 startVert = edge[1];
447 prependPolyLineVert(&polyline, startVert);
448 faces_num++;
449 BLI_freelinkN(&edges, edl);
450 ok = true;
451 }
452 else if (edge[1] == startVert) {
453 startVert = edge[0];
454 prependPolyLineVert(&polyline, startVert);
455 faces_num++;
456 BLI_freelinkN(&edges, edl);
457 ok = true;
458 }
459
460 edl = edl_prev;
461 }
462 }
463
464 /* Now we have a polyline, make into a curve */
465 if (startVert == endVert) {
466 BLI_freelinkN(&polyline, polyline.last());
467 faces_num--;
468 closed = true;
469 }
470
471 /* --- nurbs --- */
472 {
473 Nurb *nu;
474 BPoint *bp;
475 VertLink *vl;
476
477 /* create new 'nurb' within the curve */
478 nu = MEM_new<Nurb>(__func__);
479
480 nu->pntsu = faces_num;
481 nu->pntsv = 1;
482 nu->orderu = 4;
483 nu->flagu = CU_NURB_ENDPOINT | (closed ? CU_NURB_CYCLIC : eNurbKnotFlag{}); /* endpoint */
484 nu->resolu = 12;
485
486 nu->bp = MEM_new_array_zeroed<BPoint>(faces_num, "bpoints");
487
488 /* add points */
489 vl = polyline.first();
490 int i;
491 for (i = 0, bp = nu->bp; i < faces_num;
492 i++, bp++, vl = reinterpret_cast<VertLink *>(vl->next))
493 {
494 copy_v3_v3(bp->vec, positions[vl->index]);
495 bp->f1 = SELECT;
496 bp->radius = bp->weight = 1.0;
497 }
498 polyline.free_no_destruct();
499
500 /* add nurb to curve */
501 BLI_addtail(nurblist, nu);
502 }
503 /* --- done with nurbs --- */
504 }
505 }
506}
507
508void BKE_mesh_to_curve(Main *bmain, Depsgraph *depsgraph, Scene * /*scene*/, Object *ob)
509{
510 const Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
511 if (!ob_eval) {
512 return;
513 }
514 Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob_eval);
515 if (!mesh_eval) {
516 return;
517 }
519
520 ListBaseT<Nurb> nurblist = {nullptr, nullptr};
521
522 BKE_mesh_to_curve_nurblist(mesh_eval, &nurblist, 0);
523 BKE_mesh_to_curve_nurblist(mesh_eval, &nurblist, 1);
524
525 if (nurblist.first()) {
526 Curve *cu = BKE_curve_add(bmain, ob->id.name + 2, OB_CURVES_LEGACY);
527 cu->flag |= CU_3D;
528
529 cu->nurb = nurblist;
530
531 id_us_min(&(id_cast<Mesh *>(ob->data))->id);
532 ob->data = id_cast<ID *>(cu);
534
536 }
537}
538
539void BKE_mesh_to_pointcloud(Main *bmain, Depsgraph *depsgraph, Scene * /*scene*/, Object *ob)
540{
541 using namespace blender::bke;
542 BLI_assert(ob->type == OB_MESH);
543 const Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
544 if (!ob_eval) {
545 return;
546 }
547 Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob_eval);
548 if (!mesh_eval) {
549 return;
550 }
551
553 PointCloud *pointcloud = BKE_pointcloud_add(bmain, ob->id.name + 2);
554 pointcloud->totpoint = mesh_eval->verts_num;
555
556 const AttributeAccessor src_attributes = mesh_eval->attributes();
557 MutableAttributeAccessor dst_attributes = pointcloud->attributes_for_write();
558 copy_attributes(src_attributes,
561 attribute_filter_from_skip_ref({".select_vert", ".select_edge", ".select_poly"}),
562 dst_attributes);
563
564 if (const GAttributeReader src = src_attributes.lookup(".select_vert")) {
565 const AttrType type = cpp_type_to_attribute_type(src.varray.type());
566 if (src.sharing_info && src.varray.is_span()) {
567 const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
568 *src.sharing_info);
569 dst_attributes.add(".selection", AttrDomain::Point, type, init);
570 }
571 else {
572 dst_attributes.add(".selection", AttrDomain::Point, type, AttributeInitVArray(src.varray));
573 }
574 }
575
576 BKE_id_materials_copy(bmain, ob->data, id_cast<ID *>(pointcloud));
577
578 id_us_min(&(id_cast<Mesh *>(ob->data))->id);
579 ob->data = id_cast<ID *>(pointcloud);
580 ob->type = OB_POINTCLOUD;
581
583}
584
585void BKE_pointcloud_to_mesh(Main *bmain, Depsgraph *depsgraph, Scene * /*scene*/, Object *ob)
586{
587 using namespace blender::bke;
589
590 const Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
592
593 Mesh *mesh = BKE_mesh_add(bmain, ob->id.name + 2);
594 if (const PointCloud *points = geometry.get_pointcloud()) {
595 mesh->verts_num = points->totpoint;
596 const AttributeAccessor src_attributes = points->attributes();
597 MutableAttributeAccessor dst_attributes = mesh->attributes_for_write();
598 copy_attributes(src_attributes,
601 attribute_filter_from_skip_ref({".selection"}),
602 dst_attributes);
603
604 if (const GAttributeReader src = src_attributes.lookup(".selection")) {
605 const AttrType type = cpp_type_to_attribute_type(src.varray.type());
606 if (src.sharing_info && src.varray.is_span()) {
607 const bke::AttributeInitShared init(src.varray.get_internal_span().data(),
608 *src.sharing_info);
609 dst_attributes.add(".select_vert", AttrDomain::Point, type, init);
610 }
611 else {
612 const AttributeInitVArray init(src.varray);
613 dst_attributes.add(".select_vert", AttrDomain::Point, type, init);
614 }
615 }
616 }
617
618 BKE_id_materials_copy(bmain, ob->data, id_cast<ID *>(mesh));
619
620 id_us_min(&(id_cast<PointCloud *>(ob->data))->id);
621 ob->data = id_cast<ID *>(mesh);
622 ob->type = OB_MESH;
623
625
627}
628
629/* Create a temporary object to be used for nurbs-to-mesh conversion. */
631{
632 const Curve *curve = id_cast<const Curve *>(object->data);
633
634 /* Create a temporary object which can be evaluated and modified by generic
635 * curve evaluation (hence the #LIB_ID_COPY_SET_COPIED_ON_WRITE flag). */
636 Object *temp_object = id_cast<Object *>(BKE_id_copy_ex(
638
639 /* Remove all modifiers, since we don't want them to be applied. */
641
642 /* Need to create copy of curve itself as well, since it will be changed by the curve evaluation
643 * process. NOTE: Copies the data, but not the shape-keys. */
644 temp_object->data = BKE_id_copy_ex(nullptr,
645 static_cast<const ID *>(object->data),
646 nullptr,
648 Curve *temp_curve = id_cast<Curve *>(temp_object->data);
649
650 /* Make sure texture space is calculated for a copy of curve, it will be used for the final
651 * result. */
652 BKE_curve_texspace_calc(temp_curve);
653
654 /* Temporarily set edit so we get updates from edit mode, but also because for text data-blocks
655 * copying it while in edit mode gives invalid data structures. */
656 temp_curve->editfont = curve->editfont;
657 temp_curve->editnurb = curve->editnurb;
658
659 return temp_object;
660}
661
662static void object_for_curve_to_mesh_free(Object *temp_object)
663{
664 /* Clear edit mode pointers that were explicitly copied to the temporary curve. */
665 ID *final_object_data = temp_object->data;
666 if (GS(final_object_data->name) == ID_CU_LEGACY) {
667 Curve &curve = *reinterpret_cast<Curve *>(final_object_data);
668 curve.editfont = nullptr;
669 curve.editnurb = nullptr;
670 }
671
672 /* Only free the final object data if it is *not* stored in the #data_eval field. This is still
673 * necessary because #temp_object's data could be replaced by a #Curve data-block that isn't also
674 * assigned to #data_eval. */
675 const bool object_data_stored_in_data_eval = final_object_data ==
676 temp_object->runtime->data_eval;
677
678 BKE_id_free(nullptr, temp_object);
679 if (!object_data_stored_in_data_eval) {
680 BKE_id_free(nullptr, final_object_data);
681 }
682}
683
688{
689 BLI_assert(GS(object.data->name) == ID_CU_LEGACY);
690 Curve &curve = *id_cast<Curve *>(object.data);
691 /* Clear all modifiers for the bevel object.
692 *
693 * This is because they can not be reliably evaluated for an original object (at least because
694 * the state of dependencies is not know).
695 *
696 * So we create temporary copy of the object which will use same data as the original bevel, but
697 * will have no modifiers. */
698 Object bevel_object = dna::shallow_zero_initialize();
699 bke::ObjectRuntime bevel_runtime;
700 if (curve.bevobj != nullptr) {
701 bevel_object = dna::shallow_copy(*curve.bevobj);
702 bevel_runtime = *curve.bevobj->runtime;
703 bevel_object.runtime = &bevel_runtime;
704
705 bevel_object.modifiers.clear_no_delete();
706 BKE_object_runtime_reset(&bevel_object);
707 curve.bevobj = &bevel_object;
708 }
709
710 /* Same thing for taper. */
711 Object taper_object = dna::shallow_zero_initialize();
712 bke::ObjectRuntime taper_runtime;
713 if (curve.taperobj != nullptr) {
714 taper_object = dna::shallow_copy(*curve.taperobj);
715 taper_runtime = *curve.taperobj->runtime;
716 taper_object.runtime = &taper_runtime;
717
718 taper_object.modifiers.clear_no_delete();
719 BKE_object_runtime_reset(&taper_object);
720 curve.taperobj = &taper_object;
721 }
722
723 /* NOTE: We don't have dependency graph or scene here, so we pass nullptr. This is all fine since
724 * they are only used for modifier stack, which we have explicitly disabled for all objects.
725 *
726 * TODO(sergey): This is a very fragile logic, but proper solution requires re-writing quite a
727 * bit of internal functions (#BKE_mesh_nomain_to_mesh) and also Mesh From Curve operator.
728 * Brecht says hold off with that. */
729 BKE_displist_make_curveTypes(nullptr, nullptr, &object, true);
730
731 if (bevel_object.runtime) {
732 BKE_object_runtime_free_data(&bevel_object);
733 }
734 if (taper_object.runtime) {
735 BKE_object_runtime_free_data(&taper_object);
736 }
737}
738
740{
741 if (bke::GeometrySet *geometry_set_eval = object->runtime->geometry_set_eval) {
742 return geometry_set_eval->get_curves();
743 }
744 return nullptr;
745}
746
748{
749 if (const Mesh *mesh = BKE_object_get_evaluated_mesh(evaluated_object)) {
751 }
752 if (const Curves *curves = get_evaluated_curves_from_object(evaluated_object)) {
753 return bke::curve_to_wire_mesh(curves->geometry.wrap());
754 }
755 return nullptr;
756}
757
759{
760 /* If the object is evaluated, it should either have an evaluated mesh or curve data already.
761 * The mesh can be duplicated, or the curve converted to wire mesh edges. */
762 if (DEG_is_evaluated(object)) {
764 }
765
766 /* Otherwise, create a temporary "fake" evaluated object and try again. This might have
767 * different results, since in order to avoid having adverse affects to other original objects,
768 * modifiers are cleared. An alternative would be to create a temporary depsgraph only for this
769 * object and its dependencies. */
770 Object *temp_object = object_for_curve_to_mesh_create(object);
771 ID *temp_data = temp_object->data;
772 curve_to_mesh_eval_ensure(*temp_object);
773
774 /* If evaluating the curve replaced object data with different data, free the original data. */
775 if (temp_data != temp_object->data) {
776 if (GS(temp_data->name) == ID_CU_LEGACY) {
777 /* Clear edit mode pointers that were explicitly copied to the temporary curve. */
778 Curve *curve = reinterpret_cast<Curve *>(temp_data);
779 curve->editfont = nullptr;
780 curve->editnurb = nullptr;
781 }
782 BKE_id_free(nullptr, temp_data);
783 }
784
786
788
789 return mesh;
790}
791
793{
794 /* NOTE: We can only create mesh for a polygonized meta ball. This figures out all original meta
795 * balls and all evaluated child meta balls (since polygonization is only stored in the mother
796 * ball).
797 *
798 * Create empty mesh so script-authors don't run into None objects. */
799 if (!DEG_is_evaluated(object)) {
800 return BKE_id_new_nomain<Mesh>((object->data)->name + 2);
801 }
802
803 const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(object);
804 if (mesh_eval == nullptr) {
805 return BKE_id_new_nomain<Mesh>((object->data)->name + 2);
806 }
807
808 return BKE_mesh_copy_for_eval(*mesh_eval);
809}
810
811static Mesh *mesh_new_from_mesh(Object *object, const Mesh *mesh, const bool ensure_subdivision)
812{
813 /* While we could copy this into the new mesh,
814 * add the data to 'mesh' so future calls to this function don't need to re-convert the data. */
815 if (mesh->runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH) {
817 }
818 else if (ensure_subdivision) {
820 }
821
822 Mesh *mesh_result = id_cast<Mesh *>(BKE_id_copy_ex(
824 /* NOTE: Materials should already be copied. */
825 /* Copy original mesh name. This is because edit meshes might not have one properly set name. */
826 STRNCPY(mesh_result->id.name, object->data->name);
827 return mesh_result;
828}
829
830static Mesh *mesh_new_from_mesh_object_with_layers(Depsgraph *depsgraph,
831 Object *object,
832 const bool preserve_origindex,
833 const bool ensure_subdivision)
834{
835 if (DEG_is_original(object)) {
836 return mesh_new_from_mesh(object, id_cast<Mesh *>(object->data), ensure_subdivision);
837 }
838
839 if (depsgraph == nullptr) {
840 return nullptr;
841 }
842
843 Object object_for_eval = dna::shallow_copy(*object);
844 bke::ObjectRuntime runtime = *object->runtime;
845 object_for_eval.runtime = &runtime;
846
847 if (object_for_eval.runtime->data_orig != nullptr) {
848 object_for_eval.data = object_for_eval.runtime->data_orig;
849 }
850
851 Scene *scene = DEG_get_evaluated_scene(depsgraph);
853 if (preserve_origindex) {
854 mask.vmask |= CD_MASK_ORIGINDEX;
855 mask.emask |= CD_MASK_ORIGINDEX;
856 mask.lmask |= CD_MASK_ORIGINDEX;
857 mask.pmask |= CD_MASK_ORIGINDEX;
858 }
859
860 Mesh *result = bke::mesh_create_eval_final(depsgraph, scene, &object_for_eval, &mask);
861
862 if (ensure_subdivision) {
863 /* Returns a borrowed reference which is still owned by `result`.
864 * Steal the reference from `result` which can then be freed. */
865 Mesh *result_maybe_subdiv = BKE_mesh_wrapper_ensure_subdivision(result);
866 if (result != result_maybe_subdiv) {
867 /* Expected, but assert this is the case. */
868 BLI_assert(result->runtime->mesh_eval == result_maybe_subdiv);
869 if (result->runtime->mesh_eval == result_maybe_subdiv) {
870 result->runtime->mesh_eval = nullptr;
871 BKE_id_free(nullptr, result);
872 result = result_maybe_subdiv;
873 /* Don't inherit shape keys, they are not valid anymore.
874 * See #mesh_build_data for why they are on the subdiv wrapper at all. */
875 result->key = nullptr;
876 }
877 }
878 }
879
880 return result;
881}
882
883static Mesh *mesh_new_from_mesh_object(Depsgraph *depsgraph,
884 Object *object,
885 const bool preserve_all_data_layers,
886 const bool preserve_origindex,
887 const bool use_subdivision)
888{
889 /* This function tries to reevaluate the object from the original data. If the original object
890 * was not a mesh object, this won't work because it uses mesh object evaluation which assumes
891 * the type of the original object data. */
892 if (!(object->runtime->data_orig && GS(object->runtime->data_orig->name) != ID_ME) &&
893 (preserve_all_data_layers || preserve_origindex))
894 {
896 depsgraph, object, preserve_origindex, use_subdivision);
897 }
898 const Mesh *mesh_input = id_cast<const Mesh *>(object->data);
899 /* If we are in edit mode, use evaluated mesh from edit structure, matching to what
900 * viewport is using for visualization. */
901 if (mesh_input->runtime->edit_mesh != nullptr) {
902 if (const Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object)) {
903 mesh_input = editmesh_eval_final;
904 }
905 }
906 return mesh_new_from_mesh(object, mesh_input, use_subdivision);
907}
908
909Mesh *BKE_mesh_new_from_object(Depsgraph *depsgraph,
910 Object *object,
911 const bool preserve_all_data_layers,
912 const bool preserve_origindex,
913 const bool ensure_subdivision)
914{
915 Mesh *new_mesh = nullptr;
916 switch (object->type) {
917 case OB_FONT:
918 case OB_CURVES_LEGACY:
919 case OB_SURF:
920 new_mesh = mesh_new_from_curve_type_object(object);
921 break;
922 case OB_MBALL:
923 new_mesh = mesh_new_from_mball_object(object);
924 break;
925 case OB_MESH:
926 new_mesh = mesh_new_from_mesh_object(
927 depsgraph, object, preserve_all_data_layers, preserve_origindex, ensure_subdivision);
928 break;
929 default:
930 /* Object does not have geometry data. */
931 return nullptr;
932 }
933 if (new_mesh == nullptr) {
934 /* Happens in special cases like request of mesh for non-mother meta ball. */
935 return nullptr;
936 }
937
938 /* The result must have 0 users, since it's just a mesh which is free-dangling data-block.
939 * All the conversion functions are supposed to ensure mesh is not counted. */
940 BLI_assert(new_mesh->id.us == 0);
941
942 /* It is possible that mesh came from modifier stack evaluation, which preserves edit_mesh
943 * pointer (which allows draw manager to access edit mesh when drawing). Normally this does
944 * not cause ownership problems because evaluated object runtime is keeping track of the real
945 * ownership.
946 *
947 * Here we are constructing a mesh which is supposed to be independent, which means no shared
948 * ownership is allowed, so we make sure edit mesh is reset to nullptr (which is similar to as if
949 * one duplicates the objects and applies all the modifiers). */
950 new_mesh->runtime->edit_mesh = nullptr;
951
952 return new_mesh;
953}
954
956{
957 ID **id_p = cb_data->id_pointer;
958 if (*id_p == nullptr) {
959 return IDWALK_RET_NOP;
960 }
961 *id_p = DEG_get_original(*id_p);
962
963 return IDWALK_RET_NOP;
964}
965
967{
968 ID **id_p = cb_data->id_pointer;
969 if (*id_p == nullptr) {
970 return IDWALK_RET_NOP;
971 }
972
973 const LibraryForeachIDCallbackFlag cb_flag = cb_data->cb_flag;
974 if (cb_flag & IDWALK_CB_USER) {
975 id_us_plus(*id_p);
976 }
977 else if (cb_flag & IDWALK_CB_USER_ONE) {
978 /* NOTE: in that context, that one should not be needed (since there should be at least already
979 * one USER_ONE user of that ID), but better be consistent. */
980 id_us_ensure_real(*id_p);
981 }
982 return IDWALK_RET_NOP;
983}
984
986 Depsgraph *depsgraph,
987 Object *object,
988 bool preserve_all_data_layers)
989{
991
992 Mesh *mesh = BKE_mesh_new_from_object(depsgraph, object, preserve_all_data_layers, false, true);
993 if (mesh == nullptr) {
994 /* Unable to convert the object to a mesh, return an empty one. */
995 Mesh *mesh_in_bmain = BKE_mesh_add(bmain, (object->data)->name + 2);
996 id_us_min(&mesh_in_bmain->id);
997 return mesh_in_bmain;
998 }
999
1000 /* Make sure mesh only points to original data-blocks. Also increase user count of materials and
1001 * other possibly referenced data-blocks.
1002 *
1003 * Changing to original data-blocks is required to have bmain in a consistent state, where
1004 * everything is only allowed to reference original data-blocks.
1005 *
1006 * Note that user-count updates have to be done *after* the mesh has been transferred to Main
1007 * database (since doing reference-counting on non-Main IDs is forbidden). */
1010
1011 /* Add the mesh to 'bmain'. We do it in a bit longer way since there is no simple and clear way
1012 * of adding existing data-blocks to the 'bmain'. So we create new empty mesh (which guarantees
1013 * all the naming and order and flags) and move the temporary mesh in place there. */
1014 Mesh *mesh_in_bmain = BKE_mesh_add(bmain, mesh->id.name + 2);
1015
1016 /* NOTE: BKE_mesh_nomain_to_mesh() does not copy materials and instead preserves them in the
1017 * destination mesh. So we "steal" materials before calling it.
1018 *
1019 * TODO(sergey): We really ought to have a function which gets an ID and accepts it into #Main.
1020 */
1021 mesh_in_bmain->mat = mesh->mat;
1022 mesh_in_bmain->totcol = mesh->totcol;
1023 mesh->mat = nullptr;
1024
1025 BKE_mesh_nomain_to_mesh(mesh, mesh_in_bmain, nullptr);
1026
1027 /* Anonymous attributes shouldn't exist on original data. */
1028 mesh_in_bmain->attributes_for_write().remove_anonymous();
1029
1030 /* User-count is required because so far mesh was in a limbo, where library management does
1031 * not perform any user management (i.e. copy of a mesh will not increase users of materials). */
1033 nullptr, &mesh_in_bmain->id, foreach_libblock_make_usercounts_callback, nullptr, IDWALK_NOP);
1034
1035 /* Make sure user count from BKE_mesh_add() is the one we expect here and bring it down to 0. */
1036 BLI_assert(mesh_in_bmain->id.us == 1);
1037 id_us_min(&mesh_in_bmain->id);
1038
1039 return mesh_in_bmain;
1040}
1041
1042static void copy_loose_vert_hint(const Mesh &src, Mesh &dst)
1043{
1044 const auto &src_cache = src.runtime->loose_verts_cache;
1045 if (src_cache.is_cached() && src_cache.data().mask.is_empty()) {
1046 dst.tag_loose_verts_none();
1047 }
1048}
1049
1050static void copy_loose_edge_hint(const Mesh &src, Mesh &dst)
1051{
1052 const auto &src_cache = src.runtime->loose_edges_cache;
1053 if (src_cache.is_cached() && src_cache.data().mask.is_empty()) {
1054 dst.tag_loose_edges_none();
1055 }
1056}
1057
1058static void copy_overlapping_hint(const Mesh &src, Mesh &dst)
1059{
1060 if (src.no_overlapping_topology()) {
1061 dst.tag_overlapping_none();
1062 }
1063}
1064
1065static KeyBlock *keyblock_ensure_from_uid(Key &key, const int uid, const StringRefNull name)
1066{
1067 if (KeyBlock *kb = BKE_keyblock_find_uid(&key, uid)) {
1068 return kb;
1069 }
1070 KeyBlock *kb = BKE_keyblock_add(&key, name.c_str());
1071 kb->uid = uid;
1072 return kb;
1073}
1074
1075static int find_object_active_key_uid(const Key &key, const Object &object)
1076{
1077 const int active_kb_index = object.shapenr - 1;
1078 const KeyBlock *kb = static_cast<const KeyBlock *>(BLI_findlink(&key.block, active_kb_index));
1079 if (!kb) {
1080 CLOG_ERROR(&LOG, "Could not find object's active shapekey %d", active_kb_index);
1081 return -1;
1082 }
1083 return kb->uid;
1084}
1085
1087 const CustomData &custom_data,
1088 Key &key_dst,
1089 const int actshape_uid)
1090{
1091 using namespace blender::bke;
1092 for (const int i : IndexRange(CustomData_number_of_layers(&custom_data, CD_SHAPEKEY))) {
1093 const int layer_index = CustomData_get_layer_index_n(&custom_data, CD_SHAPEKEY, i);
1094 const CustomDataLayer &layer = custom_data.layers[layer_index];
1095
1096 KeyBlock *kb = keyblock_ensure_from_uid(key_dst, layer.uid, layer.name);
1097 MEM_SAFE_DELETE_VOID(kb->data);
1098
1099 kb->totelem = mesh.verts_num;
1100 kb->data = MEM_new_array_uninitialized<float3>(size_t(kb->totelem), __func__);
1101 MutableSpan<float3> kb_coords(static_cast<float3 *>(kb->data), kb->totelem);
1102 if (kb->uid == actshape_uid) {
1103 mesh.attributes().lookup<float3>("position").varray.materialize(kb_coords);
1104 }
1105 else {
1106 kb_coords.copy_from({static_cast<const float3 *>(layer.data), mesh.verts_num});
1107 }
1108 }
1109
1110 for (KeyBlock &kb : key_dst.block) {
1111 if (kb.totelem != mesh.verts_num) {
1112 MEM_SAFE_DELETE_VOID(kb.data);
1113 kb.totelem = mesh.verts_num;
1114 kb.data = MEM_new_array_zeroed<float3>(kb.totelem, __func__);
1115 CLOG_ERROR(&LOG, "Data for shape key '%s' on mesh missing from evaluated mesh ", kb.name);
1116 }
1117 }
1118}
1119
1120void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, bool process_shape_keys)
1121{
1122 using namespace blender::bke;
1123 BLI_assert(mesh_src->id.tag & ID_TAG_NO_MAIN);
1124 if (ob) {
1125 BLI_assert(id_cast<ID *>(mesh_dst) == ob->data);
1126 }
1127
1128 const bool verts_num_changed = mesh_dst->verts_num != mesh_src->verts_num;
1129
1131
1132 mesh_dst->verts_num = mesh_src->verts_num;
1133 mesh_dst->edges_num = mesh_src->edges_num;
1134 mesh_dst->faces_num = mesh_src->faces_num;
1135 mesh_dst->corners_num = mesh_src->corners_num;
1136
1137 /* Using #CD_MASK_MESH ensures that only data that should exist in Main meshes is moved. */
1139 mesh_dst->attribute_storage.wrap() = std::move(mesh_src->attribute_storage.wrap());
1141 &mesh_src->vert_data, &mesh_dst->vert_data, mask.vmask, mesh_src->verts_num);
1143 &mesh_src->edge_data, &mesh_dst->edge_data, mask.emask, mesh_src->edges_num);
1145 &mesh_src->face_data, &mesh_dst->face_data, mask.pmask, mesh_src->faces_num);
1147 &mesh_src->corner_data, &mesh_dst->corner_data, mask.lmask, mesh_src->corners_num);
1148 std::swap(mesh_dst->face_offset_indices, mesh_src->face_offset_indices);
1149 std::swap(mesh_dst->runtime->face_offsets_sharing_info,
1151
1152 /* Make sure attribute names are moved. */
1153 std::swap(mesh_dst->active_color_attribute, mesh_src->active_color_attribute);
1154 std::swap(mesh_dst->default_color_attribute, mesh_src->default_color_attribute);
1155 std::swap(mesh_dst->active_uv_map_attribute, mesh_src->active_uv_map_attribute);
1156 std::swap(mesh_dst->stencil_uv_map_attribute, mesh_src->stencil_uv_map_attribute);
1157 std::swap(mesh_dst->clone_uv_map_attribute, mesh_src->clone_uv_map_attribute);
1158 std::swap(mesh_dst->default_uv_map_attribute, mesh_src->default_uv_map_attribute);
1159 std::swap(mesh_dst->vertex_group_names, mesh_src->vertex_group_names);
1160
1161 BKE_mesh_copy_parameters(mesh_dst, mesh_src);
1162
1163 /* For original meshes, shape key data is stored in the #Key data-block, so it
1164 * must be moved from the storage in #CustomData layers used for evaluation. */
1165 if (process_shape_keys) {
1166 if (Key *key_dst = mesh_dst->key) {
1167 if (CustomData_has_layer(&mesh_src->vert_data, CD_SHAPEKEY)) {
1168 /* If no object, set to -1 so we don't mess up any shapekey layers. */
1169 const int uid_active = ob ? find_object_active_key_uid(*key_dst, *ob) : -1;
1170 move_shapekey_layers_to_keyblocks(*mesh_dst, mesh_src->vert_data, *key_dst, uid_active);
1171 }
1172 else if (verts_num_changed) {
1173 CLOG_WARN(&LOG, "Shape key data lost when replacing mesh '%s' in Main", mesh_src->id.name);
1174 id_us_min(&mesh_dst->key->id);
1175 mesh_dst->key = nullptr;
1176 }
1177 }
1178 }
1179
1180 /* Caches can have a large memory impact and aren't necessarily used, so don't indiscriminately
1181 * store all of them in the #Main data-base mesh. However, some caches are quite small and
1182 * copying them is "free" relative to how much work would be required if the data was needed. */
1183 copy_loose_vert_hint(*mesh_src, *mesh_dst);
1184 copy_loose_edge_hint(*mesh_src, *mesh_dst);
1185 copy_overlapping_hint(*mesh_src, *mesh_dst);
1186
1187 BKE_id_free(nullptr, mesh_src);
1188}
1189
1190void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb)
1191{
1192 BLI_assert(mesh_src->id.tag & ID_TAG_NO_MAIN);
1193
1194 const int totvert = mesh_src->verts_num;
1195
1196 if (totvert == 0 || mesh_dst->verts_num == 0 || mesh_dst->verts_num != totvert) {
1197 return;
1198 }
1199
1200 if (kb->data) {
1201 MEM_delete(static_cast<float3 *>(kb->data));
1202 }
1203 kb->data = MEM_new_array_uninitialized<float3>(size_t(mesh_dst->verts_num), "kb->data");
1204 kb->totelem = totvert;
1205 MutableSpan(static_cast<float3 *>(kb->data), kb->totelem).copy_from(mesh_src->vert_positions());
1206}
1207
1208} // namespace blender
#define CU_DO_2DFILL(cu)
Definition BKE_curve.hh:96
Low-level operations for curves.
support for deformation groups and hooks.
display list (or rather multi purpose list) stuff.
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
General operations for point clouds.
#define DATA_(msgid)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define ELEM(...)
#define CD_MASK_ORIGINDEX
constexpr IndexRange()=default
constexpr MutableSpan()=default
constexpr void copy_from(Span< T > values) const
Definition BLI_span.hh:745
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr const char * c_str() const
GAttributeReader lookup(const StringRef name) const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
#define layer
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
void copy_attributes(const AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, MutableAttributeAccessor dst_attributes)
GeometrySet object_get_evaluated_geometry_set(const Object &object, bool apply_subdiv=true)
void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges)
Mesh * curve_to_wire_mesh(const CurvesGeometry &curve, const bke::AttributeFilter &attribute_filter={})
void mesh_ensure_active_uv_map(Mesh &mesh)
AttrType cpp_type_to_attribute_type(const CPPType &type)
Mesh * mesh_create_eval_final(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
internal::ShallowZeroInitializeTag shallow_zero_initialize()
Definition DNA_defs.h:159
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
BMesh Iterators.
void BKE_mesh_to_curve_nurblist(const Mesh *mesh, ListBaseT< Nurb > *nurblist, int edge_users_test)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void copy_loose_edge_hint(const Mesh &src, Mesh &dst)
static Mesh * mesh_new_from_mesh(Object *object, const Mesh *mesh, const bool ensure_subdivision)
Mesh * BKE_mesh_new_from_object_to_bmain(Main *bmain, Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers)
void BKE_mesh_copy_parameters(Mesh *me_dst, const Mesh *me_src)
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_object_runtime_reset(Object *object)
Definition object.cc:5202
int CustomData_number_of_layers(const CustomData *data, eCustomDataType type)
void BKE_mesh_clear_geometry_and_metadata(Mesh *mesh)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
static void copy_overlapping_hint(const Mesh &src, Mesh &dst)
void id_us_plus(ID *id)
Definition lib_id.cc:433
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void BKE_object_runtime_free_data(Object *object)
Definition object.cc:5223
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
static Mesh * mesh_new_from_mesh_object(Depsgraph *depsgraph, Object *object, const bool preserve_all_data_layers, const bool preserve_origindex, const bool use_subdivision)
void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, bool process_shape_keys=true)
const Mesh * BKE_object_get_editmesh_eval_final(const Object *object)
Definition object.cc:4477
void BKE_mesh_to_pointcloud(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
Curve * BKE_curve_add(Main *bmain, const char *name, ObjectType type)
Definition curve.cc:429
void BKE_object_free_modifiers(Object *ob, int flag)
Definition object.cc:1337
ATTR_WARN_UNUSED_RESULT const BMVert * v
static int foreach_libblock_make_original_callback(LibraryIDLinkCallbackData *cb_data)
void BKE_id_materials_copy(Main *bmain, ID *id_src, ID *id_dst)
static void copy_loose_vert_hint(const Mesh &src, Mesh &dst)
@ LIB_ID_CREATE_NO_USER_REFCOUNT
@ LIB_ID_COPY_LOCALIZE
@ LIB_ID_COPY_SET_COPIED_ON_WRITE
@ LIB_ID_CREATE_NO_MAIN
static Mesh * mesh_new_from_evaluated_curve_type_object(const Object *evaluated_object)
static KeyBlock * keyblock_ensure_from_uid(Key &key, const int uid, const StringRefNull name)
bool DEG_is_original(const T *id)
static void mesh_copy_texture_space_from_curve_type(const Curve *cu, Mesh *mesh)
static Mesh * mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBaseT< DispList > *dispbase)
static void appendPolyLineVert(ListBaseT< VertLink > *lb, uint index)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
static Mesh * mesh_new_from_curve_type_object(const Object *object)
KeyBlock * BKE_keyblock_find_uid(Key *key, int uid)
Definition key.cc:1439
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static int find_object_active_key_uid(const Key &key, const Object &object)
void BKE_object_free_derived_caches(Object *ob)
Definition object.cc:1810
Mesh * BKE_mesh_new_nomain_from_curve(const Object *ob)
void BKE_pointcloud_to_mesh(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
PointCloud * BKE_pointcloud_add(Main *bmain, const char *name)
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:277
Mesh * BKE_mesh_new_nomain_from_curve_displist(const Object *ob, const ListBaseT< DispList > *dispbase)
static const Curves * get_evaluated_curves_from_object(const Object *object)
void BKE_id_free(Main *bmain, void *idv)
static void object_for_curve_to_mesh_free(Object *temp_object)
static int foreach_libblock_make_usercounts_callback(LibraryIDLinkCallbackData *cb_data)
static void curve_to_mesh_eval_ensure(Object &object)
static Object * object_for_curve_to_mesh_create(const Object *object)
void * BKE_id_new_nomain(short type, const char *name)
Definition lib_id.cc:1617
void id_us_ensure_real(ID *id)
Definition lib_id.cc:388
void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb)
int CustomData_get_layer_index_n(const CustomData *data, eCustomDataType type, int n)
static void move_shapekey_layers_to_keyblocks(const Mesh &mesh, const CustomData &custom_data, Key &key_dst, const int actshape_uid)
T * DEG_get_original(T *id)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
const CustomData_MeshMasks CD_MASK_MESH
KeyBlock * BKE_keyblock_add(Key *key, const char *name)
Definition key.cc:1322
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ ID_TAG_NO_MAIN
Definition DNA_ID.h:981
@ CU_TEXSPACE_FLAG_AUTO
static CLG_LogRef LOG
Definition logging.cpp:12
Mesh * BKE_mesh_new_from_object(Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers, bool preserve_origindex, bool ensure_subdivision)
void BKE_mesh_to_curve(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
void BKE_mesh_texspace_calc(Mesh *mesh)
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:851
void BKE_displist_make_curveTypes(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, bool for_render)
LibraryForeachIDCallbackFlag
VecBase< float, 3 > float3
@ ME_WRAPPER_TYPE_BMESH
Mesh * BKE_mesh_add(Main *bmain, const char *name)
static Mesh * mesh_new_from_mesh_object_with_layers(Depsgraph *depsgraph, Object *object, const bool preserve_origindex, const bool ensure_subdivision)
bool DEG_is_evaluated(const T *id)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
void BKE_curve_texspace_calc(Curve *cu)
Definition curve.cc:490
void id_us_min(ID *id)
Definition lib_id.cc:441
Mesh * BKE_mesh_wrapper_ensure_subdivision(Mesh *mesh)
void CustomData_init_from(const CustomData *source, CustomData *dest, eCustomDataMask mask, int totelem)
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
Definition lib_query.cc:449
static void prependPolyLineVert(ListBaseT< VertLink > *lb, uint index)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Definition object.cc:4436
static Mesh * mesh_new_from_mball_object(Object *object)
ListBaseT< DispList > disp
Definition BKE_curve.hh:44
ListBaseT< Nurb > nurb
EditNurb * editnurb
float texspace_location[3]
struct EditFont * editfont
struct Object * bevobj
struct Material ** mat
struct Object * taperobj
char name[258]
Definition DNA_ID.h:433
ListBaseT< KeyBlock > block
LibraryForeachIDCallbackFlag cb_flag
struct AttributeStorage attribute_storage
struct Material ** mat
ListBaseT< bDeformGroup > vertex_group_names
bke::MeshRuntime * runtime
char * stencil_uv_map_attribute
int * face_offset_indices
char * default_uv_map_attribute
char * active_uv_map_attribute
struct Key * key
CustomData corner_data
char * clone_uv_map_attribute
CustomData face_data
char * active_color_attribute
CustomData edge_data
char * default_color_attribute
CustomData vert_data
eNurbKnotFlag flagu
ListBaseT< ModifierData > modifiers
bke::ObjectRuntime * runtime
std::shared_ptr< BMEditMesh > edit_mesh
SharedCache< LooseGeomCache > loose_edges_cache
SharedCache< LooseGeomCache > loose_verts_cache
const ImplicitSharingInfo * face_offsets_sharing_info