Blender V5.3
rna_mesh.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 <cstdlib>
10
11#include "DNA_mesh_types.h"
12#include "DNA_meshdata_types.h"
13
14#include "BKE_attribute.h"
15#include "BKE_editmesh.hh"
16#include "BKE_mesh_types.hh"
17
18#include "RNA_define.hh"
19#include "RNA_enum_types.hh"
20#include "RNA_types.hh"
21
22#include "rna_internal.hh"
23
24#include "WM_types.hh"
25
26namespace blender {
27
29 {BMO_DELIM_NORMAL, "NORMAL", 0, "Normal", "Delimit by face directions"},
30 {BMO_DELIM_MATERIAL, "MATERIAL", 0, "Material", "Delimit by face material"},
31 {BMO_DELIM_SEAM, "SEAM", 0, "Seam", "Delimit by edge seams"},
32 {BMO_DELIM_SHARP, "SHARP", 0, "Sharp", "Delimit by sharp edges"},
33 {BMO_DELIM_UV, "UV", 0, "UVs", "Delimit by UV coordinates"},
34 {0, nullptr, 0, nullptr, nullptr},
35};
36
38 {BMW_DELIMIT_EDGE_MARK_SEAM, "SEAM", 0, "Seam", "Delimit edge loop selection at seams"},
40 "SHARP",
41 0,
42 "Sharp",
43 "Delimit edge loop selection at sharp edges"},
44 {BMW_DELIMIT_EDGE_LOOP_NGONS, "NGONS", 0, "N-gons", "Stop boundary selection at n-gons"},
46 "INNER_CORNERS",
47 0,
48 "Inner Corners",
49 "Stop boundary selection at vertices with more than three edges"},
51 "OUTER_CORNERS",
52 0,
53 "Outer Corners",
54 "Stop boundary selection at vertices with two edges when they share a face that is not an "
55 "n-gon"},
56 {0, nullptr, 0, nullptr, nullptr},
57};
58
60 {BMW_DELIMIT_EDGE_MARK_SEAM, "SEAM", 0, "Seam", "Delimit edge ring selection at seams"},
62 "SHARP",
63 0,
64 "Sharp",
65 "Delimit edge ring selection at sharp edges"},
67 "MATERIAL",
68 0,
69 "Material",
70 "Delimit edge ring selection at material boundaries"},
72 "NGONS",
73 0,
74 "N-gons",
75 "Allow edge ring selection to step over n-gons with an even number of sides"},
76 {0, nullptr, 0, nullptr, nullptr},
77};
78
80 {BMW_DELIMIT_EDGE_MARK_SEAM, "SEAM", 0, "Seam", "Delimit face loop selection at seams"},
82 "SHARP",
83 0,
84 "Sharp",
85 "Delimit face loop selection at sharp edges"},
87 "MATERIAL",
88 0,
89 "Material",
90 "Delimit face loop selection at material boundaries"},
91 {0, nullptr, 0, nullptr, nullptr},
92};
93
95 {REMESH_VOXEL, "VOXEL", 0, "Voxel", "Use the voxel remesher"},
96 {REMESH_QUAD, "QUAD", 0, "Quad", "Use the quad remesher"},
97 {0, nullptr, 0, nullptr, nullptr},
98};
99
100} // namespace blender
101
102#ifdef RNA_RUNTIME
103
104# include <fmt/format.h>
105
106# include "DNA_material_types.h"
107# include "DNA_scene_types.h"
108# include "DNA_world_types.h"
109
110# include "BLI_math_geom_c.hh"
111# include "BLI_math_vector_c.hh"
112# include "BLI_string.hh"
113# include "BLI_string_utf8.hh"
114
116# include "BKE_attribute.hh"
118# include "BKE_customdata.hh"
119# include "BKE_lib_id.hh"
120# include "BKE_main.hh"
121# include "BKE_mesh.hh"
122# include "BKE_mesh_runtime.hh"
123# include "BKE_report.hh"
124
125# include "DEG_depsgraph.hh"
126
127# include "ED_mesh.hh" /* XXX Bad level call */
128
129# include "WM_api.hh"
130
131namespace blender {
132
133/* -------------------------------------------------------------------- */
136
137static Mesh *rna_mesh(const PointerRNA *ptr)
138{
139 Mesh *mesh = id_cast<Mesh *>(ptr->owner_id);
140 return mesh;
141}
142
144
145/* -------------------------------------------------------------------- */
148
149static bool rna_Mesh_has_custom_normals_get(PointerRNA *ptr)
150{
151 Mesh *mesh = static_cast<Mesh *>(ptr->data);
153}
154
156
157/* -------------------------------------------------------------------- */
164
172static void rna_Mesh_update_data_legacy_deg_tag_all(Main * /*bmain*/,
173 Scene * /*scene*/,
174 PointerRNA *ptr)
175{
176 ID *id = ptr->owner_id;
177 if (id->us <= 0) { /* See note in section heading. */
178 return;
179 }
180
181 DEG_id_tag_update(id, 0);
183}
184
185static void rna_Mesh_update_geom_and_params(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
186{
187 ID *id = ptr->owner_id;
188 if (id->us <= 0) { /* See note in section heading. */
189 return;
190 }
191
194}
195
196static void rna_Mesh_update_data_edit_weight(Main *bmain, Scene *scene, PointerRNA *ptr)
197{
199
200 rna_Mesh_update_data_legacy_deg_tag_all(bmain, scene, ptr);
201}
202
203static void rna_Mesh_update_data_edit_active_color(Main *bmain, Scene *scene, PointerRNA *ptr)
204{
206
207 rna_Mesh_update_data_legacy_deg_tag_all(bmain, scene, ptr);
208}
209static void rna_Mesh_update_select(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
210{
211 ID *id = ptr->owner_id;
212 if (id->us <= 0) { /* See note in section heading. */
213 return;
214 }
215
217}
218
219void rna_Mesh_update_draw(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
220{
221 ID *id = ptr->owner_id;
222 if (id->us <= 0) { /* See note in section heading. */
223 return;
224 }
225
227}
228
229static void rna_Mesh_update_bone_selection_mode(Main *bmain, Scene *scene, PointerRNA *ptr)
230{
231 Mesh *mesh = static_cast<Mesh *>(ptr->data);
232 mesh->editflag &= ~ME_EDIT_PAINT_VERT_SEL;
233 mesh->editflag &= ~ME_EDIT_PAINT_FACE_SEL;
234
236
237 rna_Mesh_update_draw(bmain, scene, ptr);
238}
239
240static void rna_Mesh_update_vertmask(Main *bmain, Scene *scene, PointerRNA *ptr)
241{
242 Mesh *mesh = static_cast<Mesh *>(ptr->data);
243 if ((mesh->editflag & ME_EDIT_PAINT_VERT_SEL) && (mesh->editflag & ME_EDIT_PAINT_FACE_SEL)) {
244 mesh->editflag &= ~ME_EDIT_PAINT_FACE_SEL;
245 }
246
248
249 rna_Mesh_update_draw(bmain, scene, ptr);
250}
251
252static void rna_Mesh_update_facemask(Main *bmain, Scene *scene, PointerRNA *ptr)
253{
254 Mesh *mesh = static_cast<Mesh *>(ptr->data);
255 if ((mesh->editflag & ME_EDIT_PAINT_VERT_SEL) && (mesh->editflag & ME_EDIT_PAINT_FACE_SEL)) {
256 mesh->editflag &= ~ME_EDIT_PAINT_VERT_SEL;
257 }
258
260
261 rna_Mesh_update_draw(bmain, scene, ptr);
262}
263
264static void rna_Mesh_update_positions_tag(Main *bmain, Scene *scene, PointerRNA *ptr)
265{
266 rna_Mesh_update_data_legacy_deg_tag_all(bmain, scene, ptr);
267}
268
270
271/* -------------------------------------------------------------------- */
274
275static int rna_MeshVertex_index_get(PointerRNA *ptr)
276{
277 const Mesh *mesh = rna_mesh(ptr);
278 const float3 *position = static_cast<const float3 *>(ptr->data);
279 const int index = int(position - mesh->vert_positions().data());
280 BLI_assert(index >= 0);
281 BLI_assert(index < mesh->verts_num);
282 return index;
283}
284
285static int rna_MeshEdge_index_get(PointerRNA *ptr)
286{
287 const Mesh *mesh = rna_mesh(ptr);
288 const int2 *edge = static_cast<const int2 *>(ptr->data);
289 const int2 *edges = mesh->edges().data();
290 const int index = int(edge - edges);
291 BLI_assert(index >= 0);
292 BLI_assert(index < mesh->edges_num);
293 return index;
294}
295
296static int rna_MeshPolygon_index_get(PointerRNA *ptr)
297{
298 const Mesh *mesh = rna_mesh(ptr);
299 const int *face_offset = static_cast<const int *>(ptr->data);
300 const int index = int(face_offset - mesh->face_offsets().data());
301 BLI_assert(index >= 0);
302 BLI_assert(index < mesh->faces_num);
303 return index;
304}
305
306static int rna_MeshLoop_index_get(PointerRNA *ptr)
307{
308 const Mesh *mesh = rna_mesh(ptr);
309 const int *corner_vert = static_cast<const int *>(ptr->data);
310 const int index = int(corner_vert - mesh->corner_verts().data());
311 BLI_assert(index >= 0);
312 BLI_assert(index < mesh->corners_num);
313 return index;
314}
315
316static int rna_MeshLoopTriangle_index_get(PointerRNA *ptr)
317{
318 const Mesh *mesh = rna_mesh(ptr);
319 const int3 *tri = static_cast<const int3 *>(ptr->data);
320 const int index = int(tri - mesh->corner_tris().data());
321 BLI_assert(index >= 0);
323 return index;
324}
325
326static int rna_MeshLoopTriangle_polygon_index_get(PointerRNA *ptr)
327{
328 const Mesh *mesh = rna_mesh(ptr);
329 const int index = rna_MeshLoopTriangle_index_get(ptr);
330 return mesh->corner_tri_faces()[index];
331}
332
333static void rna_Mesh_loop_triangles_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
334{
335 const Mesh *mesh = rna_mesh(ptr);
336 const Span<int3> corner_tris = mesh->corner_tris();
338 ptr,
339 const_cast<int3 *>(corner_tris.data()),
340 sizeof(int3),
341 corner_tris.size(),
342 false,
343 nullptr);
344}
345
346static int rna_Mesh_loop_triangles_length(PointerRNA *ptr)
347{
348 const Mesh *mesh = rna_mesh(ptr);
350}
351
352bool rna_Mesh_loop_triangles_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
353{
354 const Mesh *mesh = rna_mesh(ptr);
355 if (index < 0 || index >= BKE_mesh_runtime_corner_tris_len(mesh)) {
356 return false;
357 }
358 /* Casting away const is okay because this RNA type doesn't allow changing the value. */
360 *ptr, RNA_MeshLoopTriangle, const_cast<int3 *>(&mesh->corner_tris()[index]), *r_ptr);
361 return true;
362}
363
364static void rna_Mesh_loop_triangle_polygons_begin(CollectionPropertyIterator *iter,
365 PointerRNA *ptr)
366{
367 const Mesh *mesh = rna_mesh(ptr);
369 ptr,
370 const_cast<int *>(mesh->corner_tri_faces().data()),
371 sizeof(int),
373 false,
374 nullptr);
375}
376
377bool rna_Mesh_loop_triangle_polygons_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
378{
379 const Mesh *mesh = rna_mesh(ptr);
380 if (index < 0 || index >= BKE_mesh_runtime_corner_tris_len(mesh)) {
381 return false;
382 }
383 /* Casting away const is okay because this RNA type doesn't allow changing the value. */
385 *ptr, RNA_ReadOnlyInteger, const_cast<int *>(&mesh->corner_tri_faces()[index]), *r_ptr);
386 return true;
387}
388
389static void rna_MeshVertex_co_get(PointerRNA *ptr, float *value)
390{
391 copy_v3_v3(value, static_cast<const float *>(ptr->data));
392}
393
394static void rna_MeshVertex_co_set(PointerRNA *ptr, const float *value)
395{
396 copy_v3_v3(static_cast<float *>(ptr->data), value);
397 Mesh *mesh = rna_mesh(ptr);
398 mesh->tag_positions_changed();
399}
400
401static void rna_MeshVertex_normal_get(PointerRNA *ptr, float *value)
402{
403 Mesh *mesh = rna_mesh(ptr);
404 const Span<float3> vert_normals = mesh->vert_normals();
405 const int index = rna_MeshVertex_index_get(ptr);
406 copy_v3_v3(value, vert_normals[index]);
407}
408
409static bool rna_MeshVertex_hide_get(PointerRNA *ptr)
410{
411 const Mesh *mesh = rna_mesh(ptr);
412 const bke::AttributeAccessor attributes = mesh->attributes();
413 const VArray hide_vert = *attributes.lookup_or_default<bool>(
414 ".hide_vert", bke::AttrDomain::Point, false);
415 const int index = rna_MeshVertex_index_get(ptr);
416 return hide_vert[index];
417}
418
419static void rna_MeshVertex_hide_set(PointerRNA *ptr, bool value)
420{
421 Mesh *mesh = rna_mesh(ptr);
422 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
423 bke::AttributeWriter hide_vert = attributes.lookup_or_add_for_write<bool>(
425 const int index = rna_MeshVertex_index_get(ptr);
426 hide_vert.varray.set(index, value);
427 hide_vert.finish();
428}
429
430static bool rna_MeshVertex_select_get(PointerRNA *ptr)
431{
432 const Mesh *mesh = rna_mesh(ptr);
433 const int index = rna_MeshVertex_index_get(ptr);
434 const bke::AttributeAccessor attributes = mesh->attributes();
435 const VArray select_vert = *attributes.lookup_or_default<bool>(
436 ".select_vert", bke::AttrDomain::Point, false);
437 return select_vert[index];
438}
439
440static void rna_MeshVertex_select_set(PointerRNA *ptr, bool value)
441{
442 Mesh *mesh = rna_mesh(ptr);
443 const int index = rna_MeshVertex_index_get(ptr);
444 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
445 bke::AttributeWriter select_vert = attributes.lookup_or_add_for_write<bool>(
447 select_vert.varray.set(index, value);
448 select_vert.finish();
449}
450
451static int rna_MeshLoop_vertex_index_get(PointerRNA *ptr)
452{
453 return *static_cast<int *>(ptr->data);
454}
455
456static void rna_MeshLoop_vertex_index_set(PointerRNA *ptr, int value)
457{
458 *static_cast<int *>(ptr->data) = value;
459}
460
461static int rna_MeshLoop_edge_index_get(PointerRNA *ptr)
462{
463 const Mesh *mesh = rna_mesh(ptr);
464 const int index = rna_MeshLoop_index_get(ptr);
465 return mesh->corner_edges()[index];
466}
467
468static void rna_MeshLoop_edge_index_set(PointerRNA *ptr, int value)
469{
470 Mesh *mesh = rna_mesh(ptr);
471 const int index = rna_MeshLoop_index_get(ptr);
472 mesh->corner_edges_for_write()[index] = value;
473}
474
475static void rna_MeshLoop_normal_get(PointerRNA *ptr, float *values)
476{
477 Mesh *mesh = rna_mesh(ptr);
478 const int index = rna_MeshLoop_index_get(ptr);
479 copy_v3_v3(values, mesh->corner_normals()[index]);
480}
481
482static void rna_MeshLoop_tangent_get(PointerRNA *ptr, float *values)
483{
484 Mesh *mesh = rna_mesh(ptr);
485 const int index = rna_MeshLoop_index_get(ptr);
486 const float4 *layer = static_cast<const float4 *>(
488
489 if (!layer) {
490 zero_v3(values);
491 }
492 else {
493 copy_v3_v3(values, reinterpret_cast<const float *>(layer + index));
494 }
495}
496
497static float rna_MeshLoop_bitangent_sign_get(PointerRNA *ptr)
498{
499 Mesh *mesh = rna_mesh(ptr);
500 const int index = rna_MeshLoop_index_get(ptr);
501 const float4 *vec = static_cast<const float4 *>(
503
504 return (vec) ? vec[index][3] : 0.0f;
505}
506
507static void rna_MeshLoop_bitangent_get(PointerRNA *ptr, float *values)
508{
509 Mesh *mesh = rna_mesh(ptr);
510 const int index = rna_MeshLoop_index_get(ptr);
511 const float4 *vec = static_cast<const float4 *>(
513
514 if (vec) {
515 cross_v3_v3v3(values, mesh->corner_normals()[index], vec[index]);
516 mul_v3_fl(values, vec[index][3]);
517 }
518 else {
519 zero_v3(values);
520 }
521}
522
523static void rna_MeshPolygon_normal_get(PointerRNA *ptr, float *values)
524{
525 Mesh *mesh = rna_mesh(ptr);
526 const int poly_start = *(static_cast<const int *>(ptr->data));
527 const int poly_size = *((static_cast<const int *>(ptr->data)) + 1) - poly_start;
528 const Span<int> face_verts = mesh->corner_verts().slice(poly_start, poly_size);
529 const float3 result = bke::mesh::face_normal_calc(mesh->vert_positions(), face_verts);
530 copy_v3_v3(values, result);
531}
532
533static bool rna_MeshPolygon_hide_get(PointerRNA *ptr)
534{
535 const Mesh *mesh = rna_mesh(ptr);
536 const int index = rna_MeshPolygon_index_get(ptr);
537 const bke::AttributeAccessor attributes = mesh->attributes();
538 const VArray hide_poly = *attributes.lookup_or_default<bool>(
539 ".hide_poly", bke::AttrDomain::Face, false);
540 return hide_poly[index];
541}
542
543static void rna_MeshPolygon_hide_set(PointerRNA *ptr, bool value)
544{
545 Mesh *mesh = rna_mesh(ptr);
546 const int index = rna_MeshPolygon_index_get(ptr);
547 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
548 bke::AttributeWriter hide_poly = attributes.lookup_or_add_for_write<bool>(
550 hide_poly.varray.set(index, value);
551 hide_poly.finish();
552}
553
554static bool rna_MeshPolygon_use_smooth_get(PointerRNA *ptr)
555{
556 const Mesh *mesh = rna_mesh(ptr);
557 const int index = rna_MeshPolygon_index_get(ptr);
558 const bke::AttributeAccessor attributes = mesh->attributes();
559 const VArray sharp_face = *attributes.lookup_or_default<bool>(
560 "sharp_face", bke::AttrDomain::Face, false);
561 return !sharp_face[index];
562}
563
564static void rna_MeshPolygon_use_smooth_set(PointerRNA *ptr, bool value)
565{
566 Mesh *mesh = rna_mesh(ptr);
567 const int index = rna_MeshPolygon_index_get(ptr);
568 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
569 bke::AttributeWriter sharp_face = attributes.lookup_or_add_for_write<bool>(
571 sharp_face.varray.set(index, !value);
572 sharp_face.finish();
573}
574
575static bool rna_MeshPolygon_select_get(PointerRNA *ptr)
576{
577 const Mesh *mesh = rna_mesh(ptr);
578 const int index = rna_MeshPolygon_index_get(ptr);
579 const bke::AttributeAccessor attributes = mesh->attributes();
580 const VArray select_poly = *attributes.lookup_or_default<bool>(
581 ".select_poly", bke::AttrDomain::Face, false);
582 return select_poly[index];
583}
584
585static void rna_MeshPolygon_select_set(PointerRNA *ptr, bool value)
586{
587 Mesh *mesh = rna_mesh(ptr);
588 const int index = rna_MeshPolygon_index_get(ptr);
589 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
590 bke::AttributeWriter select_poly = attributes.lookup_or_add_for_write<bool>(
592 select_poly.varray.set(index, value);
593 select_poly.finish();
594}
595
596static int rna_MeshPolygon_material_index_get(PointerRNA *ptr)
597{
598 const Mesh *mesh = rna_mesh(ptr);
599 const bke::AttributeAccessor attributes = mesh->attributes();
600 const VArray material_index = *attributes.lookup_or_default<int>(
601 "material_index", bke::AttrDomain::Face, 0);
602 return material_index[rna_MeshPolygon_index_get(ptr)];
603}
604
605static void rna_MeshPolygon_material_index_set(PointerRNA *ptr, int value)
606{
607 Mesh *mesh = rna_mesh(ptr);
608 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
609 bke::AttributeWriter material_index = attributes.lookup_or_add_for_write<int>(
610 "material_index", bke::AttrDomain::Face);
611 material_index.varray.set(rna_MeshPolygon_index_get(ptr), max_ii(0, value));
612 material_index.finish();
613}
614
615static void rna_MeshPolygon_center_get(PointerRNA *ptr, float *values)
616{
617 Mesh *mesh = rna_mesh(ptr);
618 const int poly_start = *(static_cast<const int *>(ptr->data));
619 const int poly_size = *((static_cast<const int *>(ptr->data)) + 1) - poly_start;
620 const Span<int> face_verts = mesh->corner_verts().slice(poly_start, poly_size);
621 const float3 result = bke::mesh::face_center_calc(mesh->vert_positions(), face_verts);
622 copy_v3_v3(values, result);
623}
624
625static float rna_MeshPolygon_area_get(PointerRNA *ptr)
626{
627 Mesh *mesh = id_cast<Mesh *>(ptr->owner_id);
628 const int poly_start = *(static_cast<const int *>(ptr->data));
629 const int poly_size = *((static_cast<const int *>(ptr->data)) + 1) - poly_start;
630 const Span<int> face_verts = mesh->corner_verts().slice(poly_start, poly_size);
631 return bke::mesh::face_area_calc(mesh->vert_positions(), face_verts);
632}
633
634static void rna_MeshPolygon_flip(ID *id, MIntProperty *poly_offset_p)
635{
636 Mesh *mesh = id_cast<Mesh *>(id);
637 const int index = reinterpret_cast<int *>(poly_offset_p) - mesh->faces().data().data();
641}
642
643static void rna_MeshLoopTriangle_verts_get(PointerRNA *ptr, int *values)
644{
645 Mesh *mesh = rna_mesh(ptr);
646 const Span<int> corner_verts = mesh->corner_verts();
647 int3 tri = *static_cast<int3 *>(ptr->data);
648 values[0] = corner_verts[tri[0]];
649 values[1] = corner_verts[tri[1]];
650 values[2] = corner_verts[tri[2]];
651}
652
653static void rna_MeshLoopTriangle_normal_get(PointerRNA *ptr, float *values)
654{
655 Mesh *mesh = rna_mesh(ptr);
656 int3 tri = *static_cast<int3 *>(ptr->data);
657 const Span<float3> positions = mesh->vert_positions();
658 const Span<int> corner_verts = mesh->corner_verts();
659 const int v1 = corner_verts[tri[0]];
660 const int v2 = corner_verts[tri[1]];
661 const int v3 = corner_verts[tri[2]];
662
663 normal_tri_v3(values, positions[v1], positions[v2], positions[v3]);
664}
665
666static void rna_MeshLoopTriangle_split_normals_get(PointerRNA *ptr, float *values)
667{
668 Mesh *mesh = rna_mesh(ptr);
669 const Span<float3> corner_normals = mesh->corner_normals();
670 const int3 tri = *static_cast<const int3 *>(ptr->data);
671 copy_v3_v3(values + 0, corner_normals[tri[0]]);
672 copy_v3_v3(values + 3, corner_normals[tri[1]]);
673 copy_v3_v3(values + 6, corner_normals[tri[2]]);
674}
675
676static float rna_MeshLoopTriangle_area_get(PointerRNA *ptr)
677{
678 Mesh *mesh = rna_mesh(ptr);
679 int3 tri = *static_cast<int3 *>(ptr->data);
680 const Span<float3> positions = mesh->vert_positions();
681 const Span<int> corner_verts = mesh->corner_verts();
682 const int v1 = corner_verts[tri[0]];
683 const int v2 = corner_verts[tri[1]];
684 const int v3 = corner_verts[tri[2]];
685 return area_tri_v3(positions[v1], positions[v2], positions[v3]);
686}
687
688static void rna_MeshLoopColor_color_get(PointerRNA *ptr, float *values)
689{
690 MLoopCol *mlcol = static_cast<MLoopCol *>(ptr->data);
691
692 values[0] = mlcol->r / 255.0f;
693 values[1] = mlcol->g / 255.0f;
694 values[2] = mlcol->b / 255.0f;
695 values[3] = mlcol->a / 255.0f;
696}
697
698static void rna_MeshLoopColor_color_set(PointerRNA *ptr, const float *values)
699{
700 MLoopCol *mlcol = static_cast<MLoopCol *>(ptr->data);
701
702 mlcol->r = round_fl_to_uchar_clamp(values[0] * 255.0f);
703 mlcol->g = round_fl_to_uchar_clamp(values[1] * 255.0f);
704 mlcol->b = round_fl_to_uchar_clamp(values[2] * 255.0f);
705 mlcol->a = round_fl_to_uchar_clamp(values[3] * 255.0f);
706}
707
708static int rna_Mesh_texspace_editable(const PointerRNA *ptr, const char ** /*r_info*/)
709{
710 Mesh *mesh = static_cast<Mesh *>(ptr->data);
711 return (mesh->texspace_flag & ME_TEXSPACE_FLAG_AUTO) ? PropertyFlag(0) : PROP_EDITABLE;
712}
713
714static void rna_Mesh_texspace_size_get(PointerRNA *ptr, float values[3])
715{
716 Mesh *mesh = static_cast<Mesh *>(ptr->data);
717
719
720 copy_v3_v3(values, mesh->texspace_size);
721}
722
723static void rna_Mesh_texspace_location_get(PointerRNA *ptr, float values[3])
724{
725 Mesh *mesh = static_cast<Mesh *>(ptr->data);
726
728
729 copy_v3_v3(values, mesh->texspace_location);
730}
731
732static void rna_MeshVertex_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
733{
734 Mesh *mesh = rna_mesh(ptr);
735 MDeformVert *dverts = mesh->deform_verts_for_write().data();
736 if (dverts) {
737 const int index = rna_MeshVertex_index_get(ptr);
738 MDeformVert *dvert = &dverts[index];
739
741 iter, ptr, dvert->dw, sizeof(MDeformWeight), dvert->totweight, 0, nullptr);
742 }
743 else {
744 rna_iterator_array_begin(iter, ptr, nullptr, 0, 0, 0, nullptr);
745 }
746}
747
748static void rna_MeshVertex_undeformed_co_get(PointerRNA *ptr, float values[3])
749{
750 Mesh *mesh = rna_mesh(ptr);
751 const float *position = static_cast<const float *>(ptr->data);
752 const float3 *orco = static_cast<const float3 *>(
753 CustomData_get_layer(&mesh->vert_data, CD_ORCO));
754
755 if (orco) {
756 const int index = rna_MeshVertex_index_get(ptr);
757 /* orco is normalized to 0..1, we do inverse to match the vertex position */
758 float texspace_location[3], texspace_size[3];
759
761 mesh->texcomesh ? mesh->texcomesh : mesh, texspace_location, texspace_size);
762 madd_v3_v3v3v3(values, texspace_location, orco[index], texspace_size);
763 }
764 else {
765 copy_v3_v3(values, position);
766 }
767}
768
769/* uv_layers */
770
771static void rna_Mesh_uv_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
772{
775}
776
777PointerRNA rna_Mesh_uv_layers_iterator_get(CollectionPropertyIterator *iter)
778{
780 return RNA_pointer_create_with_parent(iter->parent, RNA_MeshUVLoopLayer, layer);
781}
782
783static int rna_Mesh_uv_layers_length(PointerRNA *ptr)
784{
785 AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id);
787}
788
789static void rna_Mesh_uv_layer_index_range(PointerRNA *ptr, int *min, int *max, int *, int *)
790{
791 AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id);
792 *min = 0;
793 *max = std::max(
795}
796
797static PointerRNA rna_Mesh_uv_layer_active_get(PointerRNA *ptr)
798{
799 Mesh *mesh = rna_mesh(ptr);
801 *ptr, mesh->active_uv_map_name(), ATTR_DOMAIN_MASK_CORNER, CD_MASK_PROP_FLOAT2);
802 attr_ptr.type = RNA_MeshUVLoopLayer;
803 return attr_ptr;
804}
805
806static void rna_Mesh_uv_layer_active_set(PointerRNA *ptr, PointerRNA value, ReportList *)
807{
808 Mesh *mesh = rna_mesh(ptr);
809 mesh->uv_maps_active_set(rna_Attribute_name_get(value));
811}
812
813static int rna_Mesh_uv_layer_active_index_get(PointerRNA *ptr)
814{
815 AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id);
816 return BKE_attribute_to_index(owner,
817 rna_mesh(ptr)->active_uv_map_name(),
820 false);
821}
822
823static void rna_Mesh_uv_layer_active_index_set(PointerRNA *ptr, int value)
824{
825 AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id);
826 const std::optional<StringRef> name = BKE_attribute_from_index(
827 owner, value, ATTR_DOMAIN_MASK_CORNER, CD_MASK_PROP_FLOAT2, false);
828 if (!name) {
829 return;
830 }
831 Mesh *mesh = rna_mesh(ptr);
832 mesh->uv_maps_active_set(*name);
834}
835
836static PointerRNA rna_Mesh_uv_layer_default_get(PointerRNA *ptr)
837{
838 Mesh *mesh = rna_mesh(ptr);
840 *ptr, mesh->default_uv_map_name(), ATTR_DOMAIN_MASK_CORNER, CD_MASK_PROP_FLOAT2);
841 attr_ptr.type = RNA_MeshUVLoopLayer;
842 return attr_ptr;
843}
844
845static void rna_Mesh_uv_layer_default_set(PointerRNA *ptr, PointerRNA value, ReportList *)
846{
847 Mesh *mesh = rna_mesh(ptr);
848 mesh->uv_maps_default_set(rna_Attribute_name_get(value));
850}
851
852static int rna_Mesh_uv_layer_default_index_get(PointerRNA *ptr)
853{
854 AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id);
855 return BKE_attribute_to_index(owner,
856 rna_mesh(ptr)->default_uv_map_name(),
859 false);
860}
861
862static void rna_Mesh_uv_layer_default_index_set(PointerRNA *ptr, int value)
863{
864 AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id);
865 const std::optional<StringRef> name = BKE_attribute_from_index(
866 owner, value, ATTR_DOMAIN_MASK_CORNER, CD_MASK_PROP_FLOAT2, false);
867 if (!name) {
868 return;
869 }
870 Mesh *mesh = rna_mesh(ptr);
871 mesh->uv_maps_default_set(*name);
873}
874
875static PointerRNA rna_Mesh_uv_layer_clone_get(PointerRNA *ptr)
876{
878 *ptr, rna_mesh(ptr)->clone_uv_map_attribute, ATTR_DOMAIN_MASK_CORNER, CD_MASK_PROP_FLOAT2);
879 attr_ptr.type = RNA_MeshUVLoopLayer;
880 return attr_ptr;
881}
882
883static void rna_Mesh_uv_layer_clone_set(PointerRNA *ptr, PointerRNA value, ReportList *)
884{
885 Mesh *mesh = rna_mesh(ptr);
886 const StringRefNull name = rna_Attribute_name_get(value);
887 MEM_SAFE_DELETE(mesh->clone_uv_map_attribute);
888 if (name.is_empty()) {
889 return;
890 }
891 mesh->clone_uv_map_attribute = BLI_strdupn(name.c_str(), name.size());
893}
894
895static int rna_Mesh_uv_layer_clone_index_get(PointerRNA *ptr)
896{
897 Mesh *mesh = rna_mesh(ptr);
898 const VectorSet<StringRefNull> names = mesh->uv_map_names();
899 if (!names.contains_as(mesh->clone_uv_map_attribute)) {
900 return 0;
901 }
902 return names.index_of_as(mesh->clone_uv_map_attribute);
903}
904
905static void rna_Mesh_uv_layer_clone_index_set(PointerRNA *ptr, int value)
906{
907 Mesh *mesh = rna_mesh(ptr);
908 MEM_SAFE_DELETE(mesh->clone_uv_map_attribute);
909 const VectorSet<StringRefNull> names = mesh->uv_map_names();
910 if (!names.index_range().contains(value)) {
911 return;
912 }
913 mesh->clone_uv_map_attribute = BLI_strdupn(names[value].c_str(), names[value].size());
915}
916
917static PointerRNA rna_Mesh_uv_layer_stencil_get(PointerRNA *ptr)
918{
920 *ptr, rna_mesh(ptr)->stencil_uv_map_attribute, ATTR_DOMAIN_MASK_CORNER, CD_MASK_PROP_FLOAT2);
921 attr_ptr.type = RNA_MeshUVLoopLayer;
922 return attr_ptr;
923}
924
925static void rna_Mesh_uv_layer_stencil_set(PointerRNA *ptr, PointerRNA value, ReportList *)
926{
927 Mesh *mesh = rna_mesh(ptr);
928 const StringRefNull name = rna_Attribute_name_get(value);
929 MEM_SAFE_DELETE(mesh->stencil_uv_map_attribute);
930 if (name.is_empty()) {
931 return;
932 }
933 mesh->stencil_uv_map_attribute = BLI_strdupn(name.c_str(), name.size());
935}
936
937static int rna_Mesh_uv_layer_stencil_index_get(PointerRNA *ptr)
938{
939 Mesh *mesh = rna_mesh(ptr);
940 const VectorSet<StringRefNull> names = mesh->uv_map_names();
941 if (!names.contains_as(mesh->stencil_uv_map_attribute)) {
942 return 0;
943 }
944 return names.index_of_as(mesh->stencil_uv_map_attribute);
945}
946
947static void rna_Mesh_uv_layer_stencil_index_set(PointerRNA *ptr, int value)
948{
949 Mesh *mesh = rna_mesh(ptr);
950 MEM_SAFE_DELETE(mesh->stencil_uv_map_attribute);
951 const VectorSet<StringRefNull> names = mesh->uv_map_names();
952 if (!names.index_range().contains(value)) {
953 return;
954 }
955 mesh->stencil_uv_map_attribute = BLI_strdupn(names[value].c_str(), names[value].size());
957}
958
959/* MeshUVLoopLayer */
960
961static std::optional<std::string> rna_MeshUVLoopLayer_path(const PointerRNA *ptr)
962{
963 const StringRefNull name = rna_Attribute_name_get(*ptr);
964 return fmt::format("uv_layers[\"{}\"]", BLI_str_escape(name.c_str()));
965}
966
967static void bool_layer_begin(CollectionPropertyIterator *iter,
968 PointerRNA *ptr,
969 StringRef (*layername_func)(const StringRef uv_name, char *buffer))
970{
971 Mesh *mesh = rna_mesh(ptr);
972 if (mesh->runtime->edit_mesh) {
973 rna_iterator_array_begin(iter, ptr, nullptr, 0, 0, 0, nullptr);
974 return;
975 }
976 char buffer[MAX_CUSTOMDATA_LAYER_NAME];
977 const StringRef name = rna_Attribute_name_get(*ptr);
979 layername_func(name, buffer),
982 if (!bool_ptr) {
983 rna_iterator_array_begin(iter, ptr, nullptr, 0, 0, 0, nullptr);
984 return;
985 }
986 rna_Attribute_data_begin(iter, &bool_ptr);
987}
988
989static int bool_layer_length(PointerRNA *ptr,
990 StringRef (*layername_func)(const StringRef uv_name, char *buffer))
991{
992 char buffer[MAX_CUSTOMDATA_LAYER_NAME];
993 Mesh *mesh = rna_mesh(ptr);
994 const StringRef name = rna_Attribute_name_get(*ptr);
996 layername_func(name, buffer),
999 return rna_Attribute_data_length(&bool_ptr);
1000}
1001
1002static PointerRNA bool_layer_ensure(PointerRNA *ptr,
1003 StringRef (*layername_func)(const StringRef uv_name,
1004 char *buffer))
1005{
1006 char buffer[MAX_CUSTOMDATA_LAYER_NAME];
1007 Mesh *mesh = rna_mesh(ptr);
1008 if (mesh->runtime->edit_mesh) {
1009 return {};
1010 }
1011 PointerRNA mesh_ptr = RNA_id_pointer_create(&mesh->id);
1012 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
1013 const StringRef name = layername_func(rna_Attribute_name_get(*ptr), buffer);
1014 if (attributes.contains(name)) {
1017 }
1018 attributes.add<bool>(name, bke::AttrDomain::Corner, bke::AttributeInitDefaultValue());
1021}
1022
1023/* Collection accessors for pin. */
1024static void rna_MeshUVLoopLayer_pin_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1025{
1026 bool_layer_begin(iter, ptr, BKE_uv_map_pin_name_get);
1027}
1028
1029static int rna_MeshUVLoopLayer_pin_length(PointerRNA *ptr)
1030{
1031 return bool_layer_length(ptr, BKE_uv_map_pin_name_get);
1032}
1033
1034static PointerRNA rna_MeshUVLoopLayer_pin_ensure(PointerRNA ptr)
1035{
1036 return bool_layer_ensure(&ptr, BKE_uv_map_pin_name_get);
1037}
1038
1039static bool rna_MeshUVLoopLayer_active_render_get(PointerRNA *ptr)
1040{
1041 return rna_Attribute_name_get(*ptr) == rna_mesh(ptr)->default_uv_map_name();
1042}
1043
1044static bool rna_MeshUVLoopLayer_active_get(PointerRNA *ptr)
1045{
1046 return rna_Attribute_name_get(*ptr) == rna_mesh(ptr)->active_uv_map_name();
1047}
1048
1049static bool rna_MeshUVLoopLayer_clone_get(PointerRNA *ptr)
1050{
1051 Mesh *mesh = rna_mesh(ptr);
1052 const StringRefNull name = rna_Attribute_name_get(*ptr);
1053 return StringRef(mesh->clone_uv_map_attribute) == name;
1054}
1055
1056static void rna_MeshUVLoopLayer_active_render_set(PointerRNA *ptr, bool value)
1057{
1058 if (value) {
1059 Mesh *mesh = rna_mesh(ptr);
1060 mesh->uv_maps_default_set(rna_Attribute_name_get(*ptr));
1061 }
1062}
1063
1064static void rna_MeshUVLoopLayer_active_set(PointerRNA *ptr, bool value)
1065{
1066 if (value) {
1067 Mesh *mesh = rna_mesh(ptr);
1068 mesh->uv_maps_active_set(rna_Attribute_name_get(*ptr));
1069 }
1070}
1071
1072static void rna_MeshUVLoopLayer_clone_set(PointerRNA *ptr, bool value)
1073{
1074 if (!value) {
1075 return;
1076 }
1077 Mesh *mesh = rna_mesh(ptr);
1078 const StringRefNull name = rna_Attribute_name_get(*ptr);
1079 MEM_SAFE_DELETE(mesh->clone_uv_map_attribute);
1080 if (name.is_empty()) {
1081 return;
1082 }
1083 mesh->clone_uv_map_attribute = BLI_strdupn(name.c_str(), name.size());
1085}
1086
1087bool rna_MeshUVLoopLayer_data_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1088{
1090 rna_Attribute_data_begin(&iter, ptr);
1091 if (!iter.valid) {
1092 *r_ptr = {};
1093 return false;
1094 }
1095
1096 ArrayIterator *internal = &iter.internal.array;
1097 if (index < 0 || index >= internal->length) {
1098 *r_ptr = {};
1099 return false;
1100 }
1101
1102 internal->ptr += internal->itemsize * index;
1103
1105 iter.parent, RNA_MeshUVLoop, rna_iterator_array_get(&iter));
1107 return true;
1108}
1109
1110static void rna_Mesh_vertex_colors_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1111{
1114}
1115
1116PointerRNA rna_Mesh_vertex_colors_iterator_get(CollectionPropertyIterator *iter)
1117{
1119 return RNA_pointer_create_with_parent(iter->parent, RNA_MeshLoopColorLayer, layer);
1120}
1121
1122static int rna_Mesh_vertex_colors_length(PointerRNA *ptr)
1123{
1124 AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id);
1126}
1127
1128static void rna_Mesh_vertex_color_index_range(PointerRNA *ptr, int *min, int *max, int *, int *)
1129{
1130 AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id);
1131 *min = 0;
1132 *max = std::max(
1134 0);
1135}
1136
1137static PointerRNA rna_Mesh_vertex_color_active_get(PointerRNA *ptr)
1138{
1140 rna_mesh(ptr)->active_color_attribute,
1143 attr_ptr.type = RNA_MeshLoopColorLayer;
1144 return attr_ptr;
1145}
1146
1147static void rna_Mesh_vertex_color_active_set(PointerRNA *ptr,
1148 const PointerRNA value,
1149 ReportList * /*reports*/)
1150{
1151 if (!value) {
1152 return;
1153 }
1154 Mesh *mesh = static_cast<Mesh *>(ptr->data);
1156}
1157
1158static int rna_Mesh_vertex_color_active_index_get(PointerRNA *ptr)
1159{
1160 Mesh *mesh = static_cast<Mesh *>(ptr->data);
1161 AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id);
1162 return BKE_attribute_to_index(owner,
1163 mesh->active_color_attribute,
1166 false);
1167}
1168
1169static void rna_Mesh_vertex_color_active_index_set(PointerRNA *ptr, int value)
1170{
1171 Mesh *mesh = static_cast<Mesh *>(ptr->data);
1172 AttributeOwner owner = AttributeOwner::from_id(ptr->owner_id);
1173 const std::optional<StringRef> name = BKE_attribute_from_index(
1174 owner, value, ATTR_DOMAIN_MASK_CORNER, CD_MASK_PROP_BYTE_COLOR, false);
1175 if (!name) {
1176 fprintf(stderr, "Invalid loop byte attribute index %d\n", value);
1177 return;
1178 }
1180}
1181
1182static bool rna_mesh_color_active_render_get(PointerRNA *ptr)
1183{
1184 const Mesh *mesh = rna_mesh(ptr);
1185 return rna_Attribute_name_get(*ptr) == StringRef(mesh->default_color_attribute);
1186}
1187
1188static bool rna_mesh_color_active_get(PointerRNA *ptr)
1189{
1190 const Mesh *mesh = rna_mesh(ptr);
1191 return rna_Attribute_name_get(*ptr) == StringRef(mesh->active_color_attribute);
1192}
1193
1194static void rna_mesh_color_active_render_set(PointerRNA *ptr, bool value)
1195{
1196 if (value) {
1197 Mesh *mesh = rna_mesh(ptr);
1199 }
1200}
1201
1202static void rna_mesh_color_active_set(PointerRNA *ptr, bool value)
1203{
1204 if (value) {
1205 Mesh *mesh = rna_mesh(ptr);
1207 }
1208}
1209
1210static void rna_Mesh_skin_vertices_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1211{
1212 memset(&iter->internal.array, 0, sizeof(iter->internal.array));
1214 *ptr, "skin_modifier_radius", ATTR_DOMAIN_MASK_POINT, CD_MASK_PROP_FLOAT2);
1215 void *layer = attr_ptr ? attr_ptr.data : nullptr;
1217 iter, ptr, layer, sizeof(CustomDataLayer), layer ? 1 : 0, false, nullptr);
1218}
1219
1220PointerRNA rna_Mesh_skin_vertices_iterator_get(CollectionPropertyIterator *iter)
1221{
1223 iter->parent, RNA_MeshSkinVertexLayer, rna_iterator_array_get(iter));
1224}
1225
1226static int rna_Mesh_skin_vertices_length(PointerRNA *ptr)
1227{
1229 *ptr, "skin_modifier_radius", ATTR_DOMAIN_MASK_POINT, CD_MASK_PROP_FLOAT2);
1230 return attr_ptr ? 1 : 0;
1231}
1232
1233/* poly.vertices - this is faked loop access for convenience */
1234static int rna_MeshPoly_vertices_get_length(const PointerRNA *ptr,
1236{
1237 const int *poly_offset_p = static_cast<const int *>(ptr->data);
1238 const int poly_start = *poly_offset_p;
1239 const int poly_size = *(poly_offset_p + 1) - poly_start;
1240 /* NOTE: raw access uses dummy item, this _could_ crash,
1241 * watch out for this, #MFace uses it but it can't work here. */
1242 return (length[0] = poly_size);
1243}
1244
1245static void rna_MeshPoly_vertices_get(PointerRNA *ptr, int *values)
1246{
1247 const Mesh *mesh = rna_mesh(ptr);
1248 const int *poly_offset_p = static_cast<const int *>(ptr->data);
1249 const int poly_start = *poly_offset_p;
1250 const int poly_size = *(poly_offset_p + 1) - poly_start;
1251 memcpy(values, &mesh->corner_verts()[poly_start], sizeof(int) * poly_size);
1252}
1253
1254static int rna_MeshPolygon_loop_total_get(PointerRNA *ptr)
1255{
1256 const int *data = static_cast<const int *>(ptr->data);
1257 return *(data + 1) - *data;
1258}
1259
1260static void rna_MeshPoly_vertices_set(PointerRNA *ptr, const int *values)
1261{
1262 Mesh *mesh = rna_mesh(ptr);
1263 const int *poly_offset_p = static_cast<const int *>(ptr->data);
1264 const int poly_start = *poly_offset_p;
1265 const int poly_size = *(poly_offset_p + 1) - poly_start;
1266 memcpy(&mesh->corner_verts_for_write()[poly_start], values, sizeof(int) * poly_size);
1267}
1268
1269/* disabling, some importers don't know the total material count when assigning materials */
1270# if 0
1271static void rna_MeshPoly_material_index_range(
1272 PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
1273{
1274 Mesh *mesh = rna_mesh(ptr);
1275 *min = 0;
1276 *max = max_ii(0, mesh->totcol - 1);
1277}
1278# endif
1279
1280static bool rna_MeshEdge_hide_get(PointerRNA *ptr)
1281{
1282 const Mesh *mesh = rna_mesh(ptr);
1283 const int index = rna_MeshEdge_index_get(ptr);
1284 const bke::AttributeAccessor attributes = mesh->attributes();
1285 const VArray hide_edge = *attributes.lookup_or_default<bool>(
1286 ".hide_edge", bke::AttrDomain::Edge, false);
1287 return hide_edge[index];
1288}
1289
1290static void rna_MeshEdge_hide_set(PointerRNA *ptr, bool value)
1291{
1292 Mesh *mesh = rna_mesh(ptr);
1293 const int index = rna_MeshEdge_index_get(ptr);
1294 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
1295 bke::AttributeWriter hide_edge = attributes.lookup_or_add_for_write<bool>(
1297 hide_edge.varray.set(index, value);
1298 hide_edge.finish();
1299}
1300
1301static bool rna_MeshEdge_select_get(PointerRNA *ptr)
1302{
1303 const Mesh *mesh = rna_mesh(ptr);
1304 const int index = rna_MeshEdge_index_get(ptr);
1305 const bke::AttributeAccessor attributes = mesh->attributes();
1306 const VArray select_edge = *attributes.lookup_or_default<bool>(
1307 ".select_edge", bke::AttrDomain::Edge, false);
1308 return select_edge[index];
1309}
1310
1311static void rna_MeshEdge_select_set(PointerRNA *ptr, bool value)
1312{
1313 Mesh *mesh = rna_mesh(ptr);
1314 const int index = rna_MeshEdge_index_get(ptr);
1315 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
1316 bke::AttributeWriter select_edge = attributes.lookup_or_add_for_write<bool>(
1318 select_edge.varray.set(index, value);
1319 select_edge.finish();
1320}
1321
1322static bool rna_MeshEdge_use_edge_sharp_get(PointerRNA *ptr)
1323{
1324 const Mesh *mesh = rna_mesh(ptr);
1325 const int index = rna_MeshEdge_index_get(ptr);
1326 const bke::AttributeAccessor attributes = mesh->attributes();
1327 const VArray sharp_edge = *attributes.lookup_or_default<bool>(
1328 "sharp_edge", bke::AttrDomain::Edge, false);
1329 return sharp_edge[index];
1330}
1331
1332static void rna_MeshEdge_use_edge_sharp_set(PointerRNA *ptr, bool value)
1333{
1334 Mesh *mesh = rna_mesh(ptr);
1335 const int index = rna_MeshEdge_index_get(ptr);
1336 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
1337 bke::AttributeWriter sharp_edge = attributes.lookup_or_add_for_write<bool>(
1339 sharp_edge.varray.set(index, value);
1340 sharp_edge.finish();
1341}
1342
1343static bool rna_MeshEdge_use_seam_get(PointerRNA *ptr)
1344{
1345 const Mesh *mesh = rna_mesh(ptr);
1346 const int index = rna_MeshEdge_index_get(ptr);
1347 const bke::AttributeAccessor attributes = mesh->attributes();
1348 const VArray uv_seam = *attributes.lookup_or_default<bool>(
1349 "uv_seam", bke::AttrDomain::Edge, false);
1350 return uv_seam[index];
1351}
1352
1353static void rna_MeshEdge_use_seam_set(PointerRNA *ptr, bool value)
1354{
1355 Mesh *mesh = rna_mesh(ptr);
1356 const int index = rna_MeshEdge_index_get(ptr);
1357 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
1358 bke::AttributeWriter uv_seam = attributes.lookup_or_add_for_write<bool>(
1360 uv_seam.varray.set(index, value);
1361 uv_seam.finish();
1362}
1363
1364static bool rna_MeshEdge_is_loose_get(PointerRNA *ptr)
1365{
1366 const Mesh *mesh = rna_mesh(ptr);
1367 const int index = rna_MeshEdge_index_get(ptr);
1368 return mesh->loose_edges().contains(index);
1369}
1370
1371static int rna_MeshLoopTriangle_material_index_get(PointerRNA *ptr)
1372{
1373 const Mesh *mesh = rna_mesh(ptr);
1374 const bke::AttributeAccessor attributes = mesh->attributes();
1375 const VArray material_indices = *attributes.lookup_or_default<int>(
1376 "material_index", bke::AttrDomain::Face, 0);
1377 return material_indices[rna_MeshLoopTriangle_polygon_index_get(ptr)];
1378}
1379
1380static bool rna_MeshLoopTriangle_use_smooth_get(PointerRNA *ptr)
1381{
1382 const Mesh *mesh = rna_mesh(ptr);
1383 const bke::AttributeAccessor attributes = mesh->attributes();
1384 const VArray sharp_face = *attributes.lookup_or_default<bool>(
1385 "sharp_face", bke::AttrDomain::Face, false);
1386 return !sharp_face[rna_MeshLoopTriangle_polygon_index_get(ptr)];
1387}
1388
1389/* path construction */
1390
1391static std::optional<std::string> rna_VertexGroupElement_path(const PointerRNA *ptr)
1392{
1393 const Mesh *mesh = rna_mesh(ptr); /* XXX not always! */
1394 const MDeformWeight *dw = static_cast<MDeformWeight *>(ptr->data);
1395 const MDeformVert *dvert = mesh->deform_verts().data();
1396 int a, b;
1397
1398 for (a = 0; a < mesh->verts_num; a++, dvert++) {
1399 for (b = 0; b < dvert->totweight; b++) {
1400 if (dw == &dvert->dw[b]) {
1401 return fmt::format("vertices[{}].groups[{}]", a, b);
1402 }
1403 }
1404 }
1405
1406 return std::nullopt;
1407}
1408
1409static std::optional<std::string> rna_MeshPolygon_path(const PointerRNA *ptr)
1410{
1411 return fmt::format("polygons[{}]", rna_MeshPolygon_index_get(const_cast<PointerRNA *>(ptr)));
1412}
1413
1414static std::optional<std::string> rna_MeshLoopTriangle_path(const PointerRNA *ptr)
1415{
1416 const int index = rna_MeshLoopTriangle_index_get(const_cast<PointerRNA *>(ptr));
1417 return fmt::format("loop_triangles[{}]", index);
1418}
1419
1420static std::optional<std::string> rna_MeshEdge_path(const PointerRNA *ptr)
1421{
1422 return fmt::format("edges[{}]", rna_MeshEdge_index_get(const_cast<PointerRNA *>(ptr)));
1423}
1424
1425static std::optional<std::string> rna_MeshLoop_path(const PointerRNA *ptr)
1426{
1427 return fmt::format("loops[{}]", rna_MeshLoop_index_get(const_cast<PointerRNA *>(ptr)));
1428}
1429
1430static std::optional<std::string> rna_MeshVertex_path(const PointerRNA *ptr)
1431{
1432 return fmt::format("vertices[{}]", rna_MeshVertex_index_get(const_cast<PointerRNA *>(ptr)));
1433}
1434
1435struct AttrReverseLookup {
1436 StringRefNull name;
1437 int index_in_group;
1438 int elem_index;
1439};
1440static std::optional<AttrReverseLookup> find_attr_from_data_ptr(const PointerRNA *ptr,
1441 const AttrDomainMask domain_mask,
1442 const eCustomDataMask cd_type_mask)
1443{
1444 const Mesh *mesh = rna_mesh(ptr);
1445 const void *value = static_cast<const void *>(ptr->data);
1446
1447 std::optional<AttrReverseLookup> result;
1448
1449 int index_in_group = -1;
1450 mesh->attributes().foreach_attribute([&](const bke::AttributeIter &iter) {
1451 if (!(ATTR_DOMAIN_AS_MASK(iter.domain) & domain_mask)) {
1452 return;
1453 }
1454 if (!(CD_TYPE_AS_MASK(*bke::attr_type_to_custom_data_type(iter.data_type)) & cd_type_mask)) {
1455 return;
1456 }
1457 const GVArray data = *iter.get();
1458 if (!data.is_span()) {
1459 /* All these attributes should be spans currently. If not, this pointer comparison contains
1460 * test needs to be updated. */
1462 return;
1463 }
1464 index_in_group++;
1465 const GSpan span = data.get_internal_span();
1466 int64_t index = reinterpret_cast<const std::byte *>(value) -
1467 reinterpret_cast<const std::byte *>(span.data());
1468 if (index < 0) {
1469 return;
1470 }
1471 index /= span.type().size;
1472 if (index >= span.size()) {
1473 return;
1474 }
1475 result = AttrReverseLookup{iter.name, index_in_group, int(index)};
1476 iter.stop();
1477 });
1478
1479 return result;
1480}
1481
1482static std::optional<std::string> rna_LoopCustomData_data_path(const PointerRNA *ptr,
1483 const StringRef collection,
1484 eCustomDataType type)
1485{
1486 const std::optional<AttrReverseLookup> lookup = find_attr_from_data_ptr(
1488 if (!lookup) {
1489 return std::nullopt;
1490 }
1491 return fmt::format(
1492 "{}[\"{}\"].data[{}]", collection, BLI_str_escape(lookup->name), lookup->elem_index);
1493}
1494
1495static void rna_Mesh_vertices_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1496{
1497 Mesh *mesh = rna_mesh(ptr);
1499 ptr,
1500 mesh->vert_positions_for_write().data(),
1501 sizeof(float3),
1502 mesh->verts_num,
1503 false,
1504 nullptr);
1505}
1506static int rna_Mesh_vertices_length(PointerRNA *ptr)
1507{
1508 const Mesh *mesh = rna_mesh(ptr);
1509 return mesh->verts_num;
1510}
1511bool rna_Mesh_vertices_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1512{
1513 Mesh *mesh = rna_mesh(ptr);
1514 if (index < 0 || index >= mesh->verts_num) {
1515 return false;
1516 }
1518 *ptr, RNA_MeshVertex, &mesh->vert_positions_for_write()[index], *r_ptr);
1519 return true;
1520}
1521
1522static void rna_Mesh_edges_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1523{
1524 Mesh *mesh = rna_mesh(ptr);
1525 MutableSpan<int2> edges = mesh->edges_for_write();
1526 rna_iterator_array_begin(iter, ptr, edges.data(), sizeof(int2), edges.size(), false, nullptr);
1527}
1528static int rna_Mesh_edges_length(PointerRNA *ptr)
1529{
1530 const Mesh *mesh = rna_mesh(ptr);
1531 return mesh->edges_num;
1532}
1533bool rna_Mesh_edges_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1534{
1535 Mesh *mesh = rna_mesh(ptr);
1536 if (index < 0 || index >= mesh->edges_num) {
1537 return false;
1538 }
1539 MutableSpan<int2> edges = mesh->edges_for_write();
1540 rna_pointer_create_with_ancestors(*ptr, RNA_MeshEdge, &edges[index], *r_ptr);
1541 return true;
1542}
1543
1544static void rna_Mesh_polygons_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1545{
1546 Mesh *mesh = rna_mesh(ptr);
1548 ptr,
1549 mesh->face_offsets_for_write().data(),
1550 sizeof(int),
1551 mesh->faces_num,
1552 false,
1553 nullptr);
1554}
1555static int rna_Mesh_polygons_length(PointerRNA *ptr)
1556{
1557 const Mesh *mesh = rna_mesh(ptr);
1558 return mesh->faces_num;
1559}
1560bool rna_Mesh_polygons_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1561{
1562 Mesh *mesh = rna_mesh(ptr);
1563 if (index < 0 || index >= mesh->faces_num) {
1564 return false;
1565 }
1567 *ptr, RNA_MeshPolygon, &mesh->face_offsets_for_write()[index], *r_ptr);
1568 return true;
1569}
1570
1571static void rna_Mesh_loops_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1572{
1573 Mesh *mesh = rna_mesh(ptr);
1575 ptr,
1576 mesh->corner_verts_for_write().data(),
1577 sizeof(int),
1578 mesh->corners_num,
1579 false,
1580 nullptr);
1581}
1582static int rna_Mesh_loops_length(PointerRNA *ptr)
1583{
1584 const Mesh *mesh = rna_mesh(ptr);
1585 return mesh->corners_num;
1586}
1587bool rna_Mesh_loops_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1588{
1589 Mesh *mesh = rna_mesh(ptr);
1590 if (index < 0 || index >= mesh->corners_num) {
1591 return false;
1592 }
1594 *ptr, RNA_MeshLoop, &mesh->corner_verts_for_write()[index], *r_ptr);
1595 return true;
1596}
1597
1598static int rna_Mesh_normals_domain_get(PointerRNA *ptr)
1599{
1600 return int(rna_mesh(ptr)->normals_domain());
1601}
1602
1603static void rna_Mesh_vertex_normals_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1604{
1605 const Mesh *mesh = rna_mesh(ptr);
1606 const Span<float3> normals = mesh->vert_normals();
1608 ptr,
1609 const_cast<float3 *>(normals.data()),
1610 sizeof(float3),
1611 normals.size(),
1612 false,
1613 nullptr);
1614}
1615
1616static int rna_Mesh_vertex_normals_length(PointerRNA *ptr)
1617{
1618 const Mesh *mesh = rna_mesh(ptr);
1619 return mesh->verts_num;
1620}
1621
1622bool rna_Mesh_vertex_normals_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1623{
1624 const Mesh *mesh = rna_mesh(ptr);
1625 if (index < 0 || index >= mesh->verts_num) {
1626 return false;
1627 }
1628 /* Casting away const is okay because this RNA type doesn't allow changing the value. */
1630 *ptr, RNA_MeshNormalValue, const_cast<float3 *>(&mesh->vert_normals()[index]), *r_ptr);
1631 return true;
1632}
1633
1634static void rna_Mesh_poly_normals_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1635{
1636 const Mesh *mesh = rna_mesh(ptr);
1637 const Span<float3> normals = mesh->face_normals();
1639 ptr,
1640 const_cast<float3 *>(normals.data()),
1641 sizeof(float3),
1642 normals.size(),
1643 false,
1644 nullptr);
1645}
1646
1647static int rna_Mesh_poly_normals_length(PointerRNA *ptr)
1648{
1649 const Mesh *mesh = rna_mesh(ptr);
1650 return mesh->faces_num;
1651}
1652
1653bool rna_Mesh_poly_normals_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1654{
1655 const Mesh *mesh = rna_mesh(ptr);
1656 if (index < 0 || index >= mesh->faces_num) {
1657 return false;
1658 }
1659 /* Casting away const is okay because this RNA type doesn't allow changing the value. */
1661 *ptr, RNA_MeshNormalValue, const_cast<float3 *>(&mesh->face_normals()[index]), *r_ptr);
1662 return true;
1663}
1664
1665static void rna_Mesh_corner_normals_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1666{
1667 const Mesh *mesh = rna_mesh(ptr);
1668 const Span<float3> normals = mesh->corner_normals();
1669 if (normals.is_empty()) {
1670 iter->valid = false;
1671 return;
1672 }
1674 iter, ptr, (void *)normals.data(), sizeof(float[3]), mesh->corners_num, false, nullptr);
1675}
1676
1677static int rna_Mesh_corner_normals_length(PointerRNA *ptr)
1678{
1679 const Mesh *mesh = rna_mesh(ptr);
1680 return mesh->corners_num;
1681}
1682
1683bool rna_Mesh_corner_normals_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1684{
1685 const Mesh *mesh = rna_mesh(ptr);
1686 const Span<float3> normals = mesh->corner_normals();
1687 if (index < 0 || index >= mesh->corners_num || normals.is_empty()) {
1688 return false;
1689 }
1690 /* Casting away const is okay because this RNA type doesn't allow changing the value. */
1692 *ptr, RNA_MeshNormalValue, const_cast<float3 *>(&normals[index]), *r_ptr);
1693 return true;
1694}
1695
1696static std::optional<std::string> rna_MeshUVLoop_path(const PointerRNA *ptr)
1697{
1698 return rna_LoopCustomData_data_path(ptr, "uv_layers", CD_PROP_FLOAT2);
1699}
1700
1711static std::optional<AttrReverseLookup> find_uv_from_data_ptr(const PointerRNA *ptr)
1712{
1713 return find_attr_from_data_ptr(ptr, ATTR_DOMAIN_MASK_CORNER, CD_MASK_PROP_FLOAT2);
1714}
1715
1716static bool rna_MeshUVLoop_pin_uv_get(PointerRNA *ptr)
1717{
1718 const Mesh *mesh = rna_mesh(ptr);
1719 if (const std::optional<AttrReverseLookup> lookup = find_uv_from_data_ptr(ptr)) {
1720 const VArray<bool> pin_uv = ED_mesh_uv_map_pin_layer_get(mesh, lookup->index_in_group);
1721 return pin_uv[lookup->elem_index];
1722 }
1723 return false;
1724}
1725
1726static void rna_MeshUVLoop_pin_uv_set(PointerRNA *ptr, const bool value)
1727{
1728 Mesh *mesh = rna_mesh(ptr);
1729 if (const std::optional<AttrReverseLookup> lookup = find_uv_from_data_ptr(ptr)) {
1731 lookup->index_in_group);
1732 pin_uv.varray.set(lookup->elem_index, value);
1733 pin_uv.finish();
1734 }
1735}
1736
1737static void rna_MeshUVLoop_uv_get(PointerRNA *ptr, float *value)
1738{
1739 copy_v2_v2(value, static_cast<const float *>(ptr->data));
1740}
1741
1742static void rna_MeshUVLoop_uv_set(PointerRNA *ptr, const float *value)
1743{
1744 copy_v2_v2(static_cast<float *>(ptr->data), value);
1745}
1746
1747static std::optional<std::string> rna_MeshSkinVertexLayer_path(const PointerRNA * /*ptr*/)
1748{
1749 /* Strange name-based path to replicate legacy behavior. */
1750 return "skin_vertices[\"\"]";
1751}
1752
1753static std::optional<int> vert_index_from_skin_data_ptr(const PointerRNA *ptr)
1754{
1755 const Mesh *mesh = rna_mesh(ptr);
1756 const bke::AttributeReader<float2> radius = mesh->attributes().lookup<float2>(
1757 "skin_modifier_radius", bke::AttrDomain::Point);
1758 if (!radius) {
1759 return std::nullopt;
1760 }
1761 if (!radius.varray.is_span()) {
1762 return std::nullopt;
1763 }
1764 const Span<float2> data = radius.varray.get_internal_span();
1765 const int64_t index = static_cast<const float2 *>(ptr->data) - data.data();
1766 if (index < 0 || index >= data.size()) {
1767 return std::nullopt;
1768 }
1769 return int(index);
1770}
1771
1772static std::optional<std::string> rna_MeshSkinVertex_path(const PointerRNA *ptr)
1773{
1774 const std::optional<int> index = vert_index_from_skin_data_ptr(ptr);
1775 if (!index) {
1776 return std::nullopt;
1777 }
1778 return fmt::format("skin_vertices[\"\"].data[{}]", *index);
1779}
1780
1781static void rna_MeshSkinVertex_radius_get(PointerRNA *ptr, float *value)
1782{
1783 copy_v2_v2(value, static_cast<const float *>(ptr->data));
1784}
1785
1786static void rna_MeshSkinVertex_radius_set(PointerRNA *ptr, const float *value)
1787{
1788 copy_v2_v2(static_cast<float *>(ptr->data), value);
1789}
1790
1791static bool rna_MeshSkinVertex_use_root_get(PointerRNA *ptr)
1792{
1793 const Mesh *mesh = rna_mesh(ptr);
1794 if (const std::optional<int> index = vert_index_from_skin_data_ptr(ptr)) {
1795 const VArray<bool> root = *mesh->attributes().lookup_or_default<bool>(
1796 "skin_modifier_root", bke::AttrDomain::Point, false);
1797 return root[*index];
1798 }
1799 return false;
1800}
1801
1802static void rna_MeshSkinVertex_use_root_set(PointerRNA *ptr, const bool value)
1803{
1804 Mesh *mesh = rna_mesh(ptr);
1805 if (const std::optional<int> index = vert_index_from_skin_data_ptr(ptr)) {
1806 bke::AttributeWriter<bool> root = mesh->attributes_for_write().lookup_or_add_for_write<bool>(
1807 "skin_modifier_root", bke::AttrDomain::Point);
1808 root.varray.set(*index, value);
1809 root.finish();
1810 }
1811}
1812
1813static bool rna_MeshSkinVertex_use_loose_get(PointerRNA *ptr)
1814{
1815 const Mesh *mesh = rna_mesh(ptr);
1816 if (const std::optional<int> index = vert_index_from_skin_data_ptr(ptr)) {
1817 const VArray<bool> loose = *mesh->attributes().lookup_or_default<bool>(
1818 "skin_modifier_loose", bke::AttrDomain::Point, false);
1819 return loose[*index];
1820 }
1821 return false;
1822}
1823
1824static void rna_MeshSkinVertex_use_loose_set(PointerRNA *ptr, const bool value)
1825{
1826 Mesh *mesh = rna_mesh(ptr);
1827 if (const std::optional<int> index = vert_index_from_skin_data_ptr(ptr)) {
1828 bke::AttributeWriter<bool> loose = mesh->attributes_for_write().lookup_or_add_for_write<bool>(
1829 "skin_modifier_loose", bke::AttrDomain::Point);
1830 loose.varray.set(*index, value);
1831 loose.finish();
1832 }
1833}
1834
1835static bool rna_MeshSkinVertexLayer_data_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1836{
1838 rna_Attribute_data_begin(&iter, ptr);
1839 if (!iter.valid) {
1840 *r_ptr = {};
1841 return false;
1842 }
1843
1844 ArrayIterator *internal = &iter.internal.array;
1845 if (index < 0 || index >= internal->length) {
1846 *r_ptr = {};
1847 return false;
1848 }
1849
1850 internal->ptr += internal->itemsize * index;
1851
1853 iter.parent, RNA_MeshSkinVertex, rna_iterator_array_get(&iter));
1855 return true;
1856}
1857
1858static std::optional<std::string> rna_MeshLoopColorLayer_path(const PointerRNA *ptr)
1859{
1860 return fmt::format("vertex_colors[\"{}\"]", BLI_str_escape(rna_Attribute_name_get(*ptr)));
1861}
1862
1863static std::optional<std::string> rna_MeshColor_path(const PointerRNA *ptr)
1864{
1865 return rna_LoopCustomData_data_path(ptr, "vertex_colors", CD_PROP_BYTE_COLOR);
1866}
1867
1868/***************************************/
1869
1870static int rna_Mesh_tot_vert_get(PointerRNA *ptr)
1871{
1872 Mesh *mesh = rna_mesh(ptr);
1874 return bm ? bm->totvertsel : 0;
1875}
1876static int rna_Mesh_tot_edge_get(PointerRNA *ptr)
1877{
1878 Mesh *mesh = rna_mesh(ptr);
1880 return bm ? bm->totedgesel : 0;
1881}
1882static int rna_Mesh_tot_face_get(PointerRNA *ptr)
1883{
1884 Mesh *mesh = rna_mesh(ptr);
1886 return bm ? bm->totfacesel : 0;
1887}
1888
1889static PointerRNA rna_Mesh_vertex_color_new(Mesh *mesh,
1890 ReportList *reports,
1891 const char *name,
1892 const bool do_init)
1893{
1894 const std::optional<std::string> new_name = ED_mesh_color_add(
1895 mesh, name, false, do_init, reports);
1896 if (!new_name) {
1897 return {};
1898 }
1899
1900 if (!mesh->active_color_attribute) {
1901 mesh->active_color_attribute = BLI_strdup(new_name->c_str());
1902 }
1903 if (!mesh->default_color_attribute) {
1904 mesh->default_color_attribute = BLI_strdup(new_name->c_str());
1905 }
1906
1908 *new_name,
1911 attr_ptr.type = RNA_MeshLoopColorLayer;
1912 return attr_ptr;
1913}
1914
1915static void rna_Mesh_vertex_color_remove(Mesh *mesh, ReportList *reports, PointerRNA *ptr)
1916{
1918 BKE_attribute_remove(owner, rna_Attribute_name_get(*ptr), reports);
1919}
1920
1921static PointerRNA rna_Mesh_uv_layers_new(Mesh *mesh,
1922 ReportList *reports,
1923 const char *name,
1924 const bool do_init)
1925{
1926 const std::optional<std::string> new_name = ED_mesh_uv_add(mesh, name, false, do_init, reports);
1927 if (!new_name) {
1928 return {};
1929 }
1932 if (mesh->active_uv_map_name().is_empty()) {
1933 mesh->uv_maps_active_set(*new_name);
1934 }
1935 if (mesh->default_uv_map_name().is_empty()) {
1936 mesh->uv_maps_default_set(*new_name);
1937 }
1938 attr_ptr.type = RNA_MeshUVLoopLayer;
1939 return attr_ptr;
1940}
1941
1942static void rna_Mesh_uv_layers_remove(Mesh *mesh, ReportList *reports, PointerRNA *uv_ptr)
1943{
1945 const StringRefNull name = rna_Attribute_name_get(*uv_ptr);
1946 if (mesh->runtime->edit_mesh) {
1947 BMesh &bm = *mesh->runtime->edit_mesh->bm;
1949 BKE_reportf(reports, RPT_ERROR, "UV map '%s' not found", name.c_str());
1950 return;
1951 }
1952 }
1953 else {
1954 bke::AttributeAccessor attributes = *owner.get_accessor();
1955 if (!attributes.contains(name)) {
1956 BKE_reportf(reports, RPT_ERROR, "UV map '%s' not found", name.c_str());
1957 return;
1958 }
1959 }
1960 BKE_attribute_remove(owner, name, reports);
1961}
1962
1963static bool rna_Mesh_is_editmode_get(PointerRNA *ptr)
1964{
1965 Mesh *mesh = rna_mesh(ptr);
1966 return (mesh->runtime->edit_mesh != nullptr);
1967}
1968
1969static bool rna_Mesh_materials_override_apply(Main *bmain,
1970 RNAPropertyOverrideApplyContext &rnaapply_ctx)
1971{
1972 PointerRNA *ptr_dst = &rnaapply_ctx.ptr_dst;
1973 PropertyRNA *prop_dst = rnaapply_ctx.prop_dst;
1974 PointerRNA *ptr_item_dst = &rnaapply_ctx.ptr_item_dst;
1975 PointerRNA *ptr_item_src = &rnaapply_ctx.ptr_item_src;
1976 IDOverrideLibraryPropertyOperation *opop = rnaapply_ctx.liboverride_operation;
1977
1978 BLI_assert_msg(opop->operation == LIBOVERRIDE_OP_REPLACE,
1979 "Unsupported RNA override operation on collections' objects");
1980 UNUSED_VARS_NDEBUG(opop);
1981
1982 Mesh *mesh_dst = id_cast<Mesh *>(ptr_dst->owner_id);
1983
1984 if (!ptr_item_dst->has_type() || !ptr_item_src->has_type()) {
1985 // BLI_assert_msg(0, "invalid source or destination material.");
1986 return false;
1987 }
1988
1989 Material *mat_dst = static_cast<Material *>(ptr_item_dst->data);
1990 Material *mat_src = static_cast<Material *>(ptr_item_src->data);
1991
1992 if (mat_src == mat_dst) {
1993 return true;
1994 }
1995
1996 bool is_modified = false;
1997 for (int i = 0; i < mesh_dst->totcol; i++) {
1998 if (mesh_dst->mat[i] == mat_dst) {
1999 id_us_min(&mat_dst->id);
2000 mesh_dst->mat[i] = mat_src;
2001 id_us_plus(&mat_src->id);
2002 is_modified = true;
2003 }
2004 }
2005
2006 if (is_modified) {
2007 RNA_property_update_main(bmain, nullptr, ptr_dst, prop_dst);
2008 }
2009
2010 return true;
2011}
2012
2014
2015} // namespace blender
2016
2017#else
2018
2019namespace blender {
2020
2021/* -------------------------------------------------------------------- */
2024
2026{
2027 StructRNA *srna;
2028 PropertyRNA *prop;
2029
2030 srna = RNA_def_struct(brna, "VertexGroupElement", nullptr);
2031 RNA_def_struct_sdna(srna, "MDeformWeight");
2032 RNA_def_struct_path_func(srna, "rna_VertexGroupElement_path");
2034 srna, "Vertex Group Element", "Weight value of a vertex in a vertex group");
2035 RNA_def_struct_ui_icon(srna, ICON_GROUP_VERTEX);
2036
2037 /* we can't point to actual group, it is in the object and so
2038 * there is no unique group to point to, hence the index */
2039 prop = RNA_def_property(srna, "group", PROP_INT, PROP_UNSIGNED);
2040 RNA_def_property_int_sdna(prop, nullptr, "def_nr");
2042 RNA_def_property_ui_text(prop, "Group Index", "");
2043 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2044
2045 prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_NONE);
2046 RNA_def_property_range(prop, 0.0f, 1.0f);
2047 RNA_def_property_ui_text(prop, "Weight", "Vertex Weight");
2048 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_weight");
2049}
2050
2051static void rna_def_mvert(BlenderRNA *brna)
2052{
2053 StructRNA *srna;
2054 PropertyRNA *prop;
2055
2056 srna = RNA_def_struct(brna, "MeshVertex", nullptr);
2057 RNA_def_struct_ui_text(srna, "Mesh Vertex", "Vertex in a Mesh data-block");
2058 RNA_def_struct_path_func(srna, "rna_MeshVertex_path");
2059 RNA_def_struct_ui_icon(srna, ICON_VERTEXSEL);
2060
2061 prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
2062 RNA_def_property_array(prop, 3);
2063 RNA_def_property_float_funcs(prop, "rna_MeshVertex_co_get", "rna_MeshVertex_co_set", nullptr);
2064 RNA_def_property_ui_text(prop, "Position", "");
2065 RNA_def_property_update(prop, 0, "rna_Mesh_update_positions_tag");
2066
2067 prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
2068 RNA_def_property_array(prop, 3);
2070 RNA_def_property_float_funcs(prop, "rna_MeshVertex_normal_get", nullptr, nullptr);
2071 RNA_def_property_ui_text(prop, "Normal", "Vertex Normal");
2072
2073 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
2074 RNA_def_property_boolean_funcs(prop, "rna_MeshVertex_select_get", "rna_MeshVertex_select_set");
2076 RNA_def_property_ui_text(prop, "Select", "");
2077 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
2078
2079 prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
2081 RNA_def_property_ui_text(prop, "Hide", "");
2082 RNA_def_property_boolean_funcs(prop, "rna_MeshVertex_hide_get", "rna_MeshVertex_hide_set");
2083 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
2084
2085 prop = RNA_def_property(srna, "groups", PROP_COLLECTION, PROP_NONE);
2087 "rna_MeshVertex_groups_begin",
2088 "rna_iterator_array_next",
2089 "rna_iterator_array_end",
2090 "rna_iterator_array_get",
2091 nullptr,
2092 nullptr,
2093 nullptr,
2094 nullptr);
2095 RNA_def_property_struct_type(prop, "VertexGroupElement");
2097 prop, "Groups", "Weights for the vertex groups this vertex is member of");
2098
2099 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
2101 RNA_def_property_int_funcs(prop, "rna_MeshVertex_index_get", nullptr, nullptr);
2102 RNA_def_property_ui_text(prop, "Index", "Index of this vertex");
2103
2104 prop = RNA_def_property(srna, "undeformed_co", PROP_FLOAT, PROP_TRANSLATION);
2105 RNA_def_property_array(prop, 3);
2107 prop,
2108 "Undeformed Location",
2109 "For meshes with modifiers applied, the coordinate of the vertex with no deforming "
2110 "modifiers applied, as used for generated texture coordinates");
2111 RNA_def_property_float_funcs(prop, "rna_MeshVertex_undeformed_co_get", nullptr, nullptr);
2113}
2114
2115static void rna_def_medge(BlenderRNA *brna)
2116{
2117 StructRNA *srna;
2118 PropertyRNA *prop;
2119
2120 srna = RNA_def_struct(brna, "MeshEdge", nullptr);
2121 RNA_def_struct_sdna(srna, "vec2i");
2122 RNA_def_struct_ui_text(srna, "Mesh Edge", "Edge in a Mesh data-block");
2123 RNA_def_struct_path_func(srna, "rna_MeshEdge_path");
2124 RNA_def_struct_ui_icon(srna, ICON_EDGESEL);
2125
2126 prop = RNA_def_property(srna, "vertices", PROP_INT, PROP_UNSIGNED);
2127 RNA_def_property_int_sdna(prop, nullptr, "x");
2128 RNA_def_property_array(prop, 2);
2130 RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");
2131 /* XXX allows creating invalid meshes */
2132
2133 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
2134 RNA_def_property_boolean_funcs(prop, "rna_MeshEdge_select_get", "rna_MeshEdge_select_set");
2136 RNA_def_property_ui_text(prop, "Select", "");
2137 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
2138
2139 prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
2141 RNA_def_property_ui_text(prop, "Hide", "");
2142 RNA_def_property_boolean_funcs(prop, "rna_MeshEdge_hide_get", "rna_MeshEdge_hide_set");
2143 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
2144
2145 prop = RNA_def_property(srna, "use_seam", PROP_BOOLEAN, PROP_NONE);
2146 RNA_def_property_boolean_funcs(prop, "rna_MeshEdge_use_seam_get", "rna_MeshEdge_use_seam_set");
2147 RNA_def_property_ui_text(prop, "Seam", "Seam edge for UV unwrapping");
2148 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
2149
2150 prop = RNA_def_property(srna, "use_edge_sharp", PROP_BOOLEAN, PROP_NONE);
2152 prop, "rna_MeshEdge_use_edge_sharp_get", "rna_MeshEdge_use_edge_sharp_set");
2153 RNA_def_property_ui_text(prop, "Sharp", "Sharp edge for shading");
2154 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2155
2156 prop = RNA_def_property(srna, "is_loose", PROP_BOOLEAN, PROP_NONE);
2158 RNA_def_property_boolean_funcs(prop, "rna_MeshEdge_is_loose_get", nullptr);
2159 RNA_def_property_ui_text(prop, "Loose", "Edge is not connected to any faces");
2160
2161 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
2163 RNA_def_property_int_funcs(prop, "rna_MeshEdge_index_get", nullptr, nullptr);
2164 RNA_def_property_ui_text(prop, "Index", "Index of this edge");
2165}
2166
2168{
2169 StructRNA *srna;
2170 PropertyRNA *prop;
2171 const int splitnor_dim[] = {3, 3};
2172
2173 srna = RNA_def_struct(brna, "MeshLoopTriangle", nullptr);
2174 RNA_def_struct_sdna(srna, "vec3i");
2175 RNA_def_struct_ui_text(srna, "Mesh Loop Triangle", "Tessellated triangle in a Mesh data-block");
2176 RNA_def_struct_path_func(srna, "rna_MeshLoopTriangle_path");
2177 RNA_def_struct_ui_icon(srna, ICON_FACESEL);
2178
2179 prop = RNA_def_property(srna, "vertices", PROP_INT, PROP_UNSIGNED);
2180 RNA_def_property_array(prop, 3);
2181 RNA_def_property_int_funcs(prop, "rna_MeshLoopTriangle_verts_get", nullptr, nullptr);
2182 RNA_def_property_ui_text(prop, "Vertices", "Indices of triangle vertices");
2184
2185 prop = RNA_def_property(srna, "loops", PROP_INT, PROP_UNSIGNED);
2186 RNA_def_property_int_sdna(prop, nullptr, "x");
2187 RNA_def_property_array(prop, 3);
2188 RNA_def_property_ui_text(prop, "Loops", "Indices of mesh loops that make up the triangle");
2190
2191 prop = RNA_def_property(srna, "polygon_index", PROP_INT, PROP_UNSIGNED);
2192 RNA_def_property_int_funcs(prop, "rna_MeshLoopTriangle_polygon_index_get", nullptr, nullptr);
2193 RNA_def_property_ui_text(prop, "Polygon", "Index of mesh face that the triangle is a part of");
2195
2196 prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
2197 RNA_def_property_array(prop, 3);
2198 RNA_def_property_range(prop, -1.0f, 1.0f);
2200 RNA_def_property_float_funcs(prop, "rna_MeshLoopTriangle_normal_get", nullptr, nullptr);
2202 prop, "Triangle Normal", "Local space unit length normal vector for this triangle");
2203
2204 prop = RNA_def_property(srna, "split_normals", PROP_FLOAT, PROP_DIRECTION);
2205 RNA_def_property_multi_array(prop, 2, splitnor_dim);
2206 RNA_def_property_range(prop, -1.0f, 1.0f);
2208 RNA_def_property_float_funcs(prop, "rna_MeshLoopTriangle_split_normals_get", nullptr, nullptr);
2210 prop,
2211 "Custom Normals",
2212 "Local space unit length custom normal vectors of the face corners of this triangle");
2213
2214 prop = RNA_def_property(srna, "area", PROP_FLOAT, PROP_UNSIGNED);
2216 RNA_def_property_float_funcs(prop, "rna_MeshLoopTriangle_area_get", nullptr, nullptr);
2217 RNA_def_property_ui_text(prop, "Triangle Area", "Area of this triangle");
2218
2219 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
2221 RNA_def_property_int_funcs(prop, "rna_MeshLoopTriangle_index_get", nullptr, nullptr);
2222 RNA_def_property_ui_text(prop, "Index", "Index of this loop triangle");
2223
2224 prop = RNA_def_property(srna, "material_index", PROP_INT, PROP_UNSIGNED);
2226 RNA_def_property_int_funcs(prop, "rna_MeshLoopTriangle_material_index_get", nullptr, nullptr);
2227 RNA_def_property_ui_text(prop, "Material Index", "Material slot index of this triangle");
2228
2229 prop = RNA_def_property(srna, "use_smooth", PROP_BOOLEAN, PROP_NONE);
2231 RNA_def_property_boolean_funcs(prop, "rna_MeshLoopTriangle_use_smooth_get", nullptr);
2232 RNA_def_property_ui_text(prop, "Smooth", "");
2233}
2234
2235static void rna_def_mloop(BlenderRNA *brna)
2236{
2237 StructRNA *srna;
2238 PropertyRNA *prop;
2239
2240 srna = RNA_def_struct(brna, "MeshLoop", nullptr);
2241 RNA_def_struct_ui_text(srna, "Mesh Loop", "Loop in a Mesh data-block");
2242 RNA_def_struct_path_func(srna, "rna_MeshLoop_path");
2243 RNA_def_struct_ui_icon(srna, ICON_EDGESEL);
2244
2245 prop = RNA_def_property(srna, "vertex_index", PROP_INT, PROP_UNSIGNED);
2247 prop, "rna_MeshLoop_vertex_index_get", "rna_MeshLoop_vertex_index_set", nullptr);
2249 RNA_def_property_ui_text(prop, "Vertex", "Vertex index");
2250
2251 prop = RNA_def_property(srna, "edge_index", PROP_INT, PROP_UNSIGNED);
2253 prop, "rna_MeshLoop_edge_index_get", "rna_MeshLoop_edge_index_set", nullptr);
2255 RNA_def_property_ui_text(prop, "Edge", "Edge index");
2256
2257 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
2259 RNA_def_property_int_funcs(prop, "rna_MeshLoop_index_get", nullptr, nullptr);
2260 RNA_def_property_ui_text(prop, "Index", "Index of this loop");
2261
2262 prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
2264 RNA_def_property_array(prop, 3);
2265 RNA_def_property_range(prop, -1.0f, 1.0f);
2266 RNA_def_property_float_funcs(prop, "rna_MeshLoop_normal_get", nullptr, nullptr);
2268 "Normal",
2269 "The normal direction of the face corner, taking into account sharp "
2270 "faces, sharp edges, and custom normal data");
2271
2272 prop = RNA_def_property(srna, "tangent", PROP_FLOAT, PROP_DIRECTION);
2273 RNA_def_property_array(prop, 3);
2274 RNA_def_property_range(prop, -1.0f, 1.0f);
2276 RNA_def_property_float_funcs(prop, "rna_MeshLoop_tangent_get", nullptr, nullptr);
2278 "Tangent",
2279 "Local space unit length tangent vector of this vertex for this face "
2280 "(must be computed beforehand using calc_tangents)");
2281
2282 prop = RNA_def_property(srna, "bitangent_sign", PROP_FLOAT, PROP_NONE);
2283 RNA_def_property_range(prop, -1.0f, 1.0f);
2285 RNA_def_property_float_funcs(prop, "rna_MeshLoop_bitangent_sign_get", nullptr, nullptr);
2287 prop,
2288 "Bitangent Sign",
2289 "Sign of the bitangent vector of this vertex for this face (must be computed "
2290 "beforehand using calc_tangents, bitangent = bitangent_sign * cross(normal, tangent))");
2291
2292 prop = RNA_def_property(srna, "bitangent", PROP_FLOAT, PROP_DIRECTION);
2293 RNA_def_property_array(prop, 3);
2294 RNA_def_property_range(prop, -1.0f, 1.0f);
2296 RNA_def_property_float_funcs(prop, "rna_MeshLoop_bitangent_get", nullptr, nullptr);
2298 prop,
2299 "Bitangent",
2300 "Bitangent vector of this vertex for this face (must be computed beforehand using "
2301 "calc_tangents, use it only if really needed, slower access than bitangent_sign)");
2302}
2303
2305{
2306 StructRNA *srna;
2307 PropertyRNA *prop;
2308 FunctionRNA *func;
2309
2310 srna = RNA_def_struct(brna, "MeshPolygon", nullptr);
2311 RNA_def_struct_sdna(srna, "MIntProperty");
2312 RNA_def_struct_ui_text(srna, "Mesh Polygon", "Polygon in a Mesh data-block");
2313 RNA_def_struct_path_func(srna, "rna_MeshPolygon_path");
2314 RNA_def_struct_ui_icon(srna, ICON_FACESEL);
2315
2316 /* Faked, actually access to loop vertex values, don't this way because manually setting up
2317 * vertex/edge per loop is very low level.
2318 * Instead we setup face sizes, assign indices, then calc edges automatic when creating
2319 * meshes from rna/py. */
2320 prop = RNA_def_property(srna, "vertices", PROP_INT, PROP_UNSIGNED);
2321 /* Eek, this is still used in some cases but in fact we don't want to use it at all here. */
2322 RNA_def_property_array(prop, 3);
2324 RNA_def_property_dynamic_array_funcs(prop, "rna_MeshPoly_vertices_get_length");
2326 prop, "rna_MeshPoly_vertices_get", "rna_MeshPoly_vertices_set", nullptr);
2328 RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");
2329
2330 /* these are both very low level access */
2331 prop = RNA_def_property(srna, "loop_start", PROP_INT, PROP_UNSIGNED);
2332 RNA_def_property_int_sdna(prop, nullptr, "i");
2334 RNA_def_property_ui_text(prop, "Loop Start", "Index of the first loop of this face");
2335 /* also low level */
2336 prop = RNA_def_property(srna, "loop_total", PROP_INT, PROP_UNSIGNED);
2338 RNA_def_property_int_funcs(prop, "rna_MeshPolygon_loop_total_get", nullptr, nullptr);
2339 RNA_def_property_ui_text(prop, "Loop Total", "Number of loops used by this face");
2340
2341 prop = RNA_def_property(srna, "material_index", PROP_INT, PROP_UNSIGNED);
2343 prop, "rna_MeshPolygon_material_index_get", "rna_MeshPolygon_material_index_set", nullptr);
2344 RNA_def_property_ui_text(prop, "Material Index", "Material slot index of this face");
2345# if 0
2346 RNA_def_property_int_funcs(prop, nullptr, nullptr, "rna_MeshPoly_material_index_range");
2347# endif
2348 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2349
2350 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
2351 RNA_def_property_boolean_funcs(prop, "rna_MeshPolygon_select_get", "rna_MeshPolygon_select_set");
2353 RNA_def_property_ui_text(prop, "Select", "");
2354 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
2355
2356 prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
2358 RNA_def_property_ui_text(prop, "Hide", "");
2359 RNA_def_property_boolean_funcs(prop, "rna_MeshPolygon_hide_get", "rna_MeshPolygon_hide_set");
2360 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
2361
2362 prop = RNA_def_property(srna, "use_smooth", PROP_BOOLEAN, PROP_NONE);
2364 prop, "rna_MeshPolygon_use_smooth_get", "rna_MeshPolygon_use_smooth_set");
2365 RNA_def_property_ui_text(prop, "Smooth", "");
2366 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2367
2368 prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
2369 RNA_def_property_array(prop, 3);
2370 RNA_def_property_range(prop, -1.0f, 1.0f);
2372 RNA_def_property_float_funcs(prop, "rna_MeshPolygon_normal_get", nullptr, nullptr);
2374 prop, "Polygon Normal", "Local space unit length normal vector for this face");
2375
2376 prop = RNA_def_property(srna, "center", PROP_FLOAT, PROP_XYZ);
2377 RNA_def_property_array(prop, 3);
2379 RNA_def_property_float_funcs(prop, "rna_MeshPolygon_center_get", nullptr, nullptr);
2380 RNA_def_property_ui_text(prop, "Polygon Center", "Center of this face");
2381
2382 prop = RNA_def_property(srna, "area", PROP_FLOAT, PROP_UNSIGNED);
2384 RNA_def_property_float_funcs(prop, "rna_MeshPolygon_area_get", nullptr, nullptr);
2385 RNA_def_property_ui_text(prop, "Polygon Area", "Read only area of this face");
2386
2387 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
2389 RNA_def_property_int_funcs(prop, "rna_MeshPolygon_index_get", nullptr, nullptr);
2390 RNA_def_property_ui_text(prop, "Index", "Index of this face");
2391
2392 func = RNA_def_function(srna, "flip", "rna_MeshPolygon_flip");
2394 RNA_def_function_ui_description(func, "Invert winding of this face (flip its normal)");
2395}
2396
2397/* mesh.loop_uvs */
2398static void rna_def_mloopuv(BlenderRNA *brna)
2399{
2400 FunctionRNA *func;
2401 StructRNA *srna;
2402 PropertyRNA *prop, *parm;
2403
2404 srna = RNA_def_struct(brna, "MeshUVLoopLayer", nullptr);
2405 RNA_def_struct_path_func(srna, "rna_MeshUVLoopLayer_path");
2406
2407 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
2408 RNA_def_property_struct_type(prop, "MeshUVLoop");
2410 prop,
2411 "MeshUVLoop (Deprecated)",
2412 "Deprecated, use 'uv', 'vertex_select', 'edge_select' or 'pin' properties instead");
2415 "rna_Attribute_data_begin",
2416 "rna_iterator_array_next",
2417 "rna_iterator_array_end",
2418 "rna_iterator_array_get",
2419 "rna_Attribute_data_length",
2420 "rna_MeshUVLoopLayer_data_lookup_int",
2421 nullptr,
2422 nullptr);
2423
2424 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2425 RNA_def_struct_name_property(srna, prop);
2427 prop, "rna_Attribute_name_get", "rna_Attribute_name_length", "rna_Attribute_name_set");
2429 RNA_def_property_ui_text(prop, "Name", "Name of UV map");
2430 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2431
2432 prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
2434 prop, "rna_MeshUVLoopLayer_active_get", "rna_MeshUVLoopLayer_active_set");
2436 RNA_def_property_ui_text(prop, "Active", "Set the map as active for display and editing");
2437 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2438
2439 prop = RNA_def_property(srna, "active_render", PROP_BOOLEAN, PROP_NONE);
2441 prop, "rna_MeshUVLoopLayer_active_render_get", "rna_MeshUVLoopLayer_active_render_set");
2443 RNA_def_property_ui_text(prop, "Active Render", "Set the UV map as active for rendering");
2444 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2445
2446 prop = RNA_def_property(srna, "active_clone", PROP_BOOLEAN, PROP_NONE);
2448 prop, "rna_MeshUVLoopLayer_clone_get", "rna_MeshUVLoopLayer_clone_set");
2450 RNA_def_property_ui_text(prop, "Active Clone", "Set the map as active for cloning");
2451 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2452
2453 prop = RNA_def_property(srna, "uv", PROP_COLLECTION, PROP_NONE);
2454 RNA_def_property_struct_type(prop, "Float2AttributeValue");
2455 RNA_def_property_ui_text(prop, "UV", "UV coordinates on face corners");
2458 "rna_Attribute_data_begin",
2459 "rna_iterator_array_next",
2460 "rna_iterator_array_end",
2461 "rna_iterator_array_get",
2462 "rna_Attribute_data_length",
2463 "rna_Attribute_data_lookup_int",
2464 nullptr,
2465 nullptr);
2466
2467 prop = RNA_def_property(srna, "pin", PROP_COLLECTION, PROP_NONE);
2468 RNA_def_property_struct_type(prop, "BoolAttributeValue");
2470 RNA_def_property_ui_text(prop, "UV Pin", "UV pinned state in the UV editor");
2473 "rna_MeshUVLoopLayer_pin_begin",
2474 "rna_iterator_array_next",
2475 "rna_iterator_array_end",
2476 "rna_iterator_array_get",
2477 "rna_MeshUVLoopLayer_pin_length",
2478 "rna_Attribute_data_lookup_int",
2479 nullptr,
2480 nullptr);
2481
2482 func = RNA_def_function(srna, "pin_ensure", "rna_MeshUVLoopLayer_pin_ensure");
2484 parm = RNA_def_pointer(func, "layer", "BoolAttribute", "", "The boolean attribute");
2486 RNA_def_function_return(func, parm);
2487
2488 srna = RNA_def_struct(brna, "MeshUVLoop", nullptr);
2490 srna, "Mesh UV Layer", "(Deprecated) Layer of UV coordinates in a Mesh data-block");
2491 RNA_def_struct_path_func(srna, "rna_MeshUVLoop_path");
2492
2493 prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_XYZ);
2494 RNA_def_property_array(prop, 2);
2495 RNA_def_property_float_funcs(prop, "rna_MeshUVLoop_uv_get", "rna_MeshUVLoop_uv_set", nullptr);
2496 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2497
2498 prop = RNA_def_property(srna, "pin_uv", PROP_BOOLEAN, PROP_NONE);
2499 RNA_def_property_boolean_funcs(prop, "rna_MeshUVLoop_pin_uv_get", "rna_MeshUVLoop_pin_uv_set");
2501 RNA_def_property_ui_text(prop, "UV Pinned", "");
2502}
2503
2505{
2506 StructRNA *srna;
2507 PropertyRNA *prop;
2508
2509 srna = RNA_def_struct(brna, "MeshLoopColorLayer", nullptr);
2511 srna, "Mesh Vertex Color Layer", "Layer of vertex colors in a Mesh data-block");
2512 RNA_def_struct_path_func(srna, "rna_MeshLoopColorLayer_path");
2513 RNA_def_struct_ui_icon(srna, ICON_GROUP_VCOL);
2514
2515 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2516 RNA_def_struct_name_property(srna, prop);
2518 prop, "rna_Attribute_name_get", "rna_Attribute_name_length", "rna_Attribute_name_set");
2520 RNA_def_property_ui_text(prop, "Name", "Name of Vertex color layer");
2521 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2522
2523 prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
2524 RNA_def_property_boolean_funcs(prop, "rna_mesh_color_active_get", "rna_mesh_color_active_set");
2526 RNA_def_property_ui_text(prop, "Active", "Sets the layer as active for display and editing");
2527 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2528
2529 prop = RNA_def_property(srna, "active_render", PROP_BOOLEAN, PROP_NONE);
2531 prop, "rna_mesh_color_active_render_get", "rna_mesh_color_active_render_set");
2533 RNA_def_property_ui_text(prop, "Active Render", "Sets the layer as active for rendering");
2534 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2535
2536 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
2537 RNA_def_property_struct_type(prop, "MeshLoopColor");
2538 RNA_def_property_ui_text(prop, "Data", "");
2541 "rna_Attribute_data_begin",
2542 "rna_iterator_array_next",
2543 "rna_iterator_array_end",
2544 "rna_iterator_array_get",
2545 "rna_Attribute_data_length",
2546 nullptr,
2547 nullptr,
2548 nullptr);
2549
2550 srna = RNA_def_struct(brna, "MeshLoopColor", nullptr);
2551 RNA_def_struct_sdna(srna, "MLoopCol");
2552 RNA_def_struct_ui_text(srna, "Mesh Vertex Color", "Vertex loop colors in a Mesh");
2553 RNA_def_struct_path_func(srna, "rna_MeshColor_path");
2554
2555 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
2556 RNA_def_property_array(prop, 4);
2557 RNA_def_property_range(prop, 0.0f, 1.0f);
2559 prop, "rna_MeshLoopColor_color_get", "rna_MeshLoopColor_color_set", nullptr);
2560 RNA_def_property_ui_text(prop, "Color", "Color in sRGB color space");
2561 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2562}
2563
2564void rna_def_texmat_common(StructRNA *srna, const char *texspace_editable)
2565{
2566 PropertyRNA *prop;
2567
2568 /* texture space */
2569 prop = RNA_def_property(srna, "auto_texspace", PROP_BOOLEAN, PROP_NONE);
2570 RNA_def_property_boolean_sdna(prop, nullptr, "texspace_flag", ME_TEXSPACE_FLAG_AUTO);
2572 prop,
2573 "Auto Texture Space",
2574 "Adjust active object's texture space automatically when transforming object");
2575
2576 prop = RNA_def_property(srna, "texspace_location", PROP_FLOAT, PROP_TRANSLATION);
2577 RNA_def_property_float_sdna(prop, nullptr, "texspace_location");
2578 RNA_def_property_ui_text(prop, "Texture Space Location", "Texture space location");
2579 RNA_def_property_float_funcs(prop, "rna_Mesh_texspace_location_get", nullptr, nullptr);
2580 RNA_def_property_editable_func(prop, texspace_editable);
2581 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2582
2583 prop = RNA_def_property(srna, "texspace_size", PROP_FLOAT, PROP_XYZ);
2584 RNA_def_property_float_sdna(prop, nullptr, "texspace_size");
2586 RNA_def_property_ui_text(prop, "Texture Space Size", "Texture space size");
2587 RNA_def_property_float_funcs(prop, "rna_Mesh_texspace_size_get", nullptr, nullptr);
2588 RNA_def_property_editable_func(prop, texspace_editable);
2589 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2590
2591 /* materials */
2592 prop = RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
2593 RNA_def_property_collection_sdna(prop, nullptr, "mat", "totcol");
2594 RNA_def_property_struct_type(prop, "Material");
2595 RNA_def_property_ui_text(prop, "Materials", "");
2596 RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.cc */
2598 RNA_def_property_override_funcs(prop, nullptr, nullptr, "rna_Mesh_materials_override_apply");
2600 nullptr,
2601 nullptr,
2602 nullptr,
2603 nullptr,
2604 nullptr,
2605 nullptr,
2606 nullptr,
2607 "rna_IDMaterials_assign_int");
2608}
2609
2610/* scene.objects */
2611/* mesh.vertices */
2613{
2614 StructRNA *srna;
2615 // PropertyRNA *prop;
2616
2617 FunctionRNA *func;
2618 PropertyRNA *parm;
2619
2620 RNA_def_property_srna(cprop, "MeshVertices");
2621 srna = RNA_def_struct(brna, "MeshVertices", nullptr);
2622 RNA_def_struct_sdna(srna, "Mesh");
2623 RNA_def_struct_ui_text(srna, "Mesh Vertices", "Collection of mesh vertices");
2624
2625 func = RNA_def_function(srna, "add", "ED_mesh_verts_add");
2627 parm = RNA_def_int(
2628 func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
2630# if 0 /* BMESH_TODO Remove until BMesh merge */
2631 func = RNA_def_function(srna, "remove", "ED_mesh_verts_remove");
2633 RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to remove", 0, INT_MAX);
2634# endif
2635}
2636
2637/* mesh.edges */
2639{
2640 StructRNA *srna;
2641 // PropertyRNA *prop;
2642
2643 FunctionRNA *func;
2644 PropertyRNA *parm;
2645
2646 RNA_def_property_srna(cprop, "MeshEdges");
2647 srna = RNA_def_struct(brna, "MeshEdges", nullptr);
2648 RNA_def_struct_sdna(srna, "Mesh");
2649 RNA_def_struct_ui_text(srna, "Mesh Edges", "Collection of mesh edges");
2650
2651 func = RNA_def_function(srna, "add", "ED_mesh_edges_add");
2653 parm = RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of edges to add", 0, INT_MAX);
2655# if 0 /* BMESH_TODO Remove until BMesh merge */
2656 func = RNA_def_function(srna, "remove", "ED_mesh_edges_remove");
2658 RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of edges to remove", 0, INT_MAX);
2659# endif
2660}
2661
2662/* mesh.loop_triangles */
2664{
2665 StructRNA *srna;
2666
2667 RNA_def_property_srna(cprop, "MeshLoopTriangles");
2668 srna = RNA_def_struct(brna, "MeshLoopTriangles", nullptr);
2669 RNA_def_struct_sdna(srna, "Mesh");
2671 srna, "Mesh Loop Triangles", "Tessellation of mesh polygons into triangles");
2672}
2673
2674/* mesh.loops */
2676{
2677 StructRNA *srna;
2678
2679 // PropertyRNA *prop;
2680
2681 FunctionRNA *func;
2682 PropertyRNA *parm;
2683
2684 RNA_def_property_srna(cprop, "MeshLoops");
2685 srna = RNA_def_struct(brna, "MeshLoops", nullptr);
2686 RNA_def_struct_sdna(srna, "Mesh");
2687 RNA_def_struct_ui_text(srna, "Mesh Loops", "Collection of mesh loops");
2688
2689 func = RNA_def_function(srna, "add", "ED_mesh_loops_add");
2691 parm = RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of loops to add", 0, INT_MAX);
2693}
2694
2695/* mesh.polygons */
2697{
2698 StructRNA *srna;
2699
2700 PropertyRNA *prop;
2701
2702 FunctionRNA *func;
2703 PropertyRNA *parm;
2704
2705 RNA_def_property_srna(cprop, "MeshPolygons");
2706 srna = RNA_def_struct(brna, "MeshPolygons", nullptr);
2707 RNA_def_struct_sdna(srna, "Mesh");
2708 RNA_def_struct_ui_text(srna, "Mesh Polygons", "Collection of mesh polygons");
2709
2710 prop = RNA_def_property(srna, "active", PROP_INT, PROP_NONE);
2711 RNA_def_property_int_sdna(prop, nullptr, "act_face");
2713 RNA_def_property_ui_text(prop, "Active Polygon", "The active face for this mesh");
2714
2715 func = RNA_def_function(srna, "add", "ED_mesh_faces_add");
2717 parm = RNA_def_int(
2718 func, "count", 0, 0, INT_MAX, "Count", "Number of polygons to add", 0, INT_MAX);
2720}
2721
2722/* Defines a read-only vector type since normals can not be modified manually. */
2724{
2725 StructRNA *srna = RNA_def_struct(brna, "MeshNormalValue", nullptr);
2726 RNA_def_struct_sdna(srna, "vec3f");
2727 RNA_def_struct_ui_text(srna, "Mesh Normal Vector", "Vector in a mesh normal array");
2728
2729 PropertyRNA *prop = RNA_def_property(srna, "vector", PROP_FLOAT, PROP_DIRECTION);
2730 RNA_def_property_ui_text(prop, "Vector", "3D vector");
2731 RNA_def_property_float_sdna(prop, nullptr, "x");
2732 RNA_def_property_array(prop, 3);
2734}
2735
2737{
2738 StructRNA *srna;
2739 PropertyRNA *prop;
2740
2741 FunctionRNA *func;
2742 PropertyRNA *parm;
2743
2744 RNA_def_property_srna(cprop, "LoopColors");
2745 srna = RNA_def_struct(brna, "LoopColors", nullptr);
2746 RNA_def_struct_sdna(srna, "Mesh");
2747 RNA_def_struct_ui_text(srna, "Loop Colors", "Collection of vertex colors");
2748
2749 func = RNA_def_function(srna, "new", "rna_Mesh_vertex_color_new");
2750 RNA_def_function_ui_description(func, "Add a vertex color layer to Mesh");
2752 RNA_def_string(func, "name", "Col", 0, "", "Vertex color name");
2753 RNA_def_boolean(func,
2754 "do_init",
2755 true,
2756 "",
2757 "Whether new layer's data should be initialized by copying current active one");
2758 parm = RNA_def_pointer(func, "layer", "MeshLoopColorLayer", "", "The newly created layer");
2760 RNA_def_function_return(func, parm);
2761
2762 func = RNA_def_function(srna, "remove", "rna_Mesh_vertex_color_remove");
2763 RNA_def_function_ui_description(func, "Remove a vertex color layer");
2765 parm = RNA_def_pointer(func, "layer", "MeshLoopColorLayer", "", "The layer to remove");
2768
2769 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2770 RNA_def_property_struct_type(prop, "MeshLoopColorLayer");
2772 "rna_Mesh_vertex_color_active_get",
2773 "rna_Mesh_vertex_color_active_set",
2774 nullptr,
2775 nullptr);
2777 RNA_def_property_ui_text(prop, "Active Vertex Color Layer", "Active vertex color layer");
2778 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_active_color");
2779
2780 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
2782 "rna_Mesh_vertex_color_active_index_get",
2783 "rna_Mesh_vertex_color_active_index_set",
2784 "rna_Mesh_vertex_color_index_range");
2786 RNA_def_property_ui_text(prop, "Active Vertex Color Index", "Active vertex color index");
2787 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_active_color");
2788}
2789
2790static void rna_def_uv_layers(BlenderRNA *brna, PropertyRNA *cprop)
2791{
2792 StructRNA *srna;
2793 PropertyRNA *prop;
2794
2795 FunctionRNA *func;
2796 PropertyRNA *parm;
2797
2798 RNA_def_property_srna(cprop, "UVLoopLayers");
2799 srna = RNA_def_struct(brna, "UVLoopLayers", nullptr);
2800 RNA_def_struct_sdna(srna, "Mesh");
2801 RNA_def_struct_ui_text(srna, "UV Map Layers", "Collection of UV map layers");
2802
2803 func = RNA_def_function(srna, "new", "rna_Mesh_uv_layers_new");
2805 RNA_def_function_ui_description(func, "Add a UV map layer to Mesh");
2806 RNA_def_string(func, "name", "UVMap", 0, "", "UV map name");
2807 RNA_def_boolean(func,
2808 "do_init",
2809 true,
2810 "",
2811 "Whether new layer's data should be initialized by copying current active one, "
2812 "or if none is active, with a default UVmap");
2813 parm = RNA_def_pointer(func, "layer", "MeshUVLoopLayer", "", "The newly created layer");
2815 RNA_def_function_return(func, parm);
2816
2817 func = RNA_def_function(srna, "remove", "rna_Mesh_uv_layers_remove");
2818 RNA_def_function_ui_description(func, "Remove a UV map layer");
2820 parm = RNA_def_pointer(func, "layer", "MeshUVLoopLayer", "", "The layer to remove");
2822
2823 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2824 RNA_def_property_struct_type(prop, "MeshUVLoopLayer");
2826 prop, "rna_Mesh_uv_layer_active_get", "rna_Mesh_uv_layer_active_set", nullptr, nullptr);
2829 RNA_def_property_ui_text(prop, "Active UV Map Layer", "Active UV Map layer");
2830 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2831
2832 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
2834 "rna_Mesh_uv_layer_active_index_get",
2835 "rna_Mesh_uv_layer_active_index_set",
2836 "rna_Mesh_uv_layer_index_range");
2838 RNA_def_property_ui_text(prop, "Active UV Map Index", "Active UV map index");
2839 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2840
2841 prop = RNA_def_property(srna, "active_render", PROP_POINTER, PROP_NONE);
2842 RNA_def_property_struct_type(prop, "MeshUVLoopLayer");
2844 prop, "rna_Mesh_uv_layer_default_get", "rna_Mesh_uv_layer_default_set", nullptr, nullptr);
2847 RNA_def_property_ui_text(prop, "Active Render UV Map Layer", "Active Render UV Map layer");
2848 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2849
2850 prop = RNA_def_property(srna, "active_render_index", PROP_INT, PROP_UNSIGNED);
2852 "rna_Mesh_uv_layer_default_index_get",
2853 "rna_Mesh_uv_layer_default_index_set",
2854 "rna_Mesh_uv_layer_index_range");
2856 RNA_def_property_ui_text(prop, "Active Render UV Map Index", "Active Render UV map index");
2857 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2858}
2859
2861static void rna_def_skin_vertices(BlenderRNA *brna, PropertyRNA * /*cprop*/)
2862{
2863 StructRNA *srna;
2864 PropertyRNA *prop;
2865
2866 srna = RNA_def_struct(brna, "MeshSkinVertexLayer", nullptr);
2868 srna, "Mesh Skin Vertex Layer", "Per-vertex skin data for use with the Skin modifier");
2869 RNA_def_struct_path_func(srna, "rna_MeshSkinVertexLayer_path");
2870
2871 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2872 RNA_def_struct_name_property(srna, prop);
2874 prop, "rna_Attribute_name_get", "rna_Attribute_name_length", "rna_Attribute_name_set");
2876 RNA_def_property_ui_text(prop, "Name", "Name of skin layer");
2877 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2878
2879 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
2880 RNA_def_property_struct_type(prop, "MeshSkinVertex");
2881 RNA_def_property_ui_text(prop, "Data", "");
2884 "rna_Attribute_data_begin",
2885 "rna_iterator_array_next",
2886 "rna_iterator_array_end",
2887 "rna_iterator_array_get",
2888 "rna_Attribute_data_length",
2889 "rna_MeshSkinVertexLayer_data_lookup_int",
2890 nullptr,
2891 nullptr);
2892
2893 /* SkinVertex struct */
2894 srna = RNA_def_struct(brna, "MeshSkinVertex", nullptr);
2896 srna, "Skin Vertex", "Per-vertex skin data for use with the Skin modifier");
2897 RNA_def_struct_path_func(srna, "rna_MeshSkinVertex_path");
2898
2899 prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_UNSIGNED);
2900 RNA_def_property_array(prop, 2);
2902 prop, "rna_MeshSkinVertex_radius_get", "rna_MeshSkinVertex_radius_set", nullptr);
2903 RNA_def_property_ui_range(prop, 0.001, 100.0, 1, 3);
2904 RNA_def_property_ui_text(prop, "Radius", "Radius of the skin");
2905 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2906
2907 /* Flags */
2908
2909 prop = RNA_def_property(srna, "use_root", PROP_BOOLEAN, PROP_NONE);
2911 prop, "rna_MeshSkinVertex_use_root_get", "rna_MeshSkinVertex_use_root_set");
2913 "Root",
2914 "Vertex is a root for rotation calculations and armature generation, "
2915 "setting this flag does not clear other roots in the same mesh island");
2916 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2917
2918 prop = RNA_def_property(srna, "use_loose", PROP_BOOLEAN, PROP_NONE);
2920 prop, "rna_MeshSkinVertex_use_loose_get", "rna_MeshSkinVertex_use_loose_set");
2922 prop, "Loose", "If vertex has multiple adjacent edges, it is hulled to them directly");
2923 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
2924}
2925
2927{
2928 StructRNA *srna = RNA_def_struct(brna, "ReadOnlyInteger", nullptr);
2929 RNA_def_struct_sdna(srna, "MIntProperty");
2930 RNA_def_struct_ui_text(srna, "Read-only Integer", "");
2931
2932 PropertyRNA *prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
2933 RNA_def_property_ui_text(prop, "Value", "");
2934 RNA_def_property_int_sdna(prop, nullptr, "i");
2936}
2937
2938static void rna_def_mesh(BlenderRNA *brna)
2939{
2940 StructRNA *srna;
2941 PropertyRNA *prop;
2942
2943 srna = RNA_def_struct(brna, "Mesh", "ID");
2944 RNA_def_struct_ui_text(srna, "Mesh", "Mesh data-block defining geometric surfaces");
2945 RNA_def_struct_ui_icon(srna, ICON_MESH_DATA);
2946
2947 prop = RNA_def_property(srna, "vertices", PROP_COLLECTION, PROP_NONE);
2949 "rna_Mesh_vertices_begin",
2950 "rna_iterator_array_next",
2951 "rna_iterator_array_end",
2952 "rna_iterator_array_get",
2953 "rna_Mesh_vertices_length",
2954 "rna_Mesh_vertices_lookup_int",
2955 nullptr,
2956 nullptr);
2957 RNA_def_property_struct_type(prop, "MeshVertex");
2959 RNA_def_property_ui_text(prop, "Vertices", "Vertices of the mesh");
2960 rna_def_mesh_vertices(brna, prop);
2961
2962 prop = RNA_def_property(srna, "edges", PROP_COLLECTION, PROP_NONE);
2964 "rna_Mesh_edges_begin",
2965 "rna_iterator_array_next",
2966 "rna_iterator_array_end",
2967 "rna_iterator_array_get",
2968 "rna_Mesh_edges_length",
2969 "rna_Mesh_edges_lookup_int",
2970 nullptr,
2971 nullptr);
2972 RNA_def_property_struct_type(prop, "MeshEdge");
2974 RNA_def_property_ui_text(prop, "Edges", "Edges of the mesh");
2975 rna_def_mesh_edges(brna, prop);
2976
2977 prop = RNA_def_property(srna, "loops", PROP_COLLECTION, PROP_NONE);
2979 "rna_Mesh_loops_begin",
2980 "rna_iterator_array_next",
2981 "rna_iterator_array_end",
2982 "rna_iterator_array_get",
2983 "rna_Mesh_loops_length",
2984 "rna_Mesh_loops_lookup_int",
2985 nullptr,
2986 nullptr);
2987 RNA_def_property_struct_type(prop, "MeshLoop");
2989 RNA_def_property_ui_text(prop, "Loops", "Loops of the mesh (face corners)");
2990 rna_def_mesh_loops(brna, prop);
2991
2992 prop = RNA_def_property(srna, "polygons", PROP_COLLECTION, PROP_NONE);
2994 "rna_Mesh_polygons_begin",
2995 "rna_iterator_array_next",
2996 "rna_iterator_array_end",
2997 "rna_iterator_array_get",
2998 "rna_Mesh_polygons_length",
2999 "rna_Mesh_polygons_lookup_int",
3000 nullptr,
3001 nullptr);
3002 RNA_def_property_struct_type(prop, "MeshPolygon");
3004 RNA_def_property_ui_text(prop, "Polygons", "Polygons of the mesh");
3005 rna_def_mesh_polygons(brna, prop);
3006
3008
3009 static const EnumPropertyItem normal_domain_items[] = {
3010 {int(bke::MeshNormalDomain::Point), "POINT", 0, "Point", ""},
3011 {int(bke::MeshNormalDomain::Face), "FACE", 0, "Face", ""},
3012 {int(bke::MeshNormalDomain::Corner), "CORNER", 0, "Corner", ""},
3013 {0, nullptr, 0, nullptr, nullptr},
3014 };
3015
3016 prop = RNA_def_property(srna, "normals_domain", PROP_ENUM, PROP_NONE);
3017 RNA_def_property_enum_items(prop, normal_domain_items);
3019 prop,
3020 "Normal Domain",
3021 "The attribute domain that gives enough information to represent the mesh's normals");
3023 RNA_def_property_enum_funcs(prop, "rna_Mesh_normals_domain_get", nullptr, nullptr);
3024
3025 prop = RNA_def_property(srna, "vertex_normals", PROP_COLLECTION, PROP_NONE);
3026 RNA_def_property_struct_type(prop, "MeshNormalValue");
3029 "Vertex Normals",
3030 "The normal direction of each vertex, defined as the average of the "
3031 "surrounding face normals");
3033 "rna_Mesh_vertex_normals_begin",
3034 "rna_iterator_array_next",
3035 "rna_iterator_array_end",
3036 "rna_iterator_array_get",
3037 "rna_Mesh_vertex_normals_length",
3038 "rna_Mesh_vertex_normals_lookup_int",
3039 nullptr,
3040 nullptr);
3041
3042 prop = RNA_def_property(srna, "polygon_normals", PROP_COLLECTION, PROP_NONE);
3043 RNA_def_property_struct_type(prop, "MeshNormalValue");
3046 "Polygon Normals",
3047 "The normal direction of each face, defined by the winding order "
3048 "and position of its vertices");
3050 "rna_Mesh_poly_normals_begin",
3051 "rna_iterator_array_next",
3052 "rna_iterator_array_end",
3053 "rna_iterator_array_get",
3054 "rna_Mesh_poly_normals_length",
3055 "rna_Mesh_poly_normals_lookup_int",
3056 nullptr,
3057 nullptr);
3058
3059 prop = RNA_def_property(srna, "corner_normals", PROP_COLLECTION, PROP_NONE);
3060 RNA_def_property_struct_type(prop, "MeshNormalValue");
3063 prop,
3064 "Corner Normals",
3065 "The \"split\" normal direction of each face corner, influenced by vertex normals, "
3066 "sharp faces, sharp edges, and custom normals. May be empty.");
3068 "rna_Mesh_corner_normals_begin",
3069 "rna_iterator_array_next",
3070 "rna_iterator_array_end",
3071 "rna_iterator_array_get",
3072 "rna_Mesh_corner_normals_length",
3073 "rna_Mesh_corner_normals_lookup_int",
3074 nullptr,
3075 nullptr);
3076
3077 prop = RNA_def_property(srna, "loop_triangles", PROP_COLLECTION, PROP_NONE);
3079 "rna_Mesh_loop_triangles_begin",
3080 "rna_iterator_array_next",
3081 "rna_iterator_array_end",
3082 "rna_iterator_array_get",
3083 "rna_Mesh_loop_triangles_length",
3084 "rna_Mesh_loop_triangles_lookup_int",
3085 nullptr,
3086 nullptr);
3087 RNA_def_property_struct_type(prop, "MeshLoopTriangle");
3089 RNA_def_property_ui_text(prop, "Loop Triangles", "Tessellation of mesh polygons into triangles");
3090 rna_def_mesh_looptris(brna, prop);
3091
3093
3094 prop = RNA_def_property(srna, "loop_triangle_polygons", PROP_COLLECTION, PROP_NONE);
3096 "rna_Mesh_loop_triangle_polygons_begin",
3097 "rna_iterator_array_next",
3098 "rna_iterator_array_end",
3099 "rna_iterator_array_get",
3100 "rna_Mesh_loop_triangles_length",
3101 "rna_Mesh_loop_triangle_polygons_lookup_int",
3102 nullptr,
3103 nullptr);
3104 RNA_def_property_struct_type(prop, "ReadOnlyInteger");
3107 RNA_def_property_ui_text(prop, "Triangle Faces", "The face index for each loop triangle");
3108
3109 prop = RNA_def_property(srna, "texture_mesh", PROP_POINTER, PROP_NONE);
3110 RNA_def_property_pointer_sdna(prop, nullptr, "texcomesh");
3114 prop,
3115 "Texture Mesh",
3116 "Use another mesh for texture indices (vertex indices must be aligned)");
3117
3118 /* UV loop layers */
3119 prop = RNA_def_property(srna, "uv_layers", PROP_COLLECTION, PROP_NONE);
3121 "rna_Mesh_uv_layers_begin",
3122 "rna_iterator_array_next",
3123 "rna_iterator_array_end",
3124 "rna_Mesh_uv_layers_iterator_get",
3125 "rna_Mesh_uv_layers_length",
3126 nullptr,
3127 nullptr,
3128 nullptr);
3129 RNA_def_property_struct_type(prop, "MeshUVLoopLayer");
3131 RNA_def_property_ui_text(prop, "UV Loop Layers", "All UV loop layers");
3132 rna_def_uv_layers(brna, prop);
3133
3134 prop = RNA_def_property(srna, "uv_layer_clone", PROP_POINTER, PROP_NONE);
3135 RNA_def_property_struct_type(prop, "MeshUVLoopLayer");
3137 prop, "rna_Mesh_uv_layer_clone_get", "rna_Mesh_uv_layer_clone_set", nullptr, nullptr);
3141 prop, "Clone UV Loop Layer", "UV loop layer to be used as cloning source");
3142
3143 prop = RNA_def_property(srna, "uv_layer_clone_index", PROP_INT, PROP_UNSIGNED);
3145 "rna_Mesh_uv_layer_clone_index_get",
3146 "rna_Mesh_uv_layer_clone_index_set",
3147 "rna_Mesh_uv_layer_index_range");
3149 RNA_def_property_ui_text(prop, "Clone UV Loop Layer Index", "Clone UV loop layer index");
3150
3151 prop = RNA_def_property(srna, "uv_layer_stencil", PROP_POINTER, PROP_NONE);
3152 RNA_def_property_struct_type(prop, "MeshUVLoopLayer");
3154 prop, "rna_Mesh_uv_layer_stencil_get", "rna_Mesh_uv_layer_stencil_set", nullptr, nullptr);
3157 RNA_def_property_ui_text(prop, "Mask UV Loop Layer", "UV loop layer to mask the painted area");
3158
3159 prop = RNA_def_property(srna, "uv_layer_stencil_index", PROP_INT, PROP_UNSIGNED);
3161 "rna_Mesh_uv_layer_stencil_index_get",
3162 "rna_Mesh_uv_layer_stencil_index_set",
3163 "rna_Mesh_uv_layer_index_range");
3165 RNA_def_property_ui_text(prop, "Mask UV Loop Layer Index", "Mask UV loop layer index");
3166 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all");
3167
3168 /* Vertex colors */
3169
3170 prop = RNA_def_property(srna, "vertex_colors", PROP_COLLECTION, PROP_NONE);
3172 "rna_Mesh_vertex_colors_begin",
3173 "rna_iterator_array_next",
3174 "rna_iterator_array_end",
3175 "rna_Mesh_vertex_colors_iterator_get",
3176 "rna_Mesh_vertex_colors_length",
3177 nullptr,
3178 nullptr,
3179 nullptr);
3180 RNA_def_property_struct_type(prop, "MeshLoopColorLayer");
3183 prop,
3184 "Vertex Colors",
3185 "Legacy vertex color layers. Deprecated, use color attributes instead.");
3186 rna_def_loop_colors(brna, prop);
3187
3188 /* Skin vertices */
3189 prop = RNA_def_property(srna, "skin_vertices", PROP_COLLECTION, PROP_NONE);
3191 "rna_Mesh_skin_vertices_begin",
3192 "rna_iterator_array_next",
3193 "rna_iterator_array_end",
3194 "rna_Mesh_skin_vertices_iterator_get",
3195 "rna_Mesh_skin_vertices_length",
3196 nullptr,
3197 nullptr,
3198 nullptr);
3199 RNA_def_property_struct_type(prop, "MeshSkinVertexLayer");
3201 RNA_def_property_ui_text(prop, "Skin Vertices", "All skin vertices");
3202 rna_def_skin_vertices(brna, prop);
3203 /* End skin vertices */
3204
3205 /* Attributes */
3207
3208 /* Remesh */
3209 prop = RNA_def_property(srna, "remesh_voxel_size", PROP_FLOAT, PROP_DISTANCE);
3210 /* NOTE: allow zero (which skips computation), to avoid zero clamping
3211 * to a small value which is likely to run out of memory, see: #130526. */
3212 RNA_def_property_float_sdna(prop, nullptr, "remesh_voxel_size");
3214 RNA_def_property_ui_range(prop, 0.0001f, FLT_MAX, 0.01, 4);
3216 "Voxel Size",
3217 "Size of the voxel in object space used for volume evaluation. Lower "
3218 "values preserve finer details.");
3219 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3222
3223 prop = RNA_def_property(srna, "remesh_voxel_adaptivity", PROP_FLOAT, PROP_NONE);
3224 RNA_def_property_float_sdna(prop, nullptr, "remesh_voxel_adaptivity");
3225 RNA_def_property_range(prop, 0.0f, 1.0f);
3226 RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.01, 4);
3228 prop,
3229 "Adaptivity",
3230 "Reduces the final face count by simplifying geometry where detail is not needed, "
3231 "generating triangles. A value greater than 0 disables Fix Poles.");
3232 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3235
3236 prop = RNA_def_property(srna, "use_remesh_fix_poles", PROP_BOOLEAN, PROP_NONE);
3237 RNA_def_property_boolean_sdna(prop, nullptr, "flag", ME_REMESH_FIX_POLES);
3238 RNA_def_property_ui_text(prop, "Fix Poles", "Produces fewer poles and a better topology flow");
3239 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3242
3243 prop = RNA_def_property(srna, "use_remesh_preserve_volume", PROP_BOOLEAN, PROP_NONE);
3246 prop,
3247 "Preserve Volume",
3248 "Projects the mesh to preserve the volume and details of the original mesh");
3249 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3252
3253 prop = RNA_def_property(srna, "use_remesh_preserve_attributes", PROP_BOOLEAN, PROP_NONE);
3255 RNA_def_property_ui_text(prop, "Preserve Attributes", "Transfer all attributes to the new mesh");
3256 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3259
3260 prop = RNA_def_property(srna, "remesh_mode", PROP_ENUM, PROP_NONE);
3261 RNA_def_property_enum_sdna(prop, nullptr, "remesh_mode");
3263 RNA_def_property_ui_text(prop, "Remesh Mode", "");
3264 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3267
3268 /* End remesh */
3269
3270 /* Symmetry */
3271 prop = RNA_def_property(srna, "use_mirror_x", PROP_BOOLEAN, PROP_NONE);
3272 RNA_def_property_boolean_sdna(prop, nullptr, "symmetry", ME_SYMMETRY_X);
3274 RNA_def_property_ui_text(prop, "X", "Enable symmetry in the X axis");
3275 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3276
3277 prop = RNA_def_property(srna, "use_mirror_y", PROP_BOOLEAN, PROP_NONE);
3278 RNA_def_property_boolean_sdna(prop, nullptr, "symmetry", ME_SYMMETRY_Y);
3280 RNA_def_property_ui_text(prop, "Y", "Enable symmetry in the Y axis");
3281 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3282
3283 prop = RNA_def_property(srna, "use_mirror_z", PROP_BOOLEAN, PROP_NONE);
3284 RNA_def_property_boolean_sdna(prop, nullptr, "symmetry", ME_SYMMETRY_Z);
3286 RNA_def_property_ui_text(prop, "Z", "Enable symmetry in the Z axis");
3287 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3288
3289 prop = RNA_def_property(srna, "use_mirror_vertex_groups", PROP_BOOLEAN, PROP_NONE);
3293 "Mirror Vertex Groups",
3294 "Mirror the left/right vertex groups when painting. The symmetry axis "
3295 "is determined by the symmetry settings.");
3296 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3297
3298 prop = RNA_def_property(srna, "radial_symmetry", PROP_INT, PROP_XYZ);
3299 RNA_def_property_int_sdna(prop, nullptr, "radial_symmetry");
3302 RNA_def_property_range(prop, 1, 64);
3303 RNA_def_property_ui_range(prop, 1, 32, 1, 1);
3305 prop, "Radial Symmetry Count", "Number of mirrored regions around a central axis");
3306 /* End Symmetry */
3307
3309 prop = RNA_def_property(srna, "has_custom_normals", PROP_BOOLEAN, PROP_NONE);
3310 RNA_def_property_boolean_sdna(prop, nullptr, "", 0);
3313 prop, "Has Custom Normals", "True if there is custom normal data for this mesh");
3314 RNA_def_property_boolean_funcs(prop, "rna_Mesh_has_custom_normals_get", nullptr);
3316
3317 prop = RNA_def_property(srna, "texco_mesh", PROP_POINTER, PROP_NONE);
3318 RNA_def_property_pointer_sdna(prop, nullptr, "texcomesh");
3322 prop, "Texture Space Mesh", "Derive texture coordinates from another mesh");
3323
3324 prop = RNA_def_property(srna, "shape_keys", PROP_POINTER, PROP_NONE);
3325 RNA_def_property_pointer_sdna(prop, nullptr, "key");
3328 RNA_def_property_ui_text(prop, "Shape Keys", "");
3329
3330 /* texture space */
3331 prop = RNA_def_property(srna, "use_auto_texspace", PROP_BOOLEAN, PROP_NONE);
3332 RNA_def_property_boolean_sdna(prop, nullptr, "texspace_flag", ME_TEXSPACE_FLAG_AUTO);
3334 prop,
3335 "Auto Texture Space",
3336 "Adjust active object's texture space automatically when transforming object");
3337 RNA_def_property_update(prop, 0, "rna_Mesh_update_geom_and_params");
3338
3339# if 0
3340 prop = RNA_def_property(srna, "texspace_location", PROP_FLOAT, PROP_TRANSLATION);
3341 RNA_def_property_array(prop, 3);
3342 RNA_def_property_ui_text(prop, "Texture Space Location", "Texture space location");
3343 RNA_def_property_editable_func(prop, "rna_Mesh_texspace_editable");
3345 prop, "rna_Mesh_texspace_location_get", "rna_Mesh_texspace_location_set", nullptr);
3346 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3347# endif
3348
3349 /* editflag */
3350 prop = RNA_def_property(srna, "use_mirror_topology", PROP_BOOLEAN, PROP_NONE);
3351 RNA_def_property_boolean_sdna(prop, nullptr, "editflag", ME_EDIT_MIRROR_TOPO);
3354 "Topology Mirror",
3355 "Use topology based mirroring "
3356 "(for when both sides of mesh have matching, unique topology)");
3357
3358 prop = RNA_def_property(srna, "use_paint_bone_selection", PROP_BOOLEAN, PROP_NONE);
3360 prop, nullptr, "editflag", ME_EDIT_PAINT_FACE_SEL | ME_EDIT_PAINT_VERT_SEL);
3362 RNA_def_property_ui_text(prop, "Bone Selection", "Bone selection during painting");
3363 RNA_def_property_ui_icon(prop, ICON_BONE_DATA, 0);
3364 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_Mesh_update_bone_selection_mode");
3365
3366 prop = RNA_def_property(srna, "use_paint_mask", PROP_BOOLEAN, PROP_NONE);
3367 RNA_def_property_boolean_sdna(prop, nullptr, "editflag", ME_EDIT_PAINT_FACE_SEL);
3369 RNA_def_property_ui_text(prop, "Paint Mask", "Face selection masking for painting");
3370 RNA_def_property_ui_icon(prop, ICON_FACESEL, 0);
3371 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_Mesh_update_facemask");
3372
3373 prop = RNA_def_property(srna, "use_paint_mask_vertex", PROP_BOOLEAN, PROP_NONE);
3374 RNA_def_property_boolean_sdna(prop, nullptr, "editflag", ME_EDIT_PAINT_VERT_SEL);
3376 RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex selection masking for painting");
3377 RNA_def_property_ui_icon(prop, ICON_VERTEXSEL, 0);
3378 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_Mesh_update_vertmask");
3379
3380 /* readonly editmesh info - use for extrude menu */
3381 prop = RNA_def_property(srna, "total_vert_sel", PROP_INT, PROP_UNSIGNED);
3382 RNA_def_property_int_funcs(prop, "rna_Mesh_tot_vert_get", nullptr, nullptr);
3383 RNA_def_property_ui_text(prop, "Selected Vertex Total", "Selected vertex count in editmode");
3385
3386 prop = RNA_def_property(srna, "total_edge_sel", PROP_INT, PROP_UNSIGNED);
3387 RNA_def_property_int_funcs(prop, "rna_Mesh_tot_edge_get", nullptr, nullptr);
3388 RNA_def_property_ui_text(prop, "Selected Edge Total", "Selected edge count in editmode");
3390
3391 prop = RNA_def_property(srna, "total_face_sel", PROP_INT, PROP_UNSIGNED);
3392 RNA_def_property_int_funcs(prop, "rna_Mesh_tot_face_get", nullptr, nullptr);
3393 RNA_def_property_ui_text(prop, "Selected Face Total", "Selected face count in editmode");
3395
3396 prop = RNA_def_property(srna, "is_editmode", PROP_BOOLEAN, PROP_NONE);
3397 RNA_def_property_boolean_funcs(prop, "rna_Mesh_is_editmode_get", nullptr);
3399 RNA_def_property_ui_text(prop, "Is Editmode", "True when used in editmode");
3400
3401 /* pointers */
3403 rna_def_texmat_common(srna, "rna_Mesh_texspace_editable");
3404
3405 RNA_api_mesh(srna);
3406}
3407
3409{
3410 rna_def_mesh(brna);
3411 rna_def_mvert(brna);
3412 rna_def_mvert_group(brna);
3413 rna_def_medge(brna);
3414 rna_def_mlooptri(brna);
3415 rna_def_mloop(brna);
3416 rna_def_mpolygon(brna);
3417 rna_def_mloopuv(brna);
3418 rna_def_mloopcol(brna);
3419}
3420
3421} // namespace blender
3422
3423#endif
3424
Generic geometry attributes built on CustomData.
#define ATTR_DOMAIN_AS_MASK(domain)
CustomData interface, see also DNA_customdata_types.h.
#define RNA_MAX_ARRAY_DIMENSION
Definition RNA_define.hh:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define ND_SELECT
Definition WM_types.hh:551
#define ND_SPACE_VIEW3D
Definition WM_types.hh:571
#define NC_SPACE
Definition WM_types.hh:405
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert_msg(a, msg)
#define MAX_CUSTOMDATA_LAYER_NAME
#define CD_MASK_PROP_BYTE_COLOR
#define CD_MASK_PROP_FLOAT2
#define CD_MASK_PROP_BOOL
#define MAX_CUSTOMDATA_LAYER_NAME_NO_PREFIX
btScalar max
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
Definition btVector3.h:257
constexpr const T * data() const
Definition BLI_span.hh:219
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr bool is_empty() const
Definition BLI_span.hh:264
static AttributeOwner from_id(ID *id)
constexpr IndexRange()=default
constexpr StringRef()
#define FLT_MAX
#define INT_MAX
#define position
#define layer
float3 face_normal_calc(Span< float3 > vert_positions, Span< int > face_verts)
float face_area_calc(Span< float3 > vert_positions, Span< int > face_verts)
float3 face_center_calc(Span< float3 > vert_positions, Span< int > face_verts)
std::optional< eCustomDataType > attr_type_to_custom_data_type(AttrType attr_type)
void mesh_flip_faces(Mesh &mesh, const IndexMask &selection)
int size(const AssetLibraryReference *library_reference)
const MultiFunction & lookup(UString id)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
static const EnumPropertyItem rna_enum_mesh_remesh_mode_items[]
Definition rna_mesh.cc:94
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
static void rna_def_mesh_vertices(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_mesh.cc:2612
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
bool BKE_attribute_remove(AttributeOwner &owner, StringRef name, struct ReportList *reports)
void rna_Mesh_update_draw(Main *bmain, Scene *scene, PointerRNA *ptr)
__int64 int64_t
Definition BKE_text.h:90
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void BKE_id_attributes_default_color_set(struct ID *id, std::optional< StringRef > name)
void RNA_def_property_override_funcs(PropertyRNA *prop, const char *diff, const char *store, const char *apply)
MINLINE void copy_v3_v3(float r[3], const float a[3])
const EnumPropertyItem rna_enum_mesh_walk_delimit_face_loop_items[]
Definition rna_mesh.cc:79
void rna_iterator_array_end(CollectionPropertyIterator *iter)
void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void id_us_plus(ID *id)
Definition lib_id.cc:433
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
static void rna_def_mesh_looptris(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_mesh.cc:2663
static void rna_def_mvert(BlenderRNA *brna)
Definition rna_mesh.cc:2051
PointerRNA RNA_id_pointer_create(ID *id)
VArray< bool > ED_mesh_uv_map_pin_layer_get(const Mesh *mesh, int uv_index)
Definition mesh_data.cc:233
MINLINE void copy_v2_v2(float r[2], const float a[2])
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
static void rna_def_mesh_polygons(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_mesh.cc:2696
@ FUNC_USE_REPORTS
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:980
@ FUNC_SELF_AS_RNA
Definition RNA_types.hh:991
StringRefNull rna_Attribute_name_get(const PointerRNA &ptr)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void rna_pointer_create_with_ancestors(const PointerRNA &parent, StructRNA *type, void *data, PointerRNA &r_ptr)
int BKE_attributes_length(const AttributeOwner &owner, AttrDomainMask domain_mask, eCustomDataMask mask, bool include_anonymous=true)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
MINLINE int max_ii(int a, int b)
void BKE_mesh_tessface_clear(Mesh *mesh)
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
Definition math_geom.cc:45
static void rna_def_medge(BlenderRNA *brna)
Definition rna_mesh.cc:2115
@ LIBOVERRIDE_OP_REPLACE
Definition DNA_ID.h:188
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
static void rna_def_mlooptri(BlenderRNA *brna)
Definition rna_mesh.cc:2167
static void rna_def_mesh_edges(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_mesh.cc:2638
MINLINE void mul_v3_fl(float r[3], float f)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
const EnumPropertyItem rna_enum_mesh_walk_delimit_edge_ring_items[]
Definition rna_mesh.cc:59
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:588
@ PROPOVERRIDE_IGNORE
Definition RNA_types.hh:609
void rna_Attribute_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
void rna_def_animdata_common(StructRNA *srna)
uint64_t eCustomDataMask
static void rna_def_mloopcol(BlenderRNA *brna)
Definition rna_mesh.cc:2504
VecBase< float, 4 > float4
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
void rna_def_texmat_common(StructRNA *srna, const char *texspace_editable)
Definition rna_mesh.cc:2564
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
bool BKE_mesh_has_custom_loop_normals(Mesh *mesh)
@ ME_EDIT_MIRROR_VERTEX_GROUPS
@ ME_EDIT_PAINT_VERT_SEL
@ ME_EDIT_PAINT_FACE_SEL
@ ME_EDIT_MIRROR_TOPO
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
@ PROP_COLLECTION
Definition RNA_types.hh:216
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
static void rna_def_uv_layers(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_mesh.cc:2790
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void DEG_id_tag_update(ID *id, unsigned int flags)
BMesh const char void * data
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
void BKE_mesh_batch_cache_dirty_tag(Mesh *mesh, eMeshBatchDirtyMode mode)
const EnumPropertyItem rna_enum_mesh_walk_delimit_edge_loop_items[]
Definition rna_mesh.cc:37
void BKE_mesh_texspace_get(Mesh *mesh, float r_texspace_location[3], float r_texspace_size[3])
void RNA_def_mesh(BlenderRNA *brna)
Definition rna_mesh.cc:3408
int rna_Attribute_data_length(PointerRNA *ptr)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
@ ME_TEXSPACE_FLAG_AUTO
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
void BKE_mesh_texspace_ensure(Mesh *mesh)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
static void rna_def_mloop(BlenderRNA *brna)
Definition rna_mesh.cc:2235
const EnumPropertyItem rna_enum_mesh_delimit_mode_items[]
Definition rna_mesh.cc:28
int BKE_mesh_runtime_corner_tris_len(const Mesh *mesh)
eCustomDataMask CD_TYPE_AS_MASK(eCustomDataType type)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
std::optional< std::string > ED_mesh_color_add(Mesh *mesh, const char *name, bool active_set, bool do_init, ReportList *reports)
Definition mesh_data.cc:277
std::optional< StringRef > BKE_attribute_from_index(AttributeOwner &owner, int lookup_index, AttrDomainMask domain_mask, eCustomDataMask layer_mask, bool include_anonymous=true)
void * rna_iterator_array_get(CollectionPropertyIterator *iter)
MINLINE void zero_v3(float r[3])
@ ME_REMESH_REPROJECT_ATTRIBUTES
@ ME_REMESH_REPROJECT_VOLUME
@ ME_REMESH_FIX_POLES
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
bke::AttributeWriter< bool > ED_mesh_uv_map_pin_layer_ensure(Mesh *mesh, int uv_index)
Definition mesh_data.cc:248
void rna_AttributeGroup_iterator_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, AttrDomainMask domain_mask, eCustomDataMask cd_type_mask, bool include_anonymous)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3])
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
static void rna_def_loop_colors(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_mesh.cc:2736
static void rna_def_looptri_poly_value(BlenderRNA *brna)
Definition rna_mesh.cc:2926
@ ATTR_DOMAIN_MASK_CORNER
@ ATTR_DOMAIN_MASK_POINT
void RNA_api_mesh(StructRNA *srna)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static void rna_def_mvert_group(BlenderRNA *brna)
Definition rna_mesh.cc:2025
int BKE_attribute_to_index(const AttributeOwner &owner, const StringRef name, AttrDomainMask domain_mask, eCustomDataMask layer_mask, bool include_anonymous=true)
float area_tri_v3(const float v1[3], const float v2[3], const float v3[3])
Definition math_geom.cc:104
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void BKE_id_attributes_active_color_set(struct ID *id, std::optional< StringRef > name)
@ ID_RECALC_PARAMETERS
Definition DNA_ID.h:1138
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
static void rna_def_normal_layer_value(BlenderRNA *brna)
Definition rna_mesh.cc:2723
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_PROPORTIONAL
Definition RNA_types.hh:419
@ PROP_DYNAMIC
Definition RNA_types.hh:498
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_PTR_NO_OWNERSHIP
Definition RNA_types.hh:465
@ PROP_NEVER_UNLINK
Definition RNA_types.hh:454
@ PROP_ID_SELF_CHECK
Definition RNA_types.hh:440
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
@ PROP_ANIMATABLE
Definition RNA_types.hh:389
@ PROP_NO_DEG_UPDATE
Definition RNA_types.hh:509
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
const BMesh * BKE_editmesh_bmesh_get(const Object *ob)
Definition editmesh.cc:65
MINLINE unsigned char round_fl_to_uchar_clamp(float a)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
std::optional< std::string > ED_mesh_uv_add(Mesh *mesh, const char *name, bool active_set, bool do_init, ReportList *reports)
Definition mesh_data.cc:154
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
static void rna_def_mpolygon(BlenderRNA *brna)
Definition rna_mesh.cc:2304
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_define_verify_sdna(bool verify)
VecBase< float, 3 > float3
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ PROP_TRANSLATION
Definition RNA_types.hh:318
@ PROP_DISTANCE
Definition RNA_types.hh:313
@ PROP_DIRECTION
Definition RNA_types.hh:319
@ PROP_UNSIGNED
Definition RNA_types.hh:306
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_RNAPTR
Definition RNA_types.hh:633
bool CustomData_has_layer_named(const CustomData *data, eCustomDataType type, StringRef name)
void RNA_def_property_int_default(PropertyRNA *prop, int value)
@ BKE_MESH_BATCH_DIRTY_ALL
Definition BKE_mesh.h:48
StringRef BKE_uv_map_pin_name_get(StringRef uv_map_name, char *buffer)
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop, const bool allow_replace)
static void rna_def_mloopuv(BlenderRNA *brna)
Definition rna_mesh.cc:2398
static void rna_def_mesh(BlenderRNA *brna)
Definition rna_mesh.cc:2938
void id_us_min(ID *id)
Definition lib_id.cc:441
void RNA_def_property_array(PropertyRNA *prop, int length)
static void rna_def_skin_vertices(BlenderRNA *brna, PropertyRNA *)
Definition rna_mesh.cc:2861
PointerRNA rna_AttributeGroup_lookup_string(const PointerRNA &ptr, const StringRef key, AttrDomainMask domain_mask, eCustomDataMask cd_type_mask)
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
static void rna_def_mesh_loops(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_mesh.cc:2675
void rna_iterator_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, void *data, size_t itemsize, int64_t length, bool free_ptr, IteratorSkipFunc skip)
@ BMW_DELIMIT_EDGE_LOOP_OUTER_CORNERS
@ BMW_DELIMIT_EDGE_MARK_SHARP
@ BMW_DELIMIT_EDGE_LOOP_INNER_CORNERS
@ BMW_DELIMIT_EDGE_LOOP_NGONS
@ BMW_DELIMIT_FACE_MARK_MATERIAL
@ BMW_DELIMIT_EDGE_MARK_SEAM
@ BMW_DELIMIT_EDGE_RING_NGONS
void rna_def_attributes_common(StructRNA *srna, const AttributeOwnerType type)
void BKE_mesh_runtime_clear_geometry(Mesh *mesh)
#define min(a, b)
Definition sort.cc:38