1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 */
16
17 /* note: the original vertex color stuff is now just used for
18 * getting info on the layers themselves, accessing the data is
19 * done through the (not yet written) mpoly interfaces.*/
20
21 /** \file
22 * \ingroup RNA
23 */
24
25 #include <stdlib.h>
26
27 #include "MEM_guardedalloc.h"
28
29 #include "DNA_material_types.h"
30 #include "DNA_mesh_types.h"
31 #include "DNA_meshdata_types.h"
32 #include "DNA_object_types.h"
33
34 #include "BLI_math_base.h"
35 #include "BLI_math_rotation.h"
36 #include "BLI_utildefines.h"
37
38 #include "BKE_editmesh.h"
39
40 #include "RNA_access.h"
41 #include "RNA_define.h"
42 #include "RNA_enum_types.h"
43 #include "RNA_types.h"
44
45 #include "rna_internal.h"
46
47 #include "WM_types.h"
48
49 const EnumPropertyItem rna_enum_mesh_delimit_mode_items[] = {
50 {BMO_DELIM_NORMAL, "NORMAL", 0, "Normal", "Delimit by face directions"},
51 {BMO_DELIM_MATERIAL, "MATERIAL", 0, "Material", "Delimit by face material"},
52 {BMO_DELIM_SEAM, "SEAM", 0, "Seam", "Delimit by edge seams"},
53 {BMO_DELIM_SHARP, "SHARP", 0, "Sharp", "Delimit by sharp edges"},
54 {BMO_DELIM_UV, "UV", 0, "UVs", "Delimit by UV coordinates"},
55 {0, NULL, 0, NULL, NULL},
56 };
57
58 static const EnumPropertyItem rna_enum_mesh_remesh_mode_items[] = {
59 {REMESH_VOXEL, "VOXEL", 0, "Voxel", "Use the voxel remesher"},
60 {REMESH_QUAD, "QUAD", 0, "Quad", "Use the quad remesher"},
61 {0, NULL, 0, NULL, NULL},
62 };
63
64 #ifdef RNA_RUNTIME
65
66 # include "DNA_scene_types.h"
67
68 # include "BLI_math.h"
69
70 # include "BKE_customdata.h"
71 # include "BKE_main.h"
72 # include "BKE_mesh.h"
73 # include "BKE_mesh_runtime.h"
74 # include "BKE_report.h"
75
76 # include "DEG_depsgraph.h"
77
78 # include "ED_mesh.h" /* XXX Bad level call */
79
80 # include "WM_api.h"
81
82 # include "rna_mesh_utils.h"
83
84 /* -------------------------------------------------------------------- */
85 /* Generic helpers */
86
rna_mesh(PointerRNA * ptr)87 static Mesh *rna_mesh(PointerRNA *ptr)
88 {
89 Mesh *me = (Mesh *)ptr->owner_id;
90 return me;
91 }
92
rna_mesh_vdata_helper(Mesh * me)93 static CustomData *rna_mesh_vdata_helper(Mesh *me)
94 {
95 return (me->edit_mesh) ? &me->edit_mesh->bm->vdata : &me->vdata;
96 }
97
rna_mesh_edata_helper(Mesh * me)98 static CustomData *rna_mesh_edata_helper(Mesh *me)
99 {
100 return (me->edit_mesh) ? &me->edit_mesh->bm->edata : &me->edata;
101 }
102
rna_mesh_pdata_helper(Mesh * me)103 static CustomData *rna_mesh_pdata_helper(Mesh *me)
104 {
105 return (me->edit_mesh) ? &me->edit_mesh->bm->pdata : &me->pdata;
106 }
107
rna_mesh_ldata_helper(Mesh * me)108 static CustomData *rna_mesh_ldata_helper(Mesh *me)
109 {
110 return (me->edit_mesh) ? &me->edit_mesh->bm->ldata : &me->ldata;
111 }
112
rna_mesh_fdata_helper(Mesh * me)113 static CustomData *rna_mesh_fdata_helper(Mesh *me)
114 {
115 return (me->edit_mesh) ? NULL : &me->fdata;
116 }
117
rna_mesh_vdata(PointerRNA * ptr)118 static CustomData *rna_mesh_vdata(PointerRNA *ptr)
119 {
120 Mesh *me = rna_mesh(ptr);
121 return rna_mesh_vdata_helper(me);
122 }
123 # if 0
124 static CustomData *rna_mesh_edata(PointerRNA *ptr)
125 {
126 Mesh *me = rna_mesh(ptr);
127 return rna_mesh_edata_helper(me);
128 }
129 # endif
rna_mesh_pdata(PointerRNA * ptr)130 static CustomData *rna_mesh_pdata(PointerRNA *ptr)
131 {
132 Mesh *me = rna_mesh(ptr);
133 return rna_mesh_pdata_helper(me);
134 }
135
rna_mesh_ldata(PointerRNA * ptr)136 static CustomData *rna_mesh_ldata(PointerRNA *ptr)
137 {
138 Mesh *me = rna_mesh(ptr);
139 return rna_mesh_ldata_helper(me);
140 }
141
142 /* -------------------------------------------------------------------- */
143 /* Generic CustomData Layer Functions */
144
rna_cd_layer_name_set(CustomData * cdata,CustomDataLayer * cdl,const char * value)145 static void rna_cd_layer_name_set(CustomData *cdata, CustomDataLayer *cdl, const char *value)
146 {
147 BLI_strncpy_utf8(cdl->name, value, sizeof(cdl->name));
148 CustomData_set_layer_unique_name(cdata, cdl - cdata->layers);
149 }
150
151 /* avoid using where possible!, ideally the type is known */
rna_cd_from_layer(PointerRNA * ptr,CustomDataLayer * cdl)152 static CustomData *rna_cd_from_layer(PointerRNA *ptr, CustomDataLayer *cdl)
153 {
154 /* find out where we come from by */
155 Mesh *me = (Mesh *)ptr->owner_id;
156 CustomData *cd;
157
158 /* rely on negative values wrapping */
159 # define TEST_CDL(cmd) \
160 if ((void)(cd = cmd(me)), ARRAY_HAS_ITEM(cdl, cd->layers, cd->totlayer)) { \
161 return cd; \
162 } \
163 ((void)0)
164
165 TEST_CDL(rna_mesh_vdata_helper);
166 TEST_CDL(rna_mesh_edata_helper);
167 TEST_CDL(rna_mesh_pdata_helper);
168 TEST_CDL(rna_mesh_ldata_helper);
169 TEST_CDL(rna_mesh_fdata_helper);
170
171 # undef TEST_CDL
172
173 /* should _never_ happen */
174 return NULL;
175 }
176
rna_MeshVertexLayer_name_set(PointerRNA * ptr,const char * value)177 static void rna_MeshVertexLayer_name_set(PointerRNA *ptr, const char *value)
178 {
179 rna_cd_layer_name_set(rna_mesh_vdata(ptr), (CustomDataLayer *)ptr->data, value);
180 }
181 # if 0
182 static void rna_MeshEdgeLayer_name_set(PointerRNA *ptr, const char *value)
183 {
184 rna_cd_layer_name_set(rna_mesh_edata(ptr), (CustomDataLayer *)ptr->data, value);
185 }
186 # endif
rna_MeshPolyLayer_name_set(PointerRNA * ptr,const char * value)187 static void rna_MeshPolyLayer_name_set(PointerRNA *ptr, const char *value)
188 {
189 rna_cd_layer_name_set(rna_mesh_pdata(ptr), (CustomDataLayer *)ptr->data, value);
190 }
rna_MeshLoopLayer_name_set(PointerRNA * ptr,const char * value)191 static void rna_MeshLoopLayer_name_set(PointerRNA *ptr, const char *value)
192 {
193 rna_cd_layer_name_set(rna_mesh_ldata(ptr), (CustomDataLayer *)ptr->data, value);
194 }
195 /* only for layers shared between types */
rna_MeshAnyLayer_name_set(PointerRNA * ptr,const char * value)196 static void rna_MeshAnyLayer_name_set(PointerRNA *ptr, const char *value)
197 {
198 CustomData *cd = rna_cd_from_layer(ptr, (CustomDataLayer *)ptr->data);
199 rna_cd_layer_name_set(cd, (CustomDataLayer *)ptr->data, value);
200 }
201
rna_Mesh_has_custom_normals_get(PointerRNA * ptr)202 static bool rna_Mesh_has_custom_normals_get(PointerRNA *ptr)
203 {
204 Mesh *me = ptr->data;
205 return BKE_mesh_has_custom_loop_normals(me);
206 }
207
208 /* -------------------------------------------------------------------- */
209 /* Update Callbacks */
210
rna_Mesh_update_data(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)211 static void rna_Mesh_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
212 {
213 ID *id = ptr->owner_id;
214
215 /* cheating way for importers to avoid slow updates */
216 if (id->us > 0) {
217 DEG_id_tag_update(id, 0);
218 WM_main_add_notifier(NC_GEOM | ND_DATA, id);
219 }
220 }
221
rna_Mesh_update_data_edit_weight(Main * bmain,Scene * scene,PointerRNA * ptr)222 static void rna_Mesh_update_data_edit_weight(Main *bmain, Scene *scene, PointerRNA *ptr)
223 {
224 BKE_mesh_batch_cache_dirty_tag(rna_mesh(ptr), BKE_MESH_BATCH_DIRTY_ALL);
225
226 rna_Mesh_update_data(bmain, scene, ptr);
227 }
228
rna_Mesh_update_data_edit_active_color(Main * bmain,Scene * scene,PointerRNA * ptr)229 static void rna_Mesh_update_data_edit_active_color(Main *bmain, Scene *scene, PointerRNA *ptr)
230 {
231 BKE_mesh_batch_cache_dirty_tag(rna_mesh(ptr), BKE_MESH_BATCH_DIRTY_ALL);
232
233 rna_Mesh_update_data(bmain, scene, ptr);
234 }
rna_Mesh_update_select(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)235 static void rna_Mesh_update_select(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
236 {
237 ID *id = ptr->owner_id;
238 /* cheating way for importers to avoid slow updates */
239 if (id->us > 0) {
240 WM_main_add_notifier(NC_GEOM | ND_SELECT, id);
241 }
242 }
243
rna_Mesh_update_draw(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)244 void rna_Mesh_update_draw(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
245 {
246 ID *id = ptr->owner_id;
247 /* cheating way for importers to avoid slow updates */
248 if (id->us > 0) {
249 WM_main_add_notifier(NC_GEOM | ND_DATA, id);
250 }
251 }
252
rna_Mesh_update_vertmask(Main * bmain,Scene * scene,PointerRNA * ptr)253 static void rna_Mesh_update_vertmask(Main *bmain, Scene *scene, PointerRNA *ptr)
254 {
255 Mesh *me = ptr->data;
256 if ((me->editflag & ME_EDIT_PAINT_VERT_SEL) && (me->editflag & ME_EDIT_PAINT_FACE_SEL)) {
257 me->editflag &= ~ME_EDIT_PAINT_FACE_SEL;
258 }
259
260 BKE_mesh_batch_cache_dirty_tag(me, BKE_MESH_BATCH_DIRTY_ALL);
261
262 rna_Mesh_update_draw(bmain, scene, ptr);
263 }
264
rna_Mesh_update_facemask(Main * bmain,Scene * scene,PointerRNA * ptr)265 static void rna_Mesh_update_facemask(Main *bmain, Scene *scene, PointerRNA *ptr)
266 {
267 Mesh *me = ptr->data;
268 if ((me->editflag & ME_EDIT_PAINT_VERT_SEL) && (me->editflag & ME_EDIT_PAINT_FACE_SEL)) {
269 me->editflag &= ~ME_EDIT_PAINT_VERT_SEL;
270 }
271
272 BKE_mesh_batch_cache_dirty_tag(me, BKE_MESH_BATCH_DIRTY_ALL);
273
274 rna_Mesh_update_draw(bmain, scene, ptr);
275 }
276
277 /* -------------------------------------------------------------------- */
278 /* Property get/set Callbacks */
279
rna_MeshVertex_normal_get(PointerRNA * ptr,float * value)280 static void rna_MeshVertex_normal_get(PointerRNA *ptr, float *value)
281 {
282 MVert *mvert = (MVert *)ptr->data;
283 normal_short_to_float_v3(value, mvert->no);
284 }
285
rna_MeshVertex_normal_set(PointerRNA * ptr,const float * value)286 static void rna_MeshVertex_normal_set(PointerRNA *ptr, const float *value)
287 {
288 MVert *mvert = (MVert *)ptr->data;
289 float no[3];
290
291 copy_v3_v3(no, value);
292 normalize_v3(no);
293 normal_float_to_short_v3(mvert->no, no);
294 }
295
rna_MeshVertex_bevel_weight_get(PointerRNA * ptr)296 static float rna_MeshVertex_bevel_weight_get(PointerRNA *ptr)
297 {
298 MVert *mvert = (MVert *)ptr->data;
299 return mvert->bweight / 255.0f;
300 }
301
rna_MeshVertex_bevel_weight_set(PointerRNA * ptr,float value)302 static void rna_MeshVertex_bevel_weight_set(PointerRNA *ptr, float value)
303 {
304 MVert *mvert = (MVert *)ptr->data;
305 mvert->bweight = round_fl_to_uchar_clamp(value * 255.0f);
306 }
307
rna_MEdge_bevel_weight_get(PointerRNA * ptr)308 static float rna_MEdge_bevel_weight_get(PointerRNA *ptr)
309 {
310 MEdge *medge = (MEdge *)ptr->data;
311 return medge->bweight / 255.0f;
312 }
313
rna_MEdge_bevel_weight_set(PointerRNA * ptr,float value)314 static void rna_MEdge_bevel_weight_set(PointerRNA *ptr, float value)
315 {
316 MEdge *medge = (MEdge *)ptr->data;
317 medge->bweight = round_fl_to_uchar_clamp(value * 255.0f);
318 }
319
rna_MEdge_crease_get(PointerRNA * ptr)320 static float rna_MEdge_crease_get(PointerRNA *ptr)
321 {
322 MEdge *medge = (MEdge *)ptr->data;
323 return medge->crease / 255.0f;
324 }
325
rna_MEdge_crease_set(PointerRNA * ptr,float value)326 static void rna_MEdge_crease_set(PointerRNA *ptr, float value)
327 {
328 MEdge *medge = (MEdge *)ptr->data;
329 medge->crease = round_fl_to_uchar_clamp(value * 255.0f);
330 }
331
rna_MeshLoop_normal_get(PointerRNA * ptr,float * values)332 static void rna_MeshLoop_normal_get(PointerRNA *ptr, float *values)
333 {
334 Mesh *me = rna_mesh(ptr);
335 MLoop *ml = (MLoop *)ptr->data;
336 const float(*vec)[3] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_NORMAL);
337
338 if (!vec) {
339 zero_v3(values);
340 }
341 else {
342 copy_v3_v3(values, (const float *)vec);
343 }
344 }
345
rna_MeshLoop_normal_set(PointerRNA * ptr,const float * values)346 static void rna_MeshLoop_normal_set(PointerRNA *ptr, const float *values)
347 {
348 Mesh *me = rna_mesh(ptr);
349 MLoop *ml = (MLoop *)ptr->data;
350 float(*vec)[3] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_NORMAL);
351
352 if (vec) {
353 normalize_v3_v3(*vec, values);
354 }
355 }
356
rna_MeshLoop_tangent_get(PointerRNA * ptr,float * values)357 static void rna_MeshLoop_tangent_get(PointerRNA *ptr, float *values)
358 {
359 Mesh *me = rna_mesh(ptr);
360 MLoop *ml = (MLoop *)ptr->data;
361 const float(*vec)[4] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_MLOOPTANGENT);
362
363 if (!vec) {
364 zero_v3(values);
365 }
366 else {
367 copy_v3_v3(values, (const float *)vec);
368 }
369 }
370
rna_MeshLoop_bitangent_sign_get(PointerRNA * ptr)371 static float rna_MeshLoop_bitangent_sign_get(PointerRNA *ptr)
372 {
373 Mesh *me = rna_mesh(ptr);
374 MLoop *ml = (MLoop *)ptr->data;
375 const float(*vec)[4] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_MLOOPTANGENT);
376
377 return (vec) ? (*vec)[3] : 0.0f;
378 }
379
rna_MeshLoop_bitangent_get(PointerRNA * ptr,float * values)380 static void rna_MeshLoop_bitangent_get(PointerRNA *ptr, float *values)
381 {
382 Mesh *me = rna_mesh(ptr);
383 MLoop *ml = (MLoop *)ptr->data;
384 const float(*nor)[3] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_NORMAL);
385 const float(*vec)[4] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_MLOOPTANGENT);
386
387 if (nor && vec) {
388 cross_v3_v3v3(values, (const float *)nor, (const float *)vec);
389 mul_v3_fl(values, (*vec)[3]);
390 }
391 else {
392 zero_v3(values);
393 }
394 }
395
rna_MeshPolygon_normal_get(PointerRNA * ptr,float * values)396 static void rna_MeshPolygon_normal_get(PointerRNA *ptr, float *values)
397 {
398 Mesh *me = rna_mesh(ptr);
399 MPoly *mp = (MPoly *)ptr->data;
400
401 BKE_mesh_calc_poly_normal(mp, me->mloop + mp->loopstart, me->mvert, values);
402 }
403
rna_MeshPolygon_center_get(PointerRNA * ptr,float * values)404 static void rna_MeshPolygon_center_get(PointerRNA *ptr, float *values)
405 {
406 Mesh *me = rna_mesh(ptr);
407 MPoly *mp = (MPoly *)ptr->data;
408
409 BKE_mesh_calc_poly_center(mp, me->mloop + mp->loopstart, me->mvert, values);
410 }
411
rna_MeshPolygon_area_get(PointerRNA * ptr)412 static float rna_MeshPolygon_area_get(PointerRNA *ptr)
413 {
414 Mesh *me = (Mesh *)ptr->owner_id;
415 MPoly *mp = (MPoly *)ptr->data;
416
417 return BKE_mesh_calc_poly_area(mp, me->mloop + mp->loopstart, me->mvert);
418 }
419
rna_MeshPolygon_flip(ID * id,MPoly * mp)420 static void rna_MeshPolygon_flip(ID *id, MPoly *mp)
421 {
422 Mesh *me = (Mesh *)id;
423
424 BKE_mesh_polygon_flip(mp, me->mloop, &me->ldata);
425 BKE_mesh_tessface_clear(me);
426 BKE_mesh_runtime_clear_geometry(me);
427 }
428
rna_MeshLoopTriangle_verts_get(PointerRNA * ptr,int * values)429 static void rna_MeshLoopTriangle_verts_get(PointerRNA *ptr, int *values)
430 {
431 Mesh *me = rna_mesh(ptr);
432 MLoopTri *lt = (MLoopTri *)ptr->data;
433 values[0] = me->mloop[lt->tri[0]].v;
434 values[1] = me->mloop[lt->tri[1]].v;
435 values[2] = me->mloop[lt->tri[2]].v;
436 }
437
rna_MeshLoopTriangle_normal_get(PointerRNA * ptr,float * values)438 static void rna_MeshLoopTriangle_normal_get(PointerRNA *ptr, float *values)
439 {
440 Mesh *me = rna_mesh(ptr);
441 MLoopTri *lt = (MLoopTri *)ptr->data;
442 unsigned int v1 = me->mloop[lt->tri[0]].v;
443 unsigned int v2 = me->mloop[lt->tri[1]].v;
444 unsigned int v3 = me->mloop[lt->tri[2]].v;
445
446 normal_tri_v3(values, me->mvert[v1].co, me->mvert[v2].co, me->mvert[v3].co);
447 }
448
rna_MeshLoopTriangle_split_normals_get(PointerRNA * ptr,float * values)449 static void rna_MeshLoopTriangle_split_normals_get(PointerRNA *ptr, float *values)
450 {
451 Mesh *me = rna_mesh(ptr);
452 const float(*lnors)[3] = CustomData_get_layer(&me->ldata, CD_NORMAL);
453
454 if (!lnors) {
455 zero_v3(values + 0);
456 zero_v3(values + 3);
457 zero_v3(values + 6);
458 }
459 else {
460 MLoopTri *lt = (MLoopTri *)ptr->data;
461 copy_v3_v3(values + 0, lnors[lt->tri[0]]);
462 copy_v3_v3(values + 3, lnors[lt->tri[1]]);
463 copy_v3_v3(values + 6, lnors[lt->tri[2]]);
464 }
465 }
466
rna_MeshLoopTriangle_area_get(PointerRNA * ptr)467 static float rna_MeshLoopTriangle_area_get(PointerRNA *ptr)
468 {
469 Mesh *me = rna_mesh(ptr);
470 MLoopTri *lt = (MLoopTri *)ptr->data;
471 unsigned int v1 = me->mloop[lt->tri[0]].v;
472 unsigned int v2 = me->mloop[lt->tri[1]].v;
473 unsigned int v3 = me->mloop[lt->tri[2]].v;
474
475 return area_tri_v3(me->mvert[v1].co, me->mvert[v2].co, me->mvert[v3].co);
476 }
477
rna_MeshLoopColor_color_get(PointerRNA * ptr,float * values)478 static void rna_MeshLoopColor_color_get(PointerRNA *ptr, float *values)
479 {
480 MLoopCol *mlcol = (MLoopCol *)ptr->data;
481
482 values[0] = mlcol->r / 255.0f;
483 values[1] = mlcol->g / 255.0f;
484 values[2] = mlcol->b / 255.0f;
485 values[3] = mlcol->a / 255.0f;
486 }
487
rna_MeshLoopColor_color_set(PointerRNA * ptr,const float * values)488 static void rna_MeshLoopColor_color_set(PointerRNA *ptr, const float *values)
489 {
490 MLoopCol *mlcol = (MLoopCol *)ptr->data;
491
492 mlcol->r = round_fl_to_uchar_clamp(values[0] * 255.0f);
493 mlcol->g = round_fl_to_uchar_clamp(values[1] * 255.0f);
494 mlcol->b = round_fl_to_uchar_clamp(values[2] * 255.0f);
495 mlcol->a = round_fl_to_uchar_clamp(values[3] * 255.0f);
496 }
497
rna_Mesh_texspace_editable(PointerRNA * ptr,const char ** UNUSED (r_info))498 static int rna_Mesh_texspace_editable(PointerRNA *ptr, const char **UNUSED(r_info))
499 {
500 Mesh *me = (Mesh *)ptr->data;
501 return (me->texflag & ME_AUTOSPACE) ? 0 : PROP_EDITABLE;
502 }
503
rna_Mesh_texspace_size_get(PointerRNA * ptr,float values[3])504 static void rna_Mesh_texspace_size_get(PointerRNA *ptr, float values[3])
505 {
506 Mesh *me = (Mesh *)ptr->data;
507
508 BKE_mesh_texspace_ensure(me);
509
510 copy_v3_v3(values, me->size);
511 }
512
rna_Mesh_texspace_loc_get(PointerRNA * ptr,float values[3])513 static void rna_Mesh_texspace_loc_get(PointerRNA *ptr, float values[3])
514 {
515 Mesh *me = (Mesh *)ptr->data;
516
517 BKE_mesh_texspace_ensure(me);
518
519 copy_v3_v3(values, me->loc);
520 }
521
rna_MeshVertex_groups_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)522 static void rna_MeshVertex_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
523 {
524 Mesh *me = rna_mesh(ptr);
525
526 if (me->dvert) {
527 MVert *mvert = (MVert *)ptr->data;
528 MDeformVert *dvert = me->dvert + (mvert - me->mvert);
529
530 rna_iterator_array_begin(
531 iter, (void *)dvert->dw, sizeof(MDeformWeight), dvert->totweight, 0, NULL);
532 }
533 else {
534 rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL);
535 }
536 }
537
rna_MeshVertex_undeformed_co_get(PointerRNA * ptr,float values[3])538 static void rna_MeshVertex_undeformed_co_get(PointerRNA *ptr, float values[3])
539 {
540 Mesh *me = rna_mesh(ptr);
541 MVert *mvert = (MVert *)ptr->data;
542 float(*orco)[3] = CustomData_get_layer(&me->vdata, CD_ORCO);
543
544 if (orco) {
545 /* orco is normalized to 0..1, we do inverse to match mvert->co */
546 float loc[3], size[3];
547
548 BKE_mesh_texspace_get(me->texcomesh ? me->texcomesh : me, loc, size);
549 madd_v3_v3v3v3(values, loc, orco[(mvert - me->mvert)], size);
550 }
551 else {
552 copy_v3_v3(values, mvert->co);
553 }
554 }
555
rna_CustomDataLayer_active_get(PointerRNA * ptr,CustomData * data,int type,bool render)556 static int rna_CustomDataLayer_active_get(PointerRNA *ptr, CustomData *data, int type, bool render)
557 {
558 int n = ((CustomDataLayer *)ptr->data) - data->layers;
559
560 if (render) {
561 return (n == CustomData_get_render_layer_index(data, type));
562 }
563 else {
564 return (n == CustomData_get_active_layer_index(data, type));
565 }
566 }
567
rna_CustomDataLayer_clone_get(PointerRNA * ptr,CustomData * data,int type)568 static int rna_CustomDataLayer_clone_get(PointerRNA *ptr, CustomData *data, int type)
569 {
570 int n = ((CustomDataLayer *)ptr->data) - data->layers;
571
572 return (n == CustomData_get_clone_layer_index(data, type));
573 }
574
rna_CustomDataLayer_active_set(PointerRNA * ptr,CustomData * data,int value,int type,int render)575 static void rna_CustomDataLayer_active_set(
576 PointerRNA *ptr, CustomData *data, int value, int type, int render)
577 {
578 Mesh *me = (Mesh *)ptr->owner_id;
579 int n = (((CustomDataLayer *)ptr->data) - data->layers) - CustomData_get_layer_index(data, type);
580
581 if (value == 0) {
582 return;
583 }
584
585 if (render) {
586 CustomData_set_layer_render(data, type, n);
587 }
588 else {
589 CustomData_set_layer_active(data, type, n);
590 }
591
592 BKE_mesh_update_customdata_pointers(me, true);
593 }
594
rna_CustomDataLayer_clone_set(PointerRNA * ptr,CustomData * data,int value,int type)595 static void rna_CustomDataLayer_clone_set(PointerRNA *ptr, CustomData *data, int value, int type)
596 {
597 int n = ((CustomDataLayer *)ptr->data) - data->layers;
598
599 if (value == 0) {
600 return;
601 }
602
603 CustomData_set_layer_clone_index(data, type, n);
604 }
605
rna_MEdge_freestyle_edge_mark_get(PointerRNA * ptr)606 static bool rna_MEdge_freestyle_edge_mark_get(PointerRNA *ptr)
607 {
608 Mesh *me = rna_mesh(ptr);
609 MEdge *medge = (MEdge *)ptr->data;
610 FreestyleEdge *fed = CustomData_get(&me->edata, (int)(medge - me->medge), CD_FREESTYLE_EDGE);
611
612 return fed && (fed->flag & FREESTYLE_EDGE_MARK) != 0;
613 }
614
rna_MEdge_freestyle_edge_mark_set(PointerRNA * ptr,bool value)615 static void rna_MEdge_freestyle_edge_mark_set(PointerRNA *ptr, bool value)
616 {
617 Mesh *me = rna_mesh(ptr);
618 MEdge *medge = (MEdge *)ptr->data;
619 FreestyleEdge *fed = CustomData_get(&me->edata, (int)(medge - me->medge), CD_FREESTYLE_EDGE);
620
621 if (!fed) {
622 fed = CustomData_add_layer(&me->edata, CD_FREESTYLE_EDGE, CD_CALLOC, NULL, me->totedge);
623 }
624 if (value) {
625 fed->flag |= FREESTYLE_EDGE_MARK;
626 }
627 else {
628 fed->flag &= ~FREESTYLE_EDGE_MARK;
629 }
630 }
631
rna_MPoly_freestyle_face_mark_get(PointerRNA * ptr)632 static bool rna_MPoly_freestyle_face_mark_get(PointerRNA *ptr)
633 {
634 Mesh *me = rna_mesh(ptr);
635 MPoly *mpoly = (MPoly *)ptr->data;
636 FreestyleFace *ffa = CustomData_get(&me->pdata, (int)(mpoly - me->mpoly), CD_FREESTYLE_FACE);
637
638 return ffa && (ffa->flag & FREESTYLE_FACE_MARK) != 0;
639 }
640
rna_MPoly_freestyle_face_mark_set(PointerRNA * ptr,int value)641 static void rna_MPoly_freestyle_face_mark_set(PointerRNA *ptr, int value)
642 {
643 Mesh *me = rna_mesh(ptr);
644 MPoly *mpoly = (MPoly *)ptr->data;
645 FreestyleFace *ffa = CustomData_get(&me->pdata, (int)(mpoly - me->mpoly), CD_FREESTYLE_FACE);
646
647 if (!ffa) {
648 ffa = CustomData_add_layer(&me->pdata, CD_FREESTYLE_FACE, CD_CALLOC, NULL, me->totpoly);
649 }
650 if (value) {
651 ffa->flag |= FREESTYLE_FACE_MARK;
652 }
653 else {
654 ffa->flag &= ~FREESTYLE_FACE_MARK;
655 }
656 }
657
658 /* uv_layers */
659
DEFINE_CUSTOMDATA_LAYER_COLLECTION(uv_layer,ldata,CD_MLOOPUV)660 DEFINE_CUSTOMDATA_LAYER_COLLECTION(uv_layer, ldata, CD_MLOOPUV)
661 DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(uv_layer, ldata, CD_MLOOPUV, active, MeshUVLoopLayer)
662 DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(uv_layer, ldata, CD_MLOOPUV, clone, MeshUVLoopLayer)
663 DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(
664 uv_layer, ldata, CD_MLOOPUV, stencil, MeshUVLoopLayer)
665 DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(uv_layer, ldata, CD_MLOOPUV, render, MeshUVLoopLayer)
666
667 /* MeshUVLoopLayer */
668
669 static char *rna_MeshUVLoopLayer_path(PointerRNA *ptr)
670 {
671 CustomDataLayer *cdl = ptr->data;
672 char name_esc[sizeof(cdl->name) * 2];
673 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
674 return BLI_sprintfN("uv_layers[\"%s\"]", name_esc);
675 }
676
rna_MeshUVLoopLayer_data_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)677 static void rna_MeshUVLoopLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
678 {
679 Mesh *me = rna_mesh(ptr);
680 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
681 rna_iterator_array_begin(
682 iter, layer->data, sizeof(MLoopUV), (me->edit_mesh) ? 0 : me->totloop, 0, NULL);
683 }
684
rna_MeshUVLoopLayer_data_length(PointerRNA * ptr)685 static int rna_MeshUVLoopLayer_data_length(PointerRNA *ptr)
686 {
687 Mesh *me = rna_mesh(ptr);
688 return (me->edit_mesh) ? 0 : me->totloop;
689 }
690
rna_MeshUVLoopLayer_active_render_get(PointerRNA * ptr)691 static bool rna_MeshUVLoopLayer_active_render_get(PointerRNA *ptr)
692 {
693 return rna_CustomDataLayer_active_get(ptr, rna_mesh_ldata(ptr), CD_MLOOPUV, 1);
694 }
695
rna_MeshUVLoopLayer_active_get(PointerRNA * ptr)696 static bool rna_MeshUVLoopLayer_active_get(PointerRNA *ptr)
697 {
698 return rna_CustomDataLayer_active_get(ptr, rna_mesh_ldata(ptr), CD_MLOOPUV, 0);
699 }
700
rna_MeshUVLoopLayer_clone_get(PointerRNA * ptr)701 static bool rna_MeshUVLoopLayer_clone_get(PointerRNA *ptr)
702 {
703 return rna_CustomDataLayer_clone_get(ptr, rna_mesh_ldata(ptr), CD_MLOOPUV);
704 }
705
rna_MeshUVLoopLayer_active_render_set(PointerRNA * ptr,bool value)706 static void rna_MeshUVLoopLayer_active_render_set(PointerRNA *ptr, bool value)
707 {
708 rna_CustomDataLayer_active_set(ptr, rna_mesh_ldata(ptr), value, CD_MLOOPUV, 1);
709 }
710
rna_MeshUVLoopLayer_active_set(PointerRNA * ptr,bool value)711 static void rna_MeshUVLoopLayer_active_set(PointerRNA *ptr, bool value)
712 {
713 rna_CustomDataLayer_active_set(ptr, rna_mesh_ldata(ptr), value, CD_MLOOPUV, 0);
714 }
715
rna_MeshUVLoopLayer_clone_set(PointerRNA * ptr,bool value)716 static void rna_MeshUVLoopLayer_clone_set(PointerRNA *ptr, bool value)
717 {
718 rna_CustomDataLayer_clone_set(ptr, rna_mesh_ldata(ptr), value, CD_MLOOPUV);
719 }
720
721 /* vertex_color_layers */
722
DEFINE_CUSTOMDATA_LAYER_COLLECTION(vertex_color,ldata,CD_MLOOPCOL)723 DEFINE_CUSTOMDATA_LAYER_COLLECTION(vertex_color, ldata, CD_MLOOPCOL)
724 DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(
725 vertex_color, ldata, CD_MLOOPCOL, active, MeshLoopColorLayer)
726
727 static void rna_MeshLoopColorLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
728 {
729 Mesh *me = rna_mesh(ptr);
730 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
731 rna_iterator_array_begin(
732 iter, layer->data, sizeof(MLoopCol), (me->edit_mesh) ? 0 : me->totloop, 0, NULL);
733 }
734
rna_MeshLoopColorLayer_data_length(PointerRNA * ptr)735 static int rna_MeshLoopColorLayer_data_length(PointerRNA *ptr)
736 {
737 Mesh *me = rna_mesh(ptr);
738 return (me->edit_mesh) ? 0 : me->totloop;
739 }
740
rna_MeshLoopColorLayer_active_render_get(PointerRNA * ptr)741 static bool rna_MeshLoopColorLayer_active_render_get(PointerRNA *ptr)
742 {
743 return rna_CustomDataLayer_active_get(ptr, rna_mesh_ldata(ptr), CD_MLOOPCOL, 1);
744 }
745
rna_MeshLoopColorLayer_active_get(PointerRNA * ptr)746 static bool rna_MeshLoopColorLayer_active_get(PointerRNA *ptr)
747 {
748 return rna_CustomDataLayer_active_get(ptr, rna_mesh_ldata(ptr), CD_MLOOPCOL, 0);
749 }
750
rna_MeshLoopColorLayer_active_render_set(PointerRNA * ptr,bool value)751 static void rna_MeshLoopColorLayer_active_render_set(PointerRNA *ptr, bool value)
752 {
753 rna_CustomDataLayer_active_set(ptr, rna_mesh_ldata(ptr), value, CD_MLOOPCOL, 1);
754 }
755
rna_MeshLoopColorLayer_active_set(PointerRNA * ptr,bool value)756 static void rna_MeshLoopColorLayer_active_set(PointerRNA *ptr, bool value)
757 {
758 rna_CustomDataLayer_active_set(ptr, rna_mesh_ldata(ptr), value, CD_MLOOPCOL, 0);
759 }
760
761 /* sculpt_vertex_color_layers */
762
DEFINE_CUSTOMDATA_LAYER_COLLECTION(sculpt_vertex_color,vdata,CD_PROP_COLOR)763 DEFINE_CUSTOMDATA_LAYER_COLLECTION(sculpt_vertex_color, vdata, CD_PROP_COLOR)
764 DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(
765 sculpt_vertex_color, vdata, CD_PROP_COLOR, active, MeshVertColorLayer)
766
767 static void rna_MeshVertColorLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
768 {
769 Mesh *me = rna_mesh(ptr);
770 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
771 rna_iterator_array_begin(
772 iter, layer->data, sizeof(MPropCol), (me->edit_mesh) ? 0 : me->totvert, 0, NULL);
773 }
774
rna_MeshVertColorLayer_data_length(PointerRNA * ptr)775 static int rna_MeshVertColorLayer_data_length(PointerRNA *ptr)
776 {
777 Mesh *me = rna_mesh(ptr);
778 return (me->edit_mesh) ? 0 : me->totvert;
779 }
780
rna_MeshVertColorLayer_active_render_get(PointerRNA * ptr)781 static bool rna_MeshVertColorLayer_active_render_get(PointerRNA *ptr)
782 {
783 return rna_CustomDataLayer_active_get(ptr, rna_mesh_vdata(ptr), CD_PROP_COLOR, 1);
784 }
785
rna_MeshVertColorLayer_active_get(PointerRNA * ptr)786 static bool rna_MeshVertColorLayer_active_get(PointerRNA *ptr)
787 {
788 return rna_CustomDataLayer_active_get(ptr, rna_mesh_vdata(ptr), CD_PROP_COLOR, 0);
789 }
790
rna_MeshVertColorLayer_active_render_set(PointerRNA * ptr,bool value)791 static void rna_MeshVertColorLayer_active_render_set(PointerRNA *ptr, bool value)
792 {
793 rna_CustomDataLayer_active_set(ptr, rna_mesh_vdata(ptr), value, CD_PROP_COLOR, 1);
794 }
795
rna_MeshVertColorLayer_active_set(PointerRNA * ptr,bool value)796 static void rna_MeshVertColorLayer_active_set(PointerRNA *ptr, bool value)
797 {
798 rna_CustomDataLayer_active_set(ptr, rna_mesh_vdata(ptr), value, CD_PROP_COLOR, 0);
799 }
800
rna_float_layer_check(CollectionPropertyIterator * UNUSED (iter),void * data)801 static int rna_float_layer_check(CollectionPropertyIterator *UNUSED(iter), void *data)
802 {
803 CustomDataLayer *layer = (CustomDataLayer *)data;
804 return (layer->type != CD_PROP_FLOAT);
805 }
806
rna_Mesh_vertex_float_layers_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)807 static void rna_Mesh_vertex_float_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
808 {
809 CustomData *vdata = rna_mesh_vdata(ptr);
810 rna_iterator_array_begin(iter,
811 (void *)vdata->layers,
812 sizeof(CustomDataLayer),
813 vdata->totlayer,
814 0,
815 rna_float_layer_check);
816 }
rna_Mesh_polygon_float_layers_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)817 static void rna_Mesh_polygon_float_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
818 {
819 CustomData *pdata = rna_mesh_pdata(ptr);
820 rna_iterator_array_begin(iter,
821 (void *)pdata->layers,
822 sizeof(CustomDataLayer),
823 pdata->totlayer,
824 0,
825 rna_float_layer_check);
826 }
827
rna_Mesh_vertex_float_layers_length(PointerRNA * ptr)828 static int rna_Mesh_vertex_float_layers_length(PointerRNA *ptr)
829 {
830 return CustomData_number_of_layers(rna_mesh_vdata(ptr), CD_PROP_FLOAT);
831 }
rna_Mesh_polygon_float_layers_length(PointerRNA * ptr)832 static int rna_Mesh_polygon_float_layers_length(PointerRNA *ptr)
833 {
834 return CustomData_number_of_layers(rna_mesh_pdata(ptr), CD_PROP_FLOAT);
835 }
836
rna_int_layer_check(CollectionPropertyIterator * UNUSED (iter),void * data)837 static int rna_int_layer_check(CollectionPropertyIterator *UNUSED(iter), void *data)
838 {
839 CustomDataLayer *layer = (CustomDataLayer *)data;
840 return (layer->type != CD_PROP_INT32);
841 }
842
rna_Mesh_vertex_int_layers_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)843 static void rna_Mesh_vertex_int_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
844 {
845 CustomData *vdata = rna_mesh_vdata(ptr);
846 rna_iterator_array_begin(iter,
847 (void *)vdata->layers,
848 sizeof(CustomDataLayer),
849 vdata->totlayer,
850 0,
851 rna_int_layer_check);
852 }
rna_Mesh_polygon_int_layers_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)853 static void rna_Mesh_polygon_int_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
854 {
855 CustomData *pdata = rna_mesh_pdata(ptr);
856 rna_iterator_array_begin(iter,
857 (void *)pdata->layers,
858 sizeof(CustomDataLayer),
859 pdata->totlayer,
860 0,
861 rna_int_layer_check);
862 }
863
rna_Mesh_vertex_int_layers_length(PointerRNA * ptr)864 static int rna_Mesh_vertex_int_layers_length(PointerRNA *ptr)
865 {
866 return CustomData_number_of_layers(rna_mesh_vdata(ptr), CD_PROP_INT32);
867 }
rna_Mesh_polygon_int_layers_length(PointerRNA * ptr)868 static int rna_Mesh_polygon_int_layers_length(PointerRNA *ptr)
869 {
870 return CustomData_number_of_layers(rna_mesh_pdata(ptr), CD_PROP_INT32);
871 }
872
rna_string_layer_check(CollectionPropertyIterator * UNUSED (iter),void * data)873 static int rna_string_layer_check(CollectionPropertyIterator *UNUSED(iter), void *data)
874 {
875 CustomDataLayer *layer = (CustomDataLayer *)data;
876 return (layer->type != CD_PROP_STRING);
877 }
878
rna_Mesh_vertex_string_layers_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)879 static void rna_Mesh_vertex_string_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
880 {
881 CustomData *vdata = rna_mesh_vdata(ptr);
882 rna_iterator_array_begin(iter,
883 (void *)vdata->layers,
884 sizeof(CustomDataLayer),
885 vdata->totlayer,
886 0,
887 rna_string_layer_check);
888 }
rna_Mesh_polygon_string_layers_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)889 static void rna_Mesh_polygon_string_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
890 {
891 CustomData *pdata = rna_mesh_pdata(ptr);
892 rna_iterator_array_begin(iter,
893 (void *)pdata->layers,
894 sizeof(CustomDataLayer),
895 pdata->totlayer,
896 0,
897 rna_string_layer_check);
898 }
899
rna_Mesh_vertex_string_layers_length(PointerRNA * ptr)900 static int rna_Mesh_vertex_string_layers_length(PointerRNA *ptr)
901 {
902 return CustomData_number_of_layers(rna_mesh_vdata(ptr), CD_PROP_STRING);
903 }
rna_Mesh_polygon_string_layers_length(PointerRNA * ptr)904 static int rna_Mesh_polygon_string_layers_length(PointerRNA *ptr)
905 {
906 return CustomData_number_of_layers(rna_mesh_pdata(ptr), CD_PROP_STRING);
907 }
908
909 /* Skin vertices */
DEFINE_CUSTOMDATA_LAYER_COLLECTION(skin_vertice,vdata,CD_MVERT_SKIN)910 DEFINE_CUSTOMDATA_LAYER_COLLECTION(skin_vertice, vdata, CD_MVERT_SKIN)
911
912 static char *rna_MeshSkinVertexLayer_path(PointerRNA *ptr)
913 {
914 CustomDataLayer *cdl = ptr->data;
915 char name_esc[sizeof(cdl->name) * 2];
916 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
917 return BLI_sprintfN("skin_vertices[\"%s\"]", name_esc);
918 }
919
920 static char *rna_VertCustomData_data_path(PointerRNA *ptr, const char *collection, int type);
rna_MeshSkinVertex_path(PointerRNA * ptr)921 static char *rna_MeshSkinVertex_path(PointerRNA *ptr)
922 {
923 return rna_VertCustomData_data_path(ptr, "skin_vertices", CD_MVERT_SKIN);
924 }
925
rna_MeshSkinVertexLayer_data_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)926 static void rna_MeshSkinVertexLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
927 {
928 Mesh *me = rna_mesh(ptr);
929 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
930 rna_iterator_array_begin(iter, layer->data, sizeof(MVertSkin), me->totvert, 0, NULL);
931 }
932
rna_MeshSkinVertexLayer_data_length(PointerRNA * ptr)933 static int rna_MeshSkinVertexLayer_data_length(PointerRNA *ptr)
934 {
935 Mesh *me = rna_mesh(ptr);
936 return me->totvert;
937 }
938
939 /* End skin vertices */
940
941 /* Paint mask */
DEFINE_CUSTOMDATA_LAYER_COLLECTION(vertex_paint_mask,vdata,CD_PAINT_MASK)942 DEFINE_CUSTOMDATA_LAYER_COLLECTION(vertex_paint_mask, vdata, CD_PAINT_MASK)
943
944 static char *rna_MeshPaintMaskLayer_path(PointerRNA *ptr)
945 {
946 CustomDataLayer *cdl = ptr->data;
947 char name_esc[sizeof(cdl->name) * 2];
948 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
949 return BLI_sprintfN("vertex_paint_masks[\"%s\"]", name_esc);
950 }
951
rna_MeshPaintMask_path(PointerRNA * ptr)952 static char *rna_MeshPaintMask_path(PointerRNA *ptr)
953 {
954 return rna_VertCustomData_data_path(ptr, "vertex_paint_masks", CD_PAINT_MASK);
955 }
956
rna_MeshPaintMaskLayer_data_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)957 static void rna_MeshPaintMaskLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
958 {
959 Mesh *me = rna_mesh(ptr);
960 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
961 rna_iterator_array_begin(iter, layer->data, sizeof(MFloatProperty), me->totvert, 0, NULL);
962 }
963
rna_MeshPaintMaskLayer_data_length(PointerRNA * ptr)964 static int rna_MeshPaintMaskLayer_data_length(PointerRNA *ptr)
965 {
966 Mesh *me = rna_mesh(ptr);
967 return me->totvert;
968 }
969
970 /* End paint mask */
971
972 /* Face maps */
973
DEFINE_CUSTOMDATA_LAYER_COLLECTION(face_map,pdata,CD_FACEMAP)974 DEFINE_CUSTOMDATA_LAYER_COLLECTION(face_map, pdata, CD_FACEMAP)
975 DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(
976 face_map, pdata, CD_FACEMAP, active, MeshFaceMapLayer)
977
978 static char *rna_MeshFaceMapLayer_path(PointerRNA *ptr)
979 {
980 CustomDataLayer *cdl = ptr->data;
981 char name_esc[sizeof(cdl->name) * 2];
982 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
983 return BLI_sprintfN("face_maps[\"%s\"]", name_esc);
984 }
985
rna_MeshFaceMapLayer_data_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)986 static void rna_MeshFaceMapLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
987 {
988 Mesh *me = rna_mesh(ptr);
989 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
990 rna_iterator_array_begin(iter, layer->data, sizeof(int), me->totpoly, 0, NULL);
991 }
992
rna_MeshFaceMapLayer_data_length(PointerRNA * ptr)993 static int rna_MeshFaceMapLayer_data_length(PointerRNA *ptr)
994 {
995 Mesh *me = rna_mesh(ptr);
996 return me->totpoly;
997 }
998
rna_Mesh_face_map_new(struct Mesh * me,ReportList * reports,const char * name)999 static PointerRNA rna_Mesh_face_map_new(struct Mesh *me, ReportList *reports, const char *name)
1000 {
1001 if (BKE_mesh_ensure_facemap_customdata(me) == false) {
1002 BKE_report(reports, RPT_ERROR, "Currently only single face-map layers are supported");
1003 return PointerRNA_NULL;
1004 }
1005
1006 CustomData *pdata = rna_mesh_pdata_helper(me);
1007
1008 int index = CustomData_get_layer_index(pdata, CD_FACEMAP);
1009 BLI_assert(index != -1);
1010 CustomDataLayer *cdl = &pdata->layers[index];
1011 rna_cd_layer_name_set(pdata, cdl, name);
1012
1013 PointerRNA ptr;
1014 RNA_pointer_create(&me->id, &RNA_MeshFaceMapLayer, cdl, &ptr);
1015 return ptr;
1016 }
1017
rna_Mesh_face_map_remove(struct Mesh * me,ReportList * reports,struct CustomDataLayer * layer)1018 static void rna_Mesh_face_map_remove(struct Mesh *me,
1019 ReportList *reports,
1020 struct CustomDataLayer *layer)
1021 {
1022 /* just for sanity check */
1023 {
1024 CustomData *pdata = rna_mesh_pdata_helper(me);
1025 int index = CustomData_get_layer_index(pdata, CD_FACEMAP);
1026 if (index != -1) {
1027 CustomDataLayer *layer_test = &pdata->layers[index];
1028 if (layer != layer_test) {
1029 /* don't show name, its likely freed memory */
1030 BKE_report(reports, RPT_ERROR, "FaceMap not in mesh");
1031 return;
1032 }
1033 }
1034 }
1035
1036 if (BKE_mesh_clear_facemap_customdata(me) == false) {
1037 BKE_report(reports, RPT_ERROR, "Error removing face-map");
1038 }
1039 }
1040
1041 /* End face maps */
1042
1043 /* poly.vertices - this is faked loop access for convenience */
rna_MeshPoly_vertices_get_length(PointerRNA * ptr,int length[RNA_MAX_ARRAY_DIMENSION])1044 static int rna_MeshPoly_vertices_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
1045 {
1046 MPoly *mp = (MPoly *)ptr->data;
1047 /* note, raw access uses dummy item, this _could_ crash,
1048 * watch out for this, mface uses it but it cant work here. */
1049 return (length[0] = mp->totloop);
1050 }
1051
rna_MeshPoly_vertices_get(PointerRNA * ptr,int * values)1052 static void rna_MeshPoly_vertices_get(PointerRNA *ptr, int *values)
1053 {
1054 Mesh *me = rna_mesh(ptr);
1055 MPoly *mp = (MPoly *)ptr->data;
1056 MLoop *ml = &me->mloop[mp->loopstart];
1057 unsigned int i;
1058 for (i = mp->totloop; i > 0; i--, values++, ml++) {
1059 *values = ml->v;
1060 }
1061 }
1062
rna_MeshPoly_vertices_set(PointerRNA * ptr,const int * values)1063 static void rna_MeshPoly_vertices_set(PointerRNA *ptr, const int *values)
1064 {
1065 Mesh *me = rna_mesh(ptr);
1066 MPoly *mp = (MPoly *)ptr->data;
1067 MLoop *ml = &me->mloop[mp->loopstart];
1068 unsigned int i;
1069 for (i = mp->totloop; i > 0; i--, values++, ml++) {
1070 ml->v = *values;
1071 }
1072 }
1073
1074 /* disabling, some importers don't know the total material count when assigning materials */
1075 # if 0
1076 static void rna_MeshPoly_material_index_range(
1077 PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
1078 {
1079 Mesh *me = rna_mesh(ptr);
1080 *min = 0;
1081 *max = max_ii(0, me->totcol - 1);
1082 }
1083 # endif
1084
rna_MeshVertex_index_get(PointerRNA * ptr)1085 static int rna_MeshVertex_index_get(PointerRNA *ptr)
1086 {
1087 Mesh *me = rna_mesh(ptr);
1088 MVert *vert = (MVert *)ptr->data;
1089 return (int)(vert - me->mvert);
1090 }
1091
rna_MeshEdge_index_get(PointerRNA * ptr)1092 static int rna_MeshEdge_index_get(PointerRNA *ptr)
1093 {
1094 Mesh *me = rna_mesh(ptr);
1095 MEdge *edge = (MEdge *)ptr->data;
1096 return (int)(edge - me->medge);
1097 }
1098
rna_MeshLoopTriangle_index_get(PointerRNA * ptr)1099 static int rna_MeshLoopTriangle_index_get(PointerRNA *ptr)
1100 {
1101 Mesh *me = rna_mesh(ptr);
1102 MLoopTri *ltri = (MLoopTri *)ptr->data;
1103 return (int)(ltri - me->runtime.looptris.array);
1104 }
1105
rna_MeshLoopTriangle_material_index_get(PointerRNA * ptr)1106 static int rna_MeshLoopTriangle_material_index_get(PointerRNA *ptr)
1107 {
1108 Mesh *me = rna_mesh(ptr);
1109 MLoopTri *ltri = (MLoopTri *)ptr->data;
1110 return me->mpoly[ltri->poly].mat_nr;
1111 }
1112
rna_MeshLoopTriangle_use_smooth_get(PointerRNA * ptr)1113 static bool rna_MeshLoopTriangle_use_smooth_get(PointerRNA *ptr)
1114 {
1115 Mesh *me = rna_mesh(ptr);
1116 MLoopTri *ltri = (MLoopTri *)ptr->data;
1117 return me->mpoly[ltri->poly].flag & ME_SMOOTH;
1118 }
1119
rna_MeshPolygon_index_get(PointerRNA * ptr)1120 static int rna_MeshPolygon_index_get(PointerRNA *ptr)
1121 {
1122 Mesh *me = rna_mesh(ptr);
1123 MPoly *mpoly = (MPoly *)ptr->data;
1124 return (int)(mpoly - me->mpoly);
1125 }
1126
rna_MeshLoop_index_get(PointerRNA * ptr)1127 static int rna_MeshLoop_index_get(PointerRNA *ptr)
1128 {
1129 Mesh *me = rna_mesh(ptr);
1130 MLoop *mloop = (MLoop *)ptr->data;
1131 return (int)(mloop - me->mloop);
1132 }
1133
1134 /* path construction */
1135
rna_VertexGroupElement_path(PointerRNA * ptr)1136 static char *rna_VertexGroupElement_path(PointerRNA *ptr)
1137 {
1138 Mesh *me = rna_mesh(ptr); /* XXX not always! */
1139 MDeformWeight *dw = (MDeformWeight *)ptr->data;
1140 MDeformVert *dvert;
1141 int a, b;
1142
1143 for (a = 0, dvert = me->dvert; a < me->totvert; a++, dvert++) {
1144 for (b = 0; b < dvert->totweight; b++) {
1145 if (dw == &dvert->dw[b]) {
1146 return BLI_sprintfN("vertices[%d].groups[%d]", a, b);
1147 }
1148 }
1149 }
1150
1151 return NULL;
1152 }
1153
rna_MeshPolygon_path(PointerRNA * ptr)1154 static char *rna_MeshPolygon_path(PointerRNA *ptr)
1155 {
1156 return BLI_sprintfN("polygons[%d]", (int)((MPoly *)ptr->data - rna_mesh(ptr)->mpoly));
1157 }
1158
rna_MeshLoopTriangle_path(PointerRNA * ptr)1159 static char *rna_MeshLoopTriangle_path(PointerRNA *ptr)
1160 {
1161 return BLI_sprintfN("loop_triangles[%d]",
1162 (int)((MLoopTri *)ptr->data - rna_mesh(ptr)->runtime.looptris.array));
1163 }
1164
rna_MeshEdge_path(PointerRNA * ptr)1165 static char *rna_MeshEdge_path(PointerRNA *ptr)
1166 {
1167 return BLI_sprintfN("edges[%d]", (int)((MEdge *)ptr->data - rna_mesh(ptr)->medge));
1168 }
1169
rna_MeshLoop_path(PointerRNA * ptr)1170 static char *rna_MeshLoop_path(PointerRNA *ptr)
1171 {
1172 return BLI_sprintfN("loops[%d]", (int)((MLoop *)ptr->data - rna_mesh(ptr)->mloop));
1173 }
1174
rna_MeshVertex_path(PointerRNA * ptr)1175 static char *rna_MeshVertex_path(PointerRNA *ptr)
1176 {
1177 return BLI_sprintfN("vertices[%d]", (int)((MVert *)ptr->data - rna_mesh(ptr)->mvert));
1178 }
1179
rna_VertCustomData_data_path(PointerRNA * ptr,const char * collection,int type)1180 static char *rna_VertCustomData_data_path(PointerRNA *ptr, const char *collection, int type)
1181 {
1182 CustomDataLayer *cdl;
1183 Mesh *me = rna_mesh(ptr);
1184 CustomData *vdata = rna_mesh_vdata(ptr);
1185 int a, b, totvert = (me->edit_mesh) ? 0 : me->totvert;
1186
1187 for (cdl = vdata->layers, a = 0; a < vdata->totlayer; cdl++, a++) {
1188 if (cdl->type == type) {
1189 b = ((char *)ptr->data - ((char *)cdl->data)) / CustomData_sizeof(type);
1190 if (b >= 0 && b < totvert) {
1191 char name_esc[sizeof(cdl->name) * 2];
1192 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1193 return BLI_sprintfN("%s[\"%s\"].data[%d]", collection, name_esc, b);
1194 }
1195 }
1196 }
1197
1198 return NULL;
1199 }
1200
rna_PolyCustomData_data_path(PointerRNA * ptr,const char * collection,int type)1201 static char *rna_PolyCustomData_data_path(PointerRNA *ptr, const char *collection, int type)
1202 {
1203 CustomDataLayer *cdl;
1204 Mesh *me = rna_mesh(ptr);
1205 CustomData *pdata = rna_mesh_pdata(ptr);
1206 int a, b, totpoly = (me->edit_mesh) ? 0 : me->totpoly;
1207
1208 for (cdl = pdata->layers, a = 0; a < pdata->totlayer; cdl++, a++) {
1209 if (cdl->type == type) {
1210 b = ((char *)ptr->data - ((char *)cdl->data)) / CustomData_sizeof(type);
1211 if (b >= 0 && b < totpoly) {
1212 char name_esc[sizeof(cdl->name) * 2];
1213 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1214 return BLI_sprintfN("%s[\"%s\"].data[%d]", collection, name_esc, b);
1215 }
1216 }
1217 }
1218
1219 return NULL;
1220 }
1221
rna_LoopCustomData_data_path(PointerRNA * ptr,const char * collection,int type)1222 static char *rna_LoopCustomData_data_path(PointerRNA *ptr, const char *collection, int type)
1223 {
1224 CustomDataLayer *cdl;
1225 Mesh *me = rna_mesh(ptr);
1226 CustomData *ldata = rna_mesh_ldata(ptr);
1227 int a, b, totloop = (me->edit_mesh) ? 0 : me->totloop;
1228
1229 for (cdl = ldata->layers, a = 0; a < ldata->totlayer; cdl++, a++) {
1230 if (cdl->type == type) {
1231 b = ((char *)ptr->data - ((char *)cdl->data)) / CustomData_sizeof(type);
1232 if (b >= 0 && b < totloop) {
1233 char name_esc[sizeof(cdl->name) * 2];
1234 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1235 return BLI_sprintfN("%s[\"%s\"].data[%d]", collection, name_esc, b);
1236 }
1237 }
1238 }
1239
1240 return NULL;
1241 }
1242
rna_MeshUVLoop_path(PointerRNA * ptr)1243 static char *rna_MeshUVLoop_path(PointerRNA *ptr)
1244 {
1245 return rna_LoopCustomData_data_path(ptr, "uv_layers", CD_MLOOPUV);
1246 }
1247
rna_MeshLoopColorLayer_path(PointerRNA * ptr)1248 static char *rna_MeshLoopColorLayer_path(PointerRNA *ptr)
1249 {
1250 CustomDataLayer *cdl = ptr->data;
1251 char name_esc[sizeof(cdl->name) * 2];
1252 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1253 return BLI_sprintfN("vertex_colors[\"%s\"]", name_esc);
1254 }
1255
rna_MeshColor_path(PointerRNA * ptr)1256 static char *rna_MeshColor_path(PointerRNA *ptr)
1257 {
1258 return rna_LoopCustomData_data_path(ptr, "vertex_colors", CD_MLOOPCOL);
1259 }
1260
rna_MeshVertColorLayer_path(PointerRNA * ptr)1261 static char *rna_MeshVertColorLayer_path(PointerRNA *ptr)
1262 {
1263 CustomDataLayer *cdl = ptr->data;
1264 char name_esc[sizeof(cdl->name) * 2];
1265 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1266 return BLI_sprintfN("sculpt_vertex_colors[\"%s\"]", name_esc);
1267 }
1268
rna_MeshVertColor_path(PointerRNA * ptr)1269 static char *rna_MeshVertColor_path(PointerRNA *ptr)
1270 {
1271 return rna_VertCustomData_data_path(ptr, "sculpt_vertex_colors", CD_PROP_COLOR);
1272 }
1273
1274 /**** Float Property Layer API ****/
rna_MeshVertexFloatPropertyLayer_path(PointerRNA * ptr)1275 static char *rna_MeshVertexFloatPropertyLayer_path(PointerRNA *ptr)
1276 {
1277 CustomDataLayer *cdl = ptr->data;
1278 char name_esc[sizeof(cdl->name) * 2];
1279 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1280 return BLI_sprintfN("vertex_float_layers[\"%s\"]", name_esc);
1281 }
rna_MeshPolygonFloatPropertyLayer_path(PointerRNA * ptr)1282 static char *rna_MeshPolygonFloatPropertyLayer_path(PointerRNA *ptr)
1283 {
1284 CustomDataLayer *cdl = ptr->data;
1285 char name_esc[sizeof(cdl->name) * 2];
1286 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1287 return BLI_sprintfN("polygon_float_layers[\"%s\"]", name_esc);
1288 }
1289
rna_MeshVertexFloatProperty_path(PointerRNA * ptr)1290 static char *rna_MeshVertexFloatProperty_path(PointerRNA *ptr)
1291 {
1292 return rna_VertCustomData_data_path(ptr, "vertex_layers_float", CD_PROP_FLOAT);
1293 }
rna_MeshPolygonFloatProperty_path(PointerRNA * ptr)1294 static char *rna_MeshPolygonFloatProperty_path(PointerRNA *ptr)
1295 {
1296 return rna_PolyCustomData_data_path(ptr, "polygon_layers_float", CD_PROP_FLOAT);
1297 }
1298
rna_MeshVertexFloatPropertyLayer_data_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)1299 static void rna_MeshVertexFloatPropertyLayer_data_begin(CollectionPropertyIterator *iter,
1300 PointerRNA *ptr)
1301 {
1302 Mesh *me = rna_mesh(ptr);
1303 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
1304 rna_iterator_array_begin(iter, layer->data, sizeof(MFloatProperty), me->totvert, 0, NULL);
1305 }
rna_MeshPolygonFloatPropertyLayer_data_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)1306 static void rna_MeshPolygonFloatPropertyLayer_data_begin(CollectionPropertyIterator *iter,
1307 PointerRNA *ptr)
1308 {
1309 Mesh *me = rna_mesh(ptr);
1310 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
1311 rna_iterator_array_begin(iter, layer->data, sizeof(MFloatProperty), me->totpoly, 0, NULL);
1312 }
1313
rna_MeshVertexFloatPropertyLayer_data_length(PointerRNA * ptr)1314 static int rna_MeshVertexFloatPropertyLayer_data_length(PointerRNA *ptr)
1315 {
1316 Mesh *me = rna_mesh(ptr);
1317 return me->totvert;
1318 }
rna_MeshPolygonFloatPropertyLayer_data_length(PointerRNA * ptr)1319 static int rna_MeshPolygonFloatPropertyLayer_data_length(PointerRNA *ptr)
1320 {
1321 Mesh *me = rna_mesh(ptr);
1322 return me->totpoly;
1323 }
1324
1325 /**** Int Property Layer API ****/
rna_MeshVertexIntPropertyLayer_path(PointerRNA * ptr)1326 static char *rna_MeshVertexIntPropertyLayer_path(PointerRNA *ptr)
1327 {
1328 CustomDataLayer *cdl = ptr->data;
1329 char name_esc[sizeof(cdl->name) * 2];
1330 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1331 return BLI_sprintfN("vertex_int_layers[\"%s\"]", name_esc);
1332 }
rna_MeshPolygonIntPropertyLayer_path(PointerRNA * ptr)1333 static char *rna_MeshPolygonIntPropertyLayer_path(PointerRNA *ptr)
1334 {
1335 CustomDataLayer *cdl = ptr->data;
1336 char name_esc[sizeof(cdl->name) * 2];
1337 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1338 return BLI_sprintfN("polygon_int_layers[\"%s\"]", name_esc);
1339 }
1340
rna_MeshVertexIntProperty_path(PointerRNA * ptr)1341 static char *rna_MeshVertexIntProperty_path(PointerRNA *ptr)
1342 {
1343 return rna_VertCustomData_data_path(ptr, "vertex_layers_int", CD_PROP_INT32);
1344 }
rna_MeshPolygonIntProperty_path(PointerRNA * ptr)1345 static char *rna_MeshPolygonIntProperty_path(PointerRNA *ptr)
1346 {
1347 return rna_PolyCustomData_data_path(ptr, "polygon_layers_int", CD_PROP_INT32);
1348 }
1349
rna_MeshVertexIntPropertyLayer_data_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)1350 static void rna_MeshVertexIntPropertyLayer_data_begin(CollectionPropertyIterator *iter,
1351 PointerRNA *ptr)
1352 {
1353 Mesh *me = rna_mesh(ptr);
1354 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
1355 rna_iterator_array_begin(iter, layer->data, sizeof(MIntProperty), me->totvert, 0, NULL);
1356 }
rna_MeshPolygonIntPropertyLayer_data_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)1357 static void rna_MeshPolygonIntPropertyLayer_data_begin(CollectionPropertyIterator *iter,
1358 PointerRNA *ptr)
1359 {
1360 Mesh *me = rna_mesh(ptr);
1361 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
1362 rna_iterator_array_begin(iter, layer->data, sizeof(MIntProperty), me->totpoly, 0, NULL);
1363 }
1364
rna_MeshVertexIntPropertyLayer_data_length(PointerRNA * ptr)1365 static int rna_MeshVertexIntPropertyLayer_data_length(PointerRNA *ptr)
1366 {
1367 Mesh *me = rna_mesh(ptr);
1368 return me->totvert;
1369 }
rna_MeshPolygonIntPropertyLayer_data_length(PointerRNA * ptr)1370 static int rna_MeshPolygonIntPropertyLayer_data_length(PointerRNA *ptr)
1371 {
1372 Mesh *me = rna_mesh(ptr);
1373 return me->totpoly;
1374 }
1375
1376 /**** String Property Layer API ****/
rna_MeshVertexStringPropertyLayer_path(PointerRNA * ptr)1377 static char *rna_MeshVertexStringPropertyLayer_path(PointerRNA *ptr)
1378 {
1379 CustomDataLayer *cdl = ptr->data;
1380 char name_esc[sizeof(cdl->name) * 2];
1381 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1382 return BLI_sprintfN("vertex_string_layers[\"%s\"]", name_esc);
1383 }
rna_MeshPolygonStringPropertyLayer_path(PointerRNA * ptr)1384 static char *rna_MeshPolygonStringPropertyLayer_path(PointerRNA *ptr)
1385 {
1386 CustomDataLayer *cdl = ptr->data;
1387 char name_esc[sizeof(cdl->name) * 2];
1388 BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
1389 return BLI_sprintfN("polygon_string_layers[\"%s\"]", name_esc);
1390 }
1391
rna_MeshVertexStringProperty_path(PointerRNA * ptr)1392 static char *rna_MeshVertexStringProperty_path(PointerRNA *ptr)
1393 {
1394 return rna_VertCustomData_data_path(ptr, "vertex_layers_string", CD_PROP_STRING);
1395 }
rna_MeshPolygonStringProperty_path(PointerRNA * ptr)1396 static char *rna_MeshPolygonStringProperty_path(PointerRNA *ptr)
1397 {
1398 return rna_PolyCustomData_data_path(ptr, "polygon_layers_string", CD_PROP_STRING);
1399 }
1400
rna_MeshVertexStringPropertyLayer_data_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)1401 static void rna_MeshVertexStringPropertyLayer_data_begin(CollectionPropertyIterator *iter,
1402 PointerRNA *ptr)
1403 {
1404 Mesh *me = rna_mesh(ptr);
1405 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
1406 rna_iterator_array_begin(iter, layer->data, sizeof(MStringProperty), me->totvert, 0, NULL);
1407 }
rna_MeshPolygonStringPropertyLayer_data_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)1408 static void rna_MeshPolygonStringPropertyLayer_data_begin(CollectionPropertyIterator *iter,
1409 PointerRNA *ptr)
1410 {
1411 Mesh *me = rna_mesh(ptr);
1412 CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
1413 rna_iterator_array_begin(iter, layer->data, sizeof(MStringProperty), me->totpoly, 0, NULL);
1414 }
1415
rna_MeshVertexStringPropertyLayer_data_length(PointerRNA * ptr)1416 static int rna_MeshVertexStringPropertyLayer_data_length(PointerRNA *ptr)
1417 {
1418 Mesh *me = rna_mesh(ptr);
1419 return me->totvert;
1420 }
rna_MeshPolygonStringPropertyLayer_data_length(PointerRNA * ptr)1421 static int rna_MeshPolygonStringPropertyLayer_data_length(PointerRNA *ptr)
1422 {
1423 Mesh *me = rna_mesh(ptr);
1424 return me->totpoly;
1425 }
1426
1427 /* XXX, we dont have proper byte string support yet, so for now use the (bytes + 1)
1428 * bmesh API exposes correct python/byte-string access. */
rna_MeshStringProperty_s_get(PointerRNA * ptr,char * value)1429 void rna_MeshStringProperty_s_get(PointerRNA *ptr, char *value)
1430 {
1431 MStringProperty *ms = (MStringProperty *)ptr->data;
1432 BLI_strncpy(value, ms->s, (int)ms->s_len + 1);
1433 }
1434
rna_MeshStringProperty_s_length(PointerRNA * ptr)1435 int rna_MeshStringProperty_s_length(PointerRNA *ptr)
1436 {
1437 MStringProperty *ms = (MStringProperty *)ptr->data;
1438 return (int)ms->s_len + 1;
1439 }
1440
rna_MeshStringProperty_s_set(PointerRNA * ptr,const char * value)1441 void rna_MeshStringProperty_s_set(PointerRNA *ptr, const char *value)
1442 {
1443 MStringProperty *ms = (MStringProperty *)ptr->data;
1444 BLI_strncpy(ms->s, value, sizeof(ms->s));
1445 }
1446
rna_MeshFaceMap_path(PointerRNA * ptr)1447 static char *rna_MeshFaceMap_path(PointerRNA *ptr)
1448 {
1449 return rna_PolyCustomData_data_path(ptr, "face_maps", CD_FACEMAP);
1450 }
1451
1452 /***************************************/
1453
rna_Mesh_tot_vert_get(PointerRNA * ptr)1454 static int rna_Mesh_tot_vert_get(PointerRNA *ptr)
1455 {
1456 Mesh *me = rna_mesh(ptr);
1457 return me->edit_mesh ? me->edit_mesh->bm->totvertsel : 0;
1458 }
rna_Mesh_tot_edge_get(PointerRNA * ptr)1459 static int rna_Mesh_tot_edge_get(PointerRNA *ptr)
1460 {
1461 Mesh *me = rna_mesh(ptr);
1462 return me->edit_mesh ? me->edit_mesh->bm->totedgesel : 0;
1463 }
rna_Mesh_tot_face_get(PointerRNA * ptr)1464 static int rna_Mesh_tot_face_get(PointerRNA *ptr)
1465 {
1466 Mesh *me = rna_mesh(ptr);
1467 return me->edit_mesh ? me->edit_mesh->bm->totfacesel : 0;
1468 }
1469
rna_Mesh_vertex_color_new(struct Mesh * me,const char * name,const bool do_init)1470 static PointerRNA rna_Mesh_vertex_color_new(struct Mesh *me, const char *name, const bool do_init)
1471 {
1472 PointerRNA ptr;
1473 CustomData *ldata;
1474 CustomDataLayer *cdl = NULL;
1475 int index = ED_mesh_color_add(me, name, false, do_init);
1476
1477 if (index != -1) {
1478 ldata = rna_mesh_ldata_helper(me);
1479 cdl = &ldata->layers[CustomData_get_layer_index_n(ldata, CD_MLOOPCOL, index)];
1480 }
1481
1482 RNA_pointer_create(&me->id, &RNA_MeshLoopColorLayer, cdl, &ptr);
1483 return ptr;
1484 }
1485
rna_Mesh_vertex_color_remove(struct Mesh * me,ReportList * reports,CustomDataLayer * layer)1486 static void rna_Mesh_vertex_color_remove(struct Mesh *me,
1487 ReportList *reports,
1488 CustomDataLayer *layer)
1489 {
1490 if (ED_mesh_color_remove_named(me, layer->name) == false) {
1491 BKE_reportf(reports, RPT_ERROR, "Vertex color '%s' not found", layer->name);
1492 }
1493 }
1494
rna_Mesh_sculpt_vertex_color_new(struct Mesh * me,const char * name,const bool do_init)1495 static PointerRNA rna_Mesh_sculpt_vertex_color_new(struct Mesh *me,
1496 const char *name,
1497 const bool do_init)
1498 {
1499 PointerRNA ptr;
1500 CustomData *vdata;
1501 CustomDataLayer *cdl = NULL;
1502 int index = ED_mesh_sculpt_color_add(me, name, false, do_init);
1503
1504 if (index != -1) {
1505 vdata = rna_mesh_vdata_helper(me);
1506 cdl = &vdata->layers[CustomData_get_layer_index_n(vdata, CD_PROP_COLOR, index)];
1507 }
1508
1509 RNA_pointer_create(&me->id, &RNA_MeshVertColorLayer, cdl, &ptr);
1510 return ptr;
1511 }
1512
rna_Mesh_sculpt_vertex_color_remove(struct Mesh * me,ReportList * reports,CustomDataLayer * layer)1513 static void rna_Mesh_sculpt_vertex_color_remove(struct Mesh *me,
1514 ReportList *reports,
1515 CustomDataLayer *layer)
1516 {
1517 if (ED_mesh_sculpt_color_remove_named(me, layer->name) == false) {
1518 BKE_reportf(reports, RPT_ERROR, "Sculpt vertex color '%s' not found", layer->name);
1519 }
1520 }
1521
1522 # define DEFINE_CUSTOMDATA_PROPERTY_API( \
1523 elemname, datatype, cd_prop_type, cdata, countvar, layertype) \
1524 static PointerRNA rna_Mesh_##elemname##_##datatype##_property_new(struct Mesh *me, \
1525 const char *name) \
1526 { \
1527 PointerRNA ptr; \
1528 CustomDataLayer *cdl = NULL; \
1529 int index; \
1530 \
1531 CustomData_add_layer_named(&me->cdata, cd_prop_type, CD_DEFAULT, NULL, me->countvar, name); \
1532 index = CustomData_get_named_layer_index(&me->cdata, cd_prop_type, name); \
1533 \
1534 cdl = (index == -1) ? NULL : &(me->cdata.layers[index]); \
1535 \
1536 RNA_pointer_create(&me->id, &RNA_##layertype, cdl, &ptr); \
1537 return ptr; \
1538 }
1539
DEFINE_CUSTOMDATA_PROPERTY_API(vertex,float,CD_PROP_FLOAT,vdata,totvert,MeshVertexFloatPropertyLayer)1540 DEFINE_CUSTOMDATA_PROPERTY_API(
1541 vertex, float, CD_PROP_FLOAT, vdata, totvert, MeshVertexFloatPropertyLayer)
1542 DEFINE_CUSTOMDATA_PROPERTY_API(
1543 vertex, int, CD_PROP_INT32, vdata, totvert, MeshVertexIntPropertyLayer)
1544 DEFINE_CUSTOMDATA_PROPERTY_API(
1545 vertex, string, CD_PROP_STRING, vdata, totvert, MeshVertexStringPropertyLayer)
1546 DEFINE_CUSTOMDATA_PROPERTY_API(
1547 polygon, float, CD_PROP_FLOAT, pdata, totpoly, MeshPolygonFloatPropertyLayer)
1548 DEFINE_CUSTOMDATA_PROPERTY_API(
1549 polygon, int, CD_PROP_INT32, pdata, totpoly, MeshPolygonIntPropertyLayer)
1550 DEFINE_CUSTOMDATA_PROPERTY_API(
1551 polygon, string, CD_PROP_STRING, pdata, totpoly, MeshPolygonStringPropertyLayer)
1552 # undef DEFINE_CUSTOMDATA_PROPERTY_API
1553
1554 static PointerRNA rna_Mesh_uv_layers_new(struct Mesh *me, const char *name, const bool do_init)
1555 {
1556 PointerRNA ptr;
1557 CustomData *ldata;
1558 CustomDataLayer *cdl = NULL;
1559 int index = ED_mesh_uv_texture_add(me, name, false, do_init);
1560
1561 if (index != -1) {
1562 ldata = rna_mesh_ldata_helper(me);
1563 cdl = &ldata->layers[CustomData_get_layer_index_n(ldata, CD_MLOOPUV, index)];
1564 }
1565
1566 RNA_pointer_create(&me->id, &RNA_MeshUVLoopLayer, cdl, &ptr);
1567 return ptr;
1568 }
1569
rna_Mesh_uv_layers_remove(struct Mesh * me,ReportList * reports,CustomDataLayer * layer)1570 static void rna_Mesh_uv_layers_remove(struct Mesh *me, ReportList *reports, CustomDataLayer *layer)
1571 {
1572 if (ED_mesh_uv_texture_remove_named(me, layer->name) == false) {
1573 BKE_reportf(reports, RPT_ERROR, "Texture layer '%s' not found", layer->name);
1574 }
1575 }
1576
rna_Mesh_is_editmode_get(PointerRNA * ptr)1577 static bool rna_Mesh_is_editmode_get(PointerRNA *ptr)
1578 {
1579 Mesh *me = rna_mesh(ptr);
1580 return (me->edit_mesh != NULL);
1581 }
1582
1583 /* only to quiet warnings */
UNUSED_FUNCTION(rna_mesh_unused)1584 static void UNUSED_FUNCTION(rna_mesh_unused)(void)
1585 {
1586 /* unused functions made by macros */
1587 (void)rna_Mesh_skin_vertice_index_range;
1588 (void)rna_Mesh_vertex_paint_mask_index_range;
1589 (void)rna_Mesh_uv_layer_render_get;
1590 (void)rna_Mesh_uv_layer_render_index_get;
1591 (void)rna_Mesh_uv_layer_render_index_set;
1592 (void)rna_Mesh_uv_layer_render_set;
1593 (void)rna_Mesh_face_map_index_range;
1594 (void)rna_Mesh_face_map_active_index_set;
1595 (void)rna_Mesh_face_map_active_index_get;
1596 (void)rna_Mesh_face_map_active_set;
1597 /* end unused function block */
1598 }
1599
1600 #else
1601
rna_def_mvert_group(BlenderRNA * brna)1602 static void rna_def_mvert_group(BlenderRNA *brna)
1603 {
1604 StructRNA *srna;
1605 PropertyRNA *prop;
1606
1607 srna = RNA_def_struct(brna, "VertexGroupElement", NULL);
1608 RNA_def_struct_sdna(srna, "MDeformWeight");
1609 RNA_def_struct_path_func(srna, "rna_VertexGroupElement_path");
1610 RNA_def_struct_ui_text(
1611 srna, "Vertex Group Element", "Weight value of a vertex in a vertex group");
1612 RNA_def_struct_ui_icon(srna, ICON_GROUP_VERTEX);
1613
1614 /* we can't point to actual group, it is in the object and so
1615 * there is no unique group to point to, hence the index */
1616 prop = RNA_def_property(srna, "group", PROP_INT, PROP_UNSIGNED);
1617 RNA_def_property_int_sdna(prop, NULL, "def_nr");
1618 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1619 RNA_def_property_ui_text(prop, "Group Index", "");
1620 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
1621
1622 prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_NONE);
1623 RNA_def_property_range(prop, 0.0f, 1.0f);
1624 RNA_def_property_ui_text(prop, "Weight", "Vertex Weight");
1625 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_weight");
1626 }
1627
rna_def_mvert(BlenderRNA * brna)1628 static void rna_def_mvert(BlenderRNA *brna)
1629 {
1630 StructRNA *srna;
1631 PropertyRNA *prop;
1632
1633 srna = RNA_def_struct(brna, "MeshVertex", NULL);
1634 RNA_def_struct_sdna(srna, "MVert");
1635 RNA_def_struct_ui_text(srna, "Mesh Vertex", "Vertex in a Mesh data-block");
1636 RNA_def_struct_path_func(srna, "rna_MeshVertex_path");
1637 RNA_def_struct_ui_icon(srna, ICON_VERTEXSEL);
1638
1639 prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
1640 RNA_def_property_ui_text(prop, "Location", "");
1641 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
1642
1643 prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
1644 /* RNA_def_property_float_sdna(prop, NULL, "no"); */
1645 RNA_def_property_array(prop, 3);
1646 RNA_def_property_range(prop, -1.0f, 1.0f);
1647 RNA_def_property_float_funcs(
1648 prop, "rna_MeshVertex_normal_get", "rna_MeshVertex_normal_set", NULL);
1649 RNA_def_property_ui_text(prop, "Normal", "Vertex Normal");
1650
1651 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
1652 RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
1653 RNA_def_property_ui_text(prop, "Select", "");
1654 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
1655
1656 prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
1657 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_HIDE);
1658 RNA_def_property_ui_text(prop, "Hide", "");
1659 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
1660
1661 prop = RNA_def_property(srna, "bevel_weight", PROP_FLOAT, PROP_NONE);
1662 RNA_def_property_float_funcs(
1663 prop, "rna_MeshVertex_bevel_weight_get", "rna_MeshVertex_bevel_weight_set", NULL);
1664 RNA_def_property_ui_text(
1665 prop, "Bevel Weight", "Weight used by the Bevel modifier 'Only Vertices' option");
1666 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
1667
1668 prop = RNA_def_property(srna, "groups", PROP_COLLECTION, PROP_NONE);
1669 RNA_def_property_collection_funcs(prop,
1670 "rna_MeshVertex_groups_begin",
1671 "rna_iterator_array_next",
1672 "rna_iterator_array_end",
1673 "rna_iterator_array_get",
1674 NULL,
1675 NULL,
1676 NULL,
1677 NULL);
1678 RNA_def_property_struct_type(prop, "VertexGroupElement");
1679 RNA_def_property_ui_text(
1680 prop, "Groups", "Weights for the vertex groups this vertex is member of");
1681
1682 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
1683 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1684 RNA_def_property_int_funcs(prop, "rna_MeshVertex_index_get", NULL, NULL);
1685 RNA_def_property_ui_text(prop, "Index", "Index of this vertex");
1686
1687 prop = RNA_def_property(srna, "undeformed_co", PROP_FLOAT, PROP_TRANSLATION);
1688 RNA_def_property_array(prop, 3);
1689 RNA_def_property_ui_text(
1690 prop,
1691 "Undeformed Location",
1692 "For meshes with modifiers applied, the coordinate of the vertex with no deforming "
1693 "modifiers applied, as used for generated texture coordinates");
1694 RNA_def_property_float_funcs(prop, "rna_MeshVertex_undeformed_co_get", NULL, NULL);
1695 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1696 }
1697
rna_def_medge(BlenderRNA * brna)1698 static void rna_def_medge(BlenderRNA *brna)
1699 {
1700 StructRNA *srna;
1701 PropertyRNA *prop;
1702
1703 srna = RNA_def_struct(brna, "MeshEdge", NULL);
1704 RNA_def_struct_sdna(srna, "MEdge");
1705 RNA_def_struct_ui_text(srna, "Mesh Edge", "Edge in a Mesh data-block");
1706 RNA_def_struct_path_func(srna, "rna_MeshEdge_path");
1707 RNA_def_struct_ui_icon(srna, ICON_EDGESEL);
1708
1709 prop = RNA_def_property(srna, "vertices", PROP_INT, PROP_UNSIGNED);
1710 RNA_def_property_int_sdna(prop, NULL, "v1");
1711 RNA_def_property_array(prop, 2);
1712 RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");
1713 /* XXX allows creating invalid meshes */
1714
1715 prop = RNA_def_property(srna, "crease", PROP_FLOAT, PROP_NONE);
1716 RNA_def_property_float_funcs(prop, "rna_MEdge_crease_get", "rna_MEdge_crease_set", NULL);
1717 RNA_def_property_ui_text(
1718 prop, "Crease", "Weight used by the Subdivision Surface modifier for creasing");
1719 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
1720
1721 prop = RNA_def_property(srna, "bevel_weight", PROP_FLOAT, PROP_NONE);
1722 RNA_def_property_float_funcs(
1723 prop, "rna_MEdge_bevel_weight_get", "rna_MEdge_bevel_weight_set", NULL);
1724 RNA_def_property_ui_text(prop, "Bevel Weight", "Weight used by the Bevel modifier");
1725 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
1726
1727 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
1728 RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
1729 RNA_def_property_ui_text(prop, "Select", "");
1730 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
1731
1732 prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
1733 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_HIDE);
1734 RNA_def_property_ui_text(prop, "Hide", "");
1735 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
1736
1737 prop = RNA_def_property(srna, "use_seam", PROP_BOOLEAN, PROP_NONE);
1738 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_SEAM);
1739 RNA_def_property_ui_text(prop, "Seam", "Seam edge for UV unwrapping");
1740 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
1741
1742 prop = RNA_def_property(srna, "use_edge_sharp", PROP_BOOLEAN, PROP_NONE);
1743 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_SHARP);
1744 RNA_def_property_ui_text(prop, "Sharp", "Sharp edge for the Edge Split modifier");
1745 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
1746
1747 prop = RNA_def_property(srna, "is_loose", PROP_BOOLEAN, PROP_NONE);
1748 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_LOOSEEDGE);
1749 RNA_def_property_ui_text(prop, "Loose", "Loose edge");
1750
1751 prop = RNA_def_property(srna, "use_freestyle_mark", PROP_BOOLEAN, PROP_NONE);
1752 RNA_def_property_boolean_funcs(
1753 prop, "rna_MEdge_freestyle_edge_mark_get", "rna_MEdge_freestyle_edge_mark_set");
1754 RNA_def_property_ui_text(prop, "Freestyle Edge Mark", "Edge mark for Freestyle line rendering");
1755 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
1756
1757 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
1758 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1759 RNA_def_property_int_funcs(prop, "rna_MeshEdge_index_get", NULL, NULL);
1760 RNA_def_property_ui_text(prop, "Index", "Index of this edge");
1761 }
1762
rna_def_mlooptri(BlenderRNA * brna)1763 static void rna_def_mlooptri(BlenderRNA *brna)
1764 {
1765 StructRNA *srna;
1766 PropertyRNA *prop;
1767 const int splitnor_dim[] = {3, 3};
1768
1769 srna = RNA_def_struct(brna, "MeshLoopTriangle", NULL);
1770 RNA_def_struct_sdna(srna, "MLoopTri");
1771 RNA_def_struct_ui_text(srna, "Mesh Loop Triangle", "Tessellated triangle in a Mesh data-block");
1772 RNA_def_struct_path_func(srna, "rna_MeshLoopTriangle_path");
1773 RNA_def_struct_ui_icon(srna, ICON_FACESEL);
1774
1775 prop = RNA_def_property(srna, "vertices", PROP_INT, PROP_UNSIGNED);
1776 RNA_def_property_array(prop, 3);
1777 RNA_def_property_int_funcs(prop, "rna_MeshLoopTriangle_verts_get", NULL, NULL);
1778 RNA_def_property_ui_text(prop, "Vertices", "Indices of triangle vertices");
1779 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1780
1781 prop = RNA_def_property(srna, "loops", PROP_INT, PROP_UNSIGNED);
1782 RNA_def_property_int_sdna(prop, NULL, "tri");
1783 RNA_def_property_ui_text(prop, "Loops", "Indices of mesh loops that make up the triangle");
1784 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1785
1786 prop = RNA_def_property(srna, "polygon_index", PROP_INT, PROP_UNSIGNED);
1787 RNA_def_property_int_sdna(prop, NULL, "poly");
1788 RNA_def_property_ui_text(
1789 prop, "Polygon", "Index of mesh polygon that the triangle is a part of");
1790 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1791
1792 prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
1793 RNA_def_property_array(prop, 3);
1794 RNA_def_property_range(prop, -1.0f, 1.0f);
1795 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1796 RNA_def_property_float_funcs(prop, "rna_MeshLoopTriangle_normal_get", NULL, NULL);
1797 RNA_def_property_ui_text(
1798 prop, "Triangle Normal", "Local space unit length normal vector for this triangle");
1799
1800 prop = RNA_def_property(srna, "split_normals", PROP_FLOAT, PROP_DIRECTION);
1801 RNA_def_property_multi_array(prop, 2, splitnor_dim);
1802 RNA_def_property_range(prop, -1.0f, 1.0f);
1803 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1804 RNA_def_property_float_funcs(prop, "rna_MeshLoopTriangle_split_normals_get", NULL, NULL);
1805 RNA_def_property_ui_text(
1806 prop,
1807 "Split Normals",
1808 "Local space unit length split normals vectors of the vertices of this triangle "
1809 "(must be computed beforehand using calc_normals_split or calc_tangents)");
1810
1811 prop = RNA_def_property(srna, "area", PROP_FLOAT, PROP_UNSIGNED);
1812 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1813 RNA_def_property_float_funcs(prop, "rna_MeshLoopTriangle_area_get", NULL, NULL);
1814 RNA_def_property_ui_text(prop, "Triangle Area", "Area of this triangle");
1815
1816 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
1817 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1818 RNA_def_property_int_funcs(prop, "rna_MeshLoopTriangle_index_get", NULL, NULL);
1819 RNA_def_property_ui_text(prop, "Index", "Index of this loop triangle");
1820
1821 prop = RNA_def_property(srna, "material_index", PROP_INT, PROP_UNSIGNED);
1822 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1823 RNA_def_property_int_funcs(prop, "rna_MeshLoopTriangle_material_index_get", NULL, NULL);
1824 RNA_def_property_ui_text(prop, "Material Index", "");
1825
1826 prop = RNA_def_property(srna, "use_smooth", PROP_BOOLEAN, PROP_NONE);
1827 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1828 RNA_def_property_boolean_funcs(prop, "rna_MeshLoopTriangle_use_smooth_get", NULL);
1829 RNA_def_property_ui_text(prop, "Smooth", "");
1830 }
1831
rna_def_mloop(BlenderRNA * brna)1832 static void rna_def_mloop(BlenderRNA *brna)
1833 {
1834 StructRNA *srna;
1835 PropertyRNA *prop;
1836
1837 srna = RNA_def_struct(brna, "MeshLoop", NULL);
1838 RNA_def_struct_sdna(srna, "MLoop");
1839 RNA_def_struct_ui_text(srna, "Mesh Loop", "Loop in a Mesh data-block");
1840 RNA_def_struct_path_func(srna, "rna_MeshLoop_path");
1841 RNA_def_struct_ui_icon(srna, ICON_EDGESEL);
1842
1843 prop = RNA_def_property(srna, "vertex_index", PROP_INT, PROP_UNSIGNED);
1844 RNA_def_property_int_sdna(prop, NULL, "v");
1845 RNA_def_property_ui_text(prop, "Vertex", "Vertex index");
1846
1847 prop = RNA_def_property(srna, "edge_index", PROP_INT, PROP_UNSIGNED);
1848 RNA_def_property_int_sdna(prop, NULL, "e");
1849 RNA_def_property_ui_text(prop, "Edge", "Edge index");
1850
1851 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
1852 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1853 RNA_def_property_int_funcs(prop, "rna_MeshLoop_index_get", NULL, NULL);
1854 RNA_def_property_ui_text(prop, "Index", "Index of this loop");
1855
1856 prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
1857 RNA_def_property_array(prop, 3);
1858 RNA_def_property_range(prop, -1.0f, 1.0f);
1859 RNA_def_property_float_funcs(prop, "rna_MeshLoop_normal_get", "rna_MeshLoop_normal_set", NULL);
1860 RNA_def_property_ui_text(
1861 prop,
1862 "Normal",
1863 "Local space unit length split normal vector of this vertex for this polygon "
1864 "(must be computed beforehand using calc_normals_split or calc_tangents)");
1865
1866 prop = RNA_def_property(srna, "tangent", PROP_FLOAT, PROP_DIRECTION);
1867 RNA_def_property_array(prop, 3);
1868 RNA_def_property_range(prop, -1.0f, 1.0f);
1869 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1870 RNA_def_property_float_funcs(prop, "rna_MeshLoop_tangent_get", NULL, NULL);
1871 RNA_def_property_ui_text(
1872 prop,
1873 "Tangent",
1874 "Local space unit length tangent vector of this vertex for this polygon "
1875 "(must be computed beforehand using calc_tangents)");
1876
1877 prop = RNA_def_property(srna, "bitangent_sign", PROP_FLOAT, PROP_NONE);
1878 RNA_def_property_range(prop, -1.0f, 1.0f);
1879 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1880 RNA_def_property_float_funcs(prop, "rna_MeshLoop_bitangent_sign_get", NULL, NULL);
1881 RNA_def_property_ui_text(
1882 prop,
1883 "Bitangent Sign",
1884 "Sign of the bitangent vector of this vertex for this polygon (must be computed "
1885 "beforehand using calc_tangents, bitangent = bitangent_sign * cross(normal, tangent))");
1886
1887 prop = RNA_def_property(srna, "bitangent", PROP_FLOAT, PROP_DIRECTION);
1888 RNA_def_property_array(prop, 3);
1889 RNA_def_property_range(prop, -1.0f, 1.0f);
1890 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1891 RNA_def_property_float_funcs(prop, "rna_MeshLoop_bitangent_get", NULL, NULL);
1892 RNA_def_property_ui_text(
1893 prop,
1894 "Bitangent",
1895 "Bitangent vector of this vertex for this polygon (must be computed beforehand using "
1896 "calc_tangents, *use it only if really needed*, slower access than bitangent_sign)");
1897 }
1898
rna_def_mpolygon(BlenderRNA * brna)1899 static void rna_def_mpolygon(BlenderRNA *brna)
1900 {
1901 StructRNA *srna;
1902 PropertyRNA *prop;
1903 FunctionRNA *func;
1904
1905 srna = RNA_def_struct(brna, "MeshPolygon", NULL);
1906 RNA_def_struct_sdna(srna, "MPoly");
1907 RNA_def_struct_ui_text(srna, "Mesh Polygon", "Polygon in a Mesh data-block");
1908 RNA_def_struct_path_func(srna, "rna_MeshPolygon_path");
1909 RNA_def_struct_ui_icon(srna, ICON_FACESEL);
1910
1911 /* Faked, actually access to loop vertex values, don't this way because manually setting up
1912 * vertex/edge per loop is very low level.
1913 * Instead we setup poly sizes, assign indices, then calc edges automatic when creating
1914 * meshes from rna/py. */
1915 prop = RNA_def_property(srna, "vertices", PROP_INT, PROP_UNSIGNED);
1916 /* Eek, this is still used in some cases but in fact we don't want to use it at all here. */
1917 RNA_def_property_array(prop, 3);
1918 RNA_def_property_flag(prop, PROP_DYNAMIC);
1919 RNA_def_property_dynamic_array_funcs(prop, "rna_MeshPoly_vertices_get_length");
1920 RNA_def_property_int_funcs(prop, "rna_MeshPoly_vertices_get", "rna_MeshPoly_vertices_set", NULL);
1921 RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");
1922
1923 /* these are both very low level access */
1924 prop = RNA_def_property(srna, "loop_start", PROP_INT, PROP_UNSIGNED);
1925 RNA_def_property_int_sdna(prop, NULL, "loopstart");
1926 RNA_def_property_ui_text(prop, "Loop Start", "Index of the first loop of this polygon");
1927 /* also low level */
1928 prop = RNA_def_property(srna, "loop_total", PROP_INT, PROP_UNSIGNED);
1929 RNA_def_property_int_sdna(prop, NULL, "totloop");
1930 RNA_def_property_ui_text(prop, "Loop Total", "Number of loops used by this polygon");
1931
1932 prop = RNA_def_property(srna, "material_index", PROP_INT, PROP_UNSIGNED);
1933 RNA_def_property_int_sdna(prop, NULL, "mat_nr");
1934 RNA_def_property_ui_text(prop, "Material Index", "");
1935 # if 0
1936 RNA_def_property_int_funcs(prop, NULL, NULL, "rna_MeshPoly_material_index_range");
1937 # endif
1938 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
1939
1940 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
1941 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_FACE_SEL);
1942 RNA_def_property_ui_text(prop, "Select", "");
1943 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
1944
1945 prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
1946 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_HIDE);
1947 RNA_def_property_ui_text(prop, "Hide", "");
1948 RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
1949
1950 prop = RNA_def_property(srna, "use_smooth", PROP_BOOLEAN, PROP_NONE);
1951 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_SMOOTH);
1952 RNA_def_property_ui_text(prop, "Smooth", "");
1953 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
1954
1955 prop = RNA_def_property(srna, "use_freestyle_mark", PROP_BOOLEAN, PROP_NONE);
1956 RNA_def_property_boolean_funcs(
1957 prop, "rna_MPoly_freestyle_face_mark_get", "rna_MPoly_freestyle_face_mark_set");
1958 RNA_def_property_ui_text(prop, "Freestyle Face Mark", "Face mark for Freestyle line rendering");
1959 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
1960
1961 prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
1962 RNA_def_property_array(prop, 3);
1963 RNA_def_property_range(prop, -1.0f, 1.0f);
1964 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1965 RNA_def_property_float_funcs(prop, "rna_MeshPolygon_normal_get", NULL, NULL);
1966 RNA_def_property_ui_text(
1967 prop, "Polygon Normal", "Local space unit length normal vector for this polygon");
1968
1969 prop = RNA_def_property(srna, "center", PROP_FLOAT, PROP_XYZ);
1970 RNA_def_property_array(prop, 3);
1971 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1972 RNA_def_property_float_funcs(prop, "rna_MeshPolygon_center_get", NULL, NULL);
1973 RNA_def_property_ui_text(prop, "Polygon Center", "Center of this polygon");
1974
1975 prop = RNA_def_property(srna, "area", PROP_FLOAT, PROP_UNSIGNED);
1976 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1977 RNA_def_property_float_funcs(prop, "rna_MeshPolygon_area_get", NULL, NULL);
1978 RNA_def_property_ui_text(prop, "Polygon Area", "Read only area of this polygon");
1979
1980 prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
1981 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1982 RNA_def_property_int_funcs(prop, "rna_MeshPolygon_index_get", NULL, NULL);
1983 RNA_def_property_ui_text(prop, "Index", "Index of this polygon");
1984
1985 func = RNA_def_function(srna, "flip", "rna_MeshPolygon_flip");
1986 RNA_def_function_flag(func, FUNC_USE_SELF_ID);
1987 RNA_def_function_ui_description(func, "Invert winding of this polygon (flip its normal)");
1988 }
1989
1990 /* mesh.loop_uvs */
rna_def_mloopuv(BlenderRNA * brna)1991 static void rna_def_mloopuv(BlenderRNA *brna)
1992 {
1993 StructRNA *srna;
1994 PropertyRNA *prop;
1995
1996 srna = RNA_def_struct(brna, "MeshUVLoopLayer", NULL);
1997 RNA_def_struct_sdna(srna, "CustomDataLayer");
1998 RNA_def_struct_path_func(srna, "rna_MeshUVLoopLayer_path");
1999
2000 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
2001 RNA_def_property_struct_type(prop, "MeshUVLoop");
2002 RNA_def_property_collection_funcs(prop,
2003 "rna_MeshUVLoopLayer_data_begin",
2004 "rna_iterator_array_next",
2005 "rna_iterator_array_end",
2006 "rna_iterator_array_get",
2007 "rna_MeshUVLoopLayer_data_length",
2008 NULL,
2009 NULL,
2010 NULL);
2011
2012 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2013 RNA_def_struct_name_property(srna, prop);
2014 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshLoopLayer_name_set");
2015 RNA_def_property_ui_text(prop, "Name", "Name of UV map");
2016 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2017
2018 prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
2019 RNA_def_property_boolean_funcs(
2020 prop, "rna_MeshUVLoopLayer_active_get", "rna_MeshUVLoopLayer_active_set");
2021 RNA_def_property_ui_text(prop, "Active", "Set the map as active for display and editing");
2022 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2023
2024 prop = RNA_def_property(srna, "active_render", PROP_BOOLEAN, PROP_NONE);
2025 RNA_def_property_boolean_sdna(prop, NULL, "active_rnd", 0);
2026 RNA_def_property_boolean_funcs(
2027 prop, "rna_MeshUVLoopLayer_active_render_get", "rna_MeshUVLoopLayer_active_render_set");
2028 RNA_def_property_ui_text(prop, "Active Render", "Set the map as active for rendering");
2029 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2030
2031 prop = RNA_def_property(srna, "active_clone", PROP_BOOLEAN, PROP_NONE);
2032 RNA_def_property_boolean_sdna(prop, NULL, "active_clone", 0);
2033 RNA_def_property_boolean_funcs(
2034 prop, "rna_MeshUVLoopLayer_clone_get", "rna_MeshUVLoopLayer_clone_set");
2035 RNA_def_property_ui_text(prop, "Active Clone", "Set the map as active for cloning");
2036 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2037
2038 srna = RNA_def_struct(brna, "MeshUVLoop", NULL);
2039 RNA_def_struct_sdna(srna, "MLoopUV");
2040 RNA_def_struct_path_func(srna, "rna_MeshUVLoop_path");
2041
2042 prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_XYZ);
2043 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2044
2045 prop = RNA_def_property(srna, "pin_uv", PROP_BOOLEAN, PROP_NONE);
2046 RNA_def_property_boolean_sdna(prop, NULL, "flag", MLOOPUV_PINNED);
2047 RNA_def_property_ui_text(prop, "UV Pinned", "");
2048
2049 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
2050 RNA_def_property_boolean_sdna(prop, NULL, "flag", MLOOPUV_VERTSEL);
2051 RNA_def_property_ui_text(prop, "UV Select", "");
2052 }
2053
rna_def_mloopcol(BlenderRNA * brna)2054 static void rna_def_mloopcol(BlenderRNA *brna)
2055 {
2056 StructRNA *srna;
2057 PropertyRNA *prop;
2058
2059 srna = RNA_def_struct(brna, "MeshLoopColorLayer", NULL);
2060 RNA_def_struct_ui_text(
2061 srna, "Mesh Vertex Color Layer", "Layer of vertex colors in a Mesh data-block");
2062 RNA_def_struct_sdna(srna, "CustomDataLayer");
2063 RNA_def_struct_path_func(srna, "rna_MeshLoopColorLayer_path");
2064 RNA_def_struct_ui_icon(srna, ICON_GROUP_VCOL);
2065
2066 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2067 RNA_def_struct_name_property(srna, prop);
2068 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshLoopLayer_name_set");
2069 RNA_def_property_ui_text(prop, "Name", "Name of Vertex color layer");
2070 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2071
2072 prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
2073 RNA_def_property_boolean_funcs(
2074 prop, "rna_MeshLoopColorLayer_active_get", "rna_MeshLoopColorLayer_active_set");
2075 RNA_def_property_ui_text(prop, "Active", "Sets the layer as active for display and editing");
2076 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2077
2078 prop = RNA_def_property(srna, "active_render", PROP_BOOLEAN, PROP_NONE);
2079 RNA_def_property_boolean_sdna(prop, NULL, "active_rnd", 0);
2080 RNA_def_property_boolean_funcs(prop,
2081 "rna_MeshLoopColorLayer_active_render_get",
2082 "rna_MeshLoopColorLayer_active_render_set");
2083 RNA_def_property_ui_text(prop, "Active Render", "Sets the layer as active for rendering");
2084 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2085
2086 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
2087 RNA_def_property_struct_type(prop, "MeshLoopColor");
2088 RNA_def_property_ui_text(prop, "Data", "");
2089 RNA_def_property_collection_funcs(prop,
2090 "rna_MeshLoopColorLayer_data_begin",
2091 "rna_iterator_array_next",
2092 "rna_iterator_array_end",
2093 "rna_iterator_array_get",
2094 "rna_MeshLoopColorLayer_data_length",
2095 NULL,
2096 NULL,
2097 NULL);
2098
2099 srna = RNA_def_struct(brna, "MeshLoopColor", NULL);
2100 RNA_def_struct_sdna(srna, "MLoopCol");
2101 RNA_def_struct_ui_text(srna, "Mesh Vertex Color", "Vertex loop colors in a Mesh");
2102 RNA_def_struct_path_func(srna, "rna_MeshColor_path");
2103
2104 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
2105 RNA_def_property_array(prop, 4);
2106 RNA_def_property_range(prop, 0.0f, 1.0f);
2107 RNA_def_property_float_funcs(
2108 prop, "rna_MeshLoopColor_color_get", "rna_MeshLoopColor_color_set", NULL);
2109 RNA_def_property_ui_text(prop, "Color", "");
2110 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2111 }
2112
rna_def_MPropCol(BlenderRNA * brna)2113 static void rna_def_MPropCol(BlenderRNA *brna)
2114 {
2115 StructRNA *srna;
2116 PropertyRNA *prop;
2117
2118 srna = RNA_def_struct(brna, "MeshVertColorLayer", NULL);
2119 RNA_def_struct_ui_text(srna,
2120 "Mesh Sculpt Vertex Color Layer",
2121 "Layer of sculpt vertex colors in a Mesh data-block");
2122 RNA_def_struct_sdna(srna, "CustomDataLayer");
2123 RNA_def_struct_path_func(srna, "rna_MeshVertColorLayer_path");
2124 RNA_def_struct_ui_icon(srna, ICON_GROUP_VCOL);
2125
2126 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2127 RNA_def_struct_name_property(srna, prop);
2128 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshVertexLayer_name_set");
2129 RNA_def_property_ui_text(prop, "Name", "Name of Sculpt Vertex color layer");
2130 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2131
2132 prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
2133 RNA_def_property_boolean_funcs(
2134 prop, "rna_MeshVertColorLayer_active_get", "rna_MeshVertColorLayer_active_set");
2135 RNA_def_property_ui_text(
2136 prop, "Active", "Sets the sculpt vertex color layer as active for display and editing");
2137 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2138
2139 prop = RNA_def_property(srna, "active_render", PROP_BOOLEAN, PROP_NONE);
2140 RNA_def_property_boolean_sdna(prop, NULL, "active_rnd", 0);
2141 RNA_def_property_boolean_funcs(prop,
2142 "rna_MeshVertColorLayer_active_render_get",
2143 "rna_MeshVertColorLayer_active_render_set");
2144 RNA_def_property_ui_text(
2145 prop, "Active Render", "Sets the sculpt vertex color layer as active for rendering");
2146 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2147
2148 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
2149 RNA_def_property_struct_type(prop, "MeshVertColor");
2150 RNA_def_property_ui_text(prop, "Data", "");
2151 RNA_def_property_collection_funcs(prop,
2152 "rna_MeshVertColorLayer_data_begin",
2153 "rna_iterator_array_next",
2154 "rna_iterator_array_end",
2155 "rna_iterator_array_get",
2156 "rna_MeshVertColorLayer_data_length",
2157 NULL,
2158 NULL,
2159 NULL);
2160
2161 srna = RNA_def_struct(brna, "MeshVertColor", NULL);
2162 RNA_def_struct_sdna(srna, "MPropCol");
2163 RNA_def_struct_ui_text(srna, "Mesh Sculpt Vertex Color", "Vertex colors in a Mesh");
2164 RNA_def_struct_path_func(srna, "rna_MeshVertColor_path");
2165
2166 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
2167 RNA_def_property_array(prop, 4);
2168 RNA_def_property_range(prop, 0.0f, 1.0f);
2169 RNA_def_property_ui_text(prop, "Color", "");
2170 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2171 }
rna_def_mproperties(BlenderRNA * brna)2172 static void rna_def_mproperties(BlenderRNA *brna)
2173 {
2174 StructRNA *srna;
2175 PropertyRNA *prop;
2176
2177 /* Float */
2178 # define MESH_FLOAT_PROPERTY_LAYER(elemname) \
2179 srna = RNA_def_struct(brna, "Mesh" elemname "FloatPropertyLayer", NULL); \
2180 RNA_def_struct_sdna(srna, "CustomDataLayer"); \
2181 RNA_def_struct_ui_text(srna, \
2182 "Mesh " elemname " Float Property Layer", \
2183 "User defined layer of floating point number values"); \
2184 RNA_def_struct_path_func(srna, "rna_Mesh" elemname "FloatPropertyLayer_path"); \
2185 \
2186 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); \
2187 RNA_def_struct_name_property(srna, prop); \
2188 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshAnyLayer_name_set"); \
2189 RNA_def_property_ui_text(prop, "Name", ""); \
2190 RNA_def_property_update(prop, 0, "rna_Mesh_update_data"); \
2191 \
2192 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); \
2193 RNA_def_property_struct_type(prop, "Mesh" elemname "FloatProperty"); \
2194 RNA_def_property_ui_text(prop, "Data", ""); \
2195 RNA_def_property_collection_funcs(prop, \
2196 "rna_Mesh" elemname "FloatPropertyLayer_data_begin", \
2197 "rna_iterator_array_next", \
2198 "rna_iterator_array_end", \
2199 "rna_iterator_array_get", \
2200 "rna_Mesh" elemname "FloatPropertyLayer_data_length", \
2201 NULL, \
2202 NULL, \
2203 NULL); \
2204 \
2205 srna = RNA_def_struct(brna, "Mesh" elemname "FloatProperty", NULL); \
2206 RNA_def_struct_sdna(srna, "MFloatProperty"); \
2207 RNA_def_struct_ui_text( \
2208 srna, \
2209 "Mesh " elemname " Float Property", \
2210 "User defined floating point number value in a float properties layer"); \
2211 RNA_def_struct_path_func(srna, "rna_Mesh" elemname "FloatProperty_path"); \
2212 \
2213 prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE); \
2214 RNA_def_property_float_sdna(prop, NULL, "f"); \
2215 RNA_def_property_ui_text(prop, "Value", ""); \
2216 RNA_def_property_update(prop, 0, "rna_Mesh_update_data"); \
2217 ((void)0)
2218
2219 /* Int */
2220 # define MESH_INT_PROPERTY_LAYER(elemname) \
2221 srna = RNA_def_struct(brna, "Mesh" elemname "IntPropertyLayer", NULL); \
2222 RNA_def_struct_sdna(srna, "CustomDataLayer"); \
2223 RNA_def_struct_ui_text(srna, \
2224 "Mesh " elemname " Int Property Layer", \
2225 "User defined layer of integer number values"); \
2226 RNA_def_struct_path_func(srna, "rna_Mesh" elemname "IntPropertyLayer_path"); \
2227 \
2228 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); \
2229 RNA_def_struct_name_property(srna, prop); \
2230 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshAnyLayer_name_set"); \
2231 RNA_def_property_ui_text(prop, "Name", ""); \
2232 RNA_def_property_update(prop, 0, "rna_Mesh_update_data"); \
2233 \
2234 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); \
2235 RNA_def_property_struct_type(prop, "Mesh" elemname "IntProperty"); \
2236 RNA_def_property_ui_text(prop, "Data", ""); \
2237 RNA_def_property_collection_funcs(prop, \
2238 "rna_Mesh" elemname "IntPropertyLayer_data_begin", \
2239 "rna_iterator_array_next", \
2240 "rna_iterator_array_end", \
2241 "rna_iterator_array_get", \
2242 "rna_Mesh" elemname "IntPropertyLayer_data_length", \
2243 NULL, \
2244 NULL, \
2245 NULL); \
2246 \
2247 srna = RNA_def_struct(brna, "Mesh" elemname "IntProperty", NULL); \
2248 RNA_def_struct_sdna(srna, "MIntProperty"); \
2249 RNA_def_struct_ui_text(srna, \
2250 "Mesh " elemname " Int Property", \
2251 "User defined integer number value in an integer properties layer"); \
2252 RNA_def_struct_path_func(srna, "rna_Mesh" elemname "IntProperty_path"); \
2253 \
2254 prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE); \
2255 RNA_def_property_int_sdna(prop, NULL, "i"); \
2256 RNA_def_property_ui_text(prop, "Value", ""); \
2257 RNA_def_property_update(prop, 0, "rna_Mesh_update_data"); \
2258 ((void)0)
2259
2260 /* String */
2261 # define MESH_STRING_PROPERTY_LAYER(elemname) \
2262 srna = RNA_def_struct(brna, "Mesh" elemname "StringPropertyLayer", NULL); \
2263 RNA_def_struct_sdna(srna, "CustomDataLayer"); \
2264 RNA_def_struct_ui_text(srna, \
2265 "Mesh " elemname " String Property Layer", \
2266 "User defined layer of string text values"); \
2267 RNA_def_struct_path_func(srna, "rna_Mesh" elemname "StringPropertyLayer_path"); \
2268 \
2269 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); \
2270 RNA_def_struct_name_property(srna, prop); \
2271 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshAnyLayer_name_set"); \
2272 RNA_def_property_ui_text(prop, "Name", ""); \
2273 RNA_def_property_update(prop, 0, "rna_Mesh_update_data"); \
2274 \
2275 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE); \
2276 RNA_def_property_struct_type(prop, "Mesh" elemname "StringProperty"); \
2277 RNA_def_property_ui_text(prop, "Data", ""); \
2278 RNA_def_property_collection_funcs(prop, \
2279 "rna_Mesh" elemname "StringPropertyLayer_data_begin", \
2280 "rna_iterator_array_next", \
2281 "rna_iterator_array_end", \
2282 "rna_iterator_array_get", \
2283 "rna_Mesh" elemname "StringPropertyLayer_data_length", \
2284 NULL, \
2285 NULL, \
2286 NULL); \
2287 \
2288 srna = RNA_def_struct(brna, "Mesh" elemname "StringProperty", NULL); \
2289 RNA_def_struct_sdna(srna, "MStringProperty"); \
2290 RNA_def_struct_ui_text(srna, \
2291 "Mesh " elemname " String Property", \
2292 "User defined string text value in a string properties layer"); \
2293 RNA_def_struct_path_func(srna, "rna_Mesh" elemname "StringProperty_path"); \
2294 \
2295 /* low level mesh data access, treat as bytes */ \
2296 prop = RNA_def_property(srna, "value", PROP_STRING, PROP_BYTESTRING); \
2297 RNA_def_property_string_sdna(prop, NULL, "s"); \
2298 RNA_def_property_string_funcs(prop, \
2299 "rna_MeshStringProperty_s_get", \
2300 "rna_MeshStringProperty_s_length", \
2301 "rna_MeshStringProperty_s_set"); \
2302 RNA_def_property_ui_text(prop, "Value", ""); \
2303 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2304
2305 MESH_FLOAT_PROPERTY_LAYER("Vertex");
2306 MESH_FLOAT_PROPERTY_LAYER("Polygon");
2307 MESH_INT_PROPERTY_LAYER("Vertex");
2308 MESH_INT_PROPERTY_LAYER("Polygon");
2309 MESH_STRING_PROPERTY_LAYER("Vertex")
2310 MESH_STRING_PROPERTY_LAYER("Polygon")
2311 # undef MESH_PROPERTY_LAYER
2312 }
2313
rna_def_texmat_common(StructRNA * srna,const char * texspace_editable)2314 void rna_def_texmat_common(StructRNA *srna, const char *texspace_editable)
2315 {
2316 PropertyRNA *prop;
2317
2318 /* texture space */
2319 prop = RNA_def_property(srna, "auto_texspace", PROP_BOOLEAN, PROP_NONE);
2320 RNA_def_property_boolean_sdna(prop, NULL, "texflag", ME_AUTOSPACE);
2321 RNA_def_property_ui_text(
2322 prop,
2323 "Auto Texture Space",
2324 "Adjust active object's texture space automatically when transforming object");
2325
2326 prop = RNA_def_property(srna, "texspace_location", PROP_FLOAT, PROP_TRANSLATION);
2327 RNA_def_property_float_sdna(prop, NULL, "loc");
2328 RNA_def_property_ui_text(prop, "Texture Space Location", "Texture space location");
2329 RNA_def_property_float_funcs(prop, "rna_Mesh_texspace_loc_get", NULL, NULL);
2330 RNA_def_property_editable_func(prop, texspace_editable);
2331 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2332
2333 prop = RNA_def_property(srna, "texspace_size", PROP_FLOAT, PROP_XYZ);
2334 RNA_def_property_float_sdna(prop, NULL, "size");
2335 RNA_def_property_flag(prop, PROP_PROPORTIONAL);
2336 RNA_def_property_ui_text(prop, "Texture Space Size", "Texture space size");
2337 RNA_def_property_float_funcs(prop, "rna_Mesh_texspace_size_get", NULL, NULL);
2338 RNA_def_property_editable_func(prop, texspace_editable);
2339 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2340
2341 /* materials */
2342 prop = RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
2343 RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
2344 RNA_def_property_struct_type(prop, "Material");
2345 RNA_def_property_ui_text(prop, "Materials", "");
2346 RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */
2347 RNA_def_property_collection_funcs(
2348 prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "rna_IDMaterials_assign_int");
2349 }
2350
2351 /* scene.objects */
2352 /* mesh.vertices */
rna_def_mesh_vertices(BlenderRNA * brna,PropertyRNA * cprop)2353 static void rna_def_mesh_vertices(BlenderRNA *brna, PropertyRNA *cprop)
2354 {
2355 StructRNA *srna;
2356 /* PropertyRNA *prop; */
2357
2358 FunctionRNA *func;
2359 PropertyRNA *parm;
2360
2361 RNA_def_property_srna(cprop, "MeshVertices");
2362 srna = RNA_def_struct(brna, "MeshVertices", NULL);
2363 RNA_def_struct_sdna(srna, "Mesh");
2364 RNA_def_struct_ui_text(srna, "Mesh Vertices", "Collection of mesh vertices");
2365
2366 func = RNA_def_function(srna, "add", "ED_mesh_verts_add");
2367 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2368 parm = RNA_def_int(
2369 func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
2370 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2371 # if 0 /* BMESH_TODO Remove until BMesh merge */
2372 func = RNA_def_function(srna, "remove", "ED_mesh_verts_remove");
2373 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2374 RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to remove", 0, INT_MAX);
2375 # endif
2376 }
2377
2378 /* mesh.edges */
rna_def_mesh_edges(BlenderRNA * brna,PropertyRNA * cprop)2379 static void rna_def_mesh_edges(BlenderRNA *brna, PropertyRNA *cprop)
2380 {
2381 StructRNA *srna;
2382 /* PropertyRNA *prop; */
2383
2384 FunctionRNA *func;
2385 PropertyRNA *parm;
2386
2387 RNA_def_property_srna(cprop, "MeshEdges");
2388 srna = RNA_def_struct(brna, "MeshEdges", NULL);
2389 RNA_def_struct_sdna(srna, "Mesh");
2390 RNA_def_struct_ui_text(srna, "Mesh Edges", "Collection of mesh edges");
2391
2392 func = RNA_def_function(srna, "add", "ED_mesh_edges_add");
2393 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2394 parm = RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of edges to add", 0, INT_MAX);
2395 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2396 # if 0 /* BMESH_TODO Remove until BMesh merge */
2397 func = RNA_def_function(srna, "remove", "ED_mesh_edges_remove");
2398 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2399 RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of edges to remove", 0, INT_MAX);
2400 # endif
2401 }
2402
2403 /* mesh.loop_triangles */
rna_def_mesh_looptris(BlenderRNA * brna,PropertyRNA * cprop)2404 static void rna_def_mesh_looptris(BlenderRNA *brna, PropertyRNA *cprop)
2405 {
2406 StructRNA *srna;
2407
2408 RNA_def_property_srna(cprop, "MeshLoopTriangles");
2409 srna = RNA_def_struct(brna, "MeshLoopTriangles", NULL);
2410 RNA_def_struct_sdna(srna, "Mesh");
2411 RNA_def_struct_ui_text(
2412 srna, "Mesh Loop Triangles", "Tessellation of mesh polygons into triangles");
2413 }
2414
2415 /* mesh.loops */
rna_def_mesh_loops(BlenderRNA * brna,PropertyRNA * cprop)2416 static void rna_def_mesh_loops(BlenderRNA *brna, PropertyRNA *cprop)
2417 {
2418 StructRNA *srna;
2419
2420 /*PropertyRNA *prop;*/
2421
2422 FunctionRNA *func;
2423 PropertyRNA *parm;
2424
2425 RNA_def_property_srna(cprop, "MeshLoops");
2426 srna = RNA_def_struct(brna, "MeshLoops", NULL);
2427 RNA_def_struct_sdna(srna, "Mesh");
2428 RNA_def_struct_ui_text(srna, "Mesh Loops", "Collection of mesh loops");
2429
2430 func = RNA_def_function(srna, "add", "ED_mesh_loops_add");
2431 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2432 parm = RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of loops to add", 0, INT_MAX);
2433 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2434 }
2435
2436 /* mesh.polygons */
rna_def_mesh_polygons(BlenderRNA * brna,PropertyRNA * cprop)2437 static void rna_def_mesh_polygons(BlenderRNA *brna, PropertyRNA *cprop)
2438 {
2439 StructRNA *srna;
2440
2441 PropertyRNA *prop;
2442
2443 FunctionRNA *func;
2444 PropertyRNA *parm;
2445
2446 RNA_def_property_srna(cprop, "MeshPolygons");
2447 srna = RNA_def_struct(brna, "MeshPolygons", NULL);
2448 RNA_def_struct_sdna(srna, "Mesh");
2449 RNA_def_struct_ui_text(srna, "Mesh Polygons", "Collection of mesh polygons");
2450
2451 prop = RNA_def_property(srna, "active", PROP_INT, PROP_NONE);
2452 RNA_def_property_int_sdna(prop, NULL, "act_face");
2453 RNA_def_property_ui_text(prop, "Active Polygon", "The active polygon for this mesh");
2454
2455 func = RNA_def_function(srna, "add", "ED_mesh_polys_add");
2456 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2457 parm = RNA_def_int(
2458 func, "count", 0, 0, INT_MAX, "Count", "Number of polygons to add", 0, INT_MAX);
2459 RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
2460 }
2461
rna_def_loop_colors(BlenderRNA * brna,PropertyRNA * cprop)2462 static void rna_def_loop_colors(BlenderRNA *brna, PropertyRNA *cprop)
2463 {
2464 StructRNA *srna;
2465 PropertyRNA *prop;
2466
2467 FunctionRNA *func;
2468 PropertyRNA *parm;
2469
2470 RNA_def_property_srna(cprop, "LoopColors");
2471 srna = RNA_def_struct(brna, "LoopColors", NULL);
2472 RNA_def_struct_sdna(srna, "Mesh");
2473 RNA_def_struct_ui_text(srna, "Loop Colors", "Collection of vertex colors");
2474
2475 func = RNA_def_function(srna, "new", "rna_Mesh_vertex_color_new");
2476 RNA_def_function_ui_description(func, "Add a vertex color layer to Mesh");
2477 RNA_def_string(func, "name", "Col", 0, "", "Vertex color name");
2478 RNA_def_boolean(func,
2479 "do_init",
2480 true,
2481 "",
2482 "Whether new layer's data should be initialized by copying current active one");
2483 parm = RNA_def_pointer(func, "layer", "MeshLoopColorLayer", "", "The newly created layer");
2484 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
2485 RNA_def_function_return(func, parm);
2486
2487 func = RNA_def_function(srna, "remove", "rna_Mesh_vertex_color_remove");
2488 RNA_def_function_ui_description(func, "Remove a vertex color layer");
2489 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2490 parm = RNA_def_pointer(func, "layer", "MeshLoopColorLayer", "", "The layer to remove");
2491 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
2492 RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
2493
2494 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2495 RNA_def_property_struct_type(prop, "MeshLoopColorLayer");
2496 RNA_def_property_pointer_funcs(
2497 prop, "rna_Mesh_vertex_color_active_get", "rna_Mesh_vertex_color_active_set", NULL, NULL);
2498 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
2499 RNA_def_property_ui_text(prop, "Active Vertex Color Layer", "Active vertex color layer");
2500 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_active_color");
2501
2502 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
2503 RNA_def_property_int_funcs(prop,
2504 "rna_Mesh_vertex_color_active_index_get",
2505 "rna_Mesh_vertex_color_active_index_set",
2506 "rna_Mesh_vertex_color_index_range");
2507 RNA_def_property_ui_text(prop, "Active Vertex Color Index", "Active vertex color index");
2508 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_active_color");
2509 }
2510
rna_def_vert_colors(BlenderRNA * brna,PropertyRNA * cprop)2511 static void rna_def_vert_colors(BlenderRNA *brna, PropertyRNA *cprop)
2512 {
2513 StructRNA *srna;
2514 PropertyRNA *prop;
2515
2516 FunctionRNA *func;
2517 PropertyRNA *parm;
2518
2519 RNA_def_property_srna(cprop, "VertColors");
2520 srna = RNA_def_struct(brna, "VertColors", NULL);
2521 RNA_def_struct_sdna(srna, "Mesh");
2522 RNA_def_struct_ui_text(srna, "Vert Colors", "Collection of sculpt vertex colors");
2523
2524 func = RNA_def_function(srna, "new", "rna_Mesh_sculpt_vertex_color_new");
2525 RNA_def_function_ui_description(func, "Add a sculpt vertex color layer to Mesh");
2526 RNA_def_string(func, "name", "Col", 0, "", "Sculpt Vertex color name");
2527 RNA_def_boolean(func,
2528 "do_init",
2529 true,
2530 "",
2531 "Whether new layer's data should be initialized by copying current active one");
2532 parm = RNA_def_pointer(func, "layer", "MeshVertColorLayer", "", "The newly created layer");
2533 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
2534 RNA_def_function_return(func, parm);
2535
2536 func = RNA_def_function(srna, "remove", "rna_Mesh_sculpt_vertex_color_remove");
2537 RNA_def_function_ui_description(func, "Remove a vertex color layer");
2538 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2539 parm = RNA_def_pointer(func, "layer", "MeshVertColorLayer", "", "The layer to remove");
2540 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
2541 RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
2542
2543 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2544 RNA_def_property_struct_type(prop, "MeshVertColorLayer");
2545 RNA_def_property_pointer_funcs(prop,
2546 "rna_Mesh_sculpt_vertex_color_active_get",
2547 "rna_Mesh_sculpt_vertex_color_active_set",
2548 NULL,
2549 NULL);
2550 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
2551 RNA_def_property_ui_text(
2552 prop, "Active Sculpt Vertex Color Layer", "Active sculpt vertex color layer");
2553 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_active_color");
2554
2555 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
2556 RNA_def_property_int_funcs(prop,
2557 "rna_Mesh_sculpt_vertex_color_active_index_get",
2558 "rna_Mesh_sculpt_vertex_color_active_index_set",
2559 "rna_Mesh_sculpt_vertex_color_index_range");
2560 RNA_def_property_ui_text(
2561 prop, "Active Sculpt Vertex Color Index", "Active sculpt vertex color index");
2562 RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_active_color");
2563 }
2564
rna_def_uv_layers(BlenderRNA * brna,PropertyRNA * cprop)2565 static void rna_def_uv_layers(BlenderRNA *brna, PropertyRNA *cprop)
2566 {
2567 StructRNA *srna;
2568 PropertyRNA *prop;
2569
2570 FunctionRNA *func;
2571 PropertyRNA *parm;
2572
2573 RNA_def_property_srna(cprop, "UVLoopLayers");
2574 srna = RNA_def_struct(brna, "UVLoopLayers", NULL);
2575 RNA_def_struct_sdna(srna, "Mesh");
2576 RNA_def_struct_ui_text(srna, "UV Loop Layers", "Collection of uv loop layers");
2577
2578 func = RNA_def_function(srna, "new", "rna_Mesh_uv_layers_new");
2579 RNA_def_function_ui_description(func, "Add a UV map layer to Mesh");
2580 RNA_def_string(func, "name", "UVMap", 0, "", "UV map name");
2581 RNA_def_boolean(func,
2582 "do_init",
2583 true,
2584 "",
2585 "Whether new layer's data should be initialized by copying current active one, "
2586 "or if none is active, with a default UVmap");
2587 parm = RNA_def_pointer(func, "layer", "MeshUVLoopLayer", "", "The newly created layer");
2588 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
2589 RNA_def_function_return(func, parm);
2590
2591 func = RNA_def_function(srna, "remove", "rna_Mesh_uv_layers_remove");
2592 RNA_def_function_ui_description(func, "Remove a vertex color layer");
2593 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2594 parm = RNA_def_pointer(func, "layer", "MeshUVLoopLayer", "", "The layer to remove");
2595 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
2596
2597 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2598 RNA_def_property_struct_type(prop, "MeshUVLoopLayer");
2599 RNA_def_property_pointer_funcs(
2600 prop, "rna_Mesh_uv_layer_active_get", "rna_Mesh_uv_layer_active_set", NULL, NULL);
2601 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
2602 RNA_def_property_ui_text(prop, "Active UV Loop Layer", "Active UV loop layer");
2603 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2604
2605 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
2606 RNA_def_property_int_funcs(prop,
2607 "rna_Mesh_uv_layer_active_index_get",
2608 "rna_Mesh_uv_layer_active_index_set",
2609 "rna_Mesh_uv_layer_index_range");
2610 RNA_def_property_ui_text(prop, "Active UV Loop Layer Index", "Active UV loop layer index");
2611 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2612 }
2613
2614 /* mesh float layers */
rna_def_vertex_float_layers(BlenderRNA * brna,PropertyRNA * cprop)2615 static void rna_def_vertex_float_layers(BlenderRNA *brna, PropertyRNA *cprop)
2616 {
2617 StructRNA *srna;
2618
2619 FunctionRNA *func;
2620 PropertyRNA *parm;
2621
2622 RNA_def_property_srna(cprop, "VertexFloatProperties");
2623 srna = RNA_def_struct(brna, "VertexFloatProperties", NULL);
2624 RNA_def_struct_sdna(srna, "Mesh");
2625 RNA_def_struct_ui_text(srna, "Vertex Float Properties", "Collection of float properties");
2626
2627 func = RNA_def_function(srna, "new", "rna_Mesh_vertex_float_property_new");
2628 RNA_def_function_ui_description(func, "Add a float property layer to Mesh");
2629 RNA_def_string(func, "name", "Float Prop", 0, "", "Float property name");
2630 parm = RNA_def_pointer(
2631 func, "layer", "MeshVertexFloatPropertyLayer", "", "The newly created layer");
2632 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
2633 RNA_def_function_return(func, parm);
2634 }
2635
2636 /* mesh int layers */
rna_def_vertex_int_layers(BlenderRNA * brna,PropertyRNA * cprop)2637 static void rna_def_vertex_int_layers(BlenderRNA *brna, PropertyRNA *cprop)
2638 {
2639 StructRNA *srna;
2640
2641 FunctionRNA *func;
2642 PropertyRNA *parm;
2643
2644 RNA_def_property_srna(cprop, "VertexIntProperties");
2645 srna = RNA_def_struct(brna, "VertexIntProperties", NULL);
2646 RNA_def_struct_sdna(srna, "Mesh");
2647 RNA_def_struct_ui_text(srna, "Vertex Int Properties", "Collection of int properties");
2648
2649 func = RNA_def_function(srna, "new", "rna_Mesh_vertex_int_property_new");
2650 RNA_def_function_ui_description(func, "Add a integer property layer to Mesh");
2651 RNA_def_string(func, "name", "Int Prop", 0, "", "Int property name");
2652 parm = RNA_def_pointer(
2653 func, "layer", "MeshVertexIntPropertyLayer", "", "The newly created layer");
2654 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
2655 RNA_def_function_return(func, parm);
2656 }
2657
2658 /* mesh string layers */
rna_def_vertex_string_layers(BlenderRNA * brna,PropertyRNA * cprop)2659 static void rna_def_vertex_string_layers(BlenderRNA *brna, PropertyRNA *cprop)
2660 {
2661 StructRNA *srna;
2662
2663 FunctionRNA *func;
2664 PropertyRNA *parm;
2665
2666 RNA_def_property_srna(cprop, "VertexStringProperties");
2667 srna = RNA_def_struct(brna, "VertexStringProperties", NULL);
2668 RNA_def_struct_sdna(srna, "Mesh");
2669 RNA_def_struct_ui_text(srna, "Vertex String Properties", "Collection of string properties");
2670
2671 func = RNA_def_function(srna, "new", "rna_Mesh_vertex_string_property_new");
2672 RNA_def_function_ui_description(func, "Add a string property layer to Mesh");
2673 RNA_def_string(func, "name", "String Prop", 0, "", "String property name");
2674 parm = RNA_def_pointer(
2675 func, "layer", "MeshVertexStringPropertyLayer", "", "The newly created layer");
2676 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
2677 RNA_def_function_return(func, parm);
2678 }
2679
2680 /* mesh float layers */
rna_def_polygon_float_layers(BlenderRNA * brna,PropertyRNA * cprop)2681 static void rna_def_polygon_float_layers(BlenderRNA *brna, PropertyRNA *cprop)
2682 {
2683 StructRNA *srna;
2684
2685 FunctionRNA *func;
2686 PropertyRNA *parm;
2687
2688 RNA_def_property_srna(cprop, "PolygonFloatProperties");
2689 srna = RNA_def_struct(brna, "PolygonFloatProperties", NULL);
2690 RNA_def_struct_sdna(srna, "Mesh");
2691 RNA_def_struct_ui_text(srna, "Polygon Float Properties", "Collection of float properties");
2692
2693 func = RNA_def_function(srna, "new", "rna_Mesh_polygon_float_property_new");
2694 RNA_def_function_ui_description(func, "Add a float property layer to Mesh");
2695 RNA_def_string(func, "name", "Float Prop", 0, "", "Float property name");
2696 parm = RNA_def_pointer(
2697 func, "layer", "MeshPolygonFloatPropertyLayer", "", "The newly created layer");
2698 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
2699 RNA_def_function_return(func, parm);
2700 }
2701
2702 /* mesh int layers */
rna_def_polygon_int_layers(BlenderRNA * brna,PropertyRNA * cprop)2703 static void rna_def_polygon_int_layers(BlenderRNA *brna, PropertyRNA *cprop)
2704 {
2705 StructRNA *srna;
2706
2707 FunctionRNA *func;
2708 PropertyRNA *parm;
2709
2710 RNA_def_property_srna(cprop, "PolygonIntProperties");
2711 srna = RNA_def_struct(brna, "PolygonIntProperties", NULL);
2712 RNA_def_struct_sdna(srna, "Mesh");
2713 RNA_def_struct_ui_text(srna, "Polygon Int Properties", "Collection of int properties");
2714
2715 func = RNA_def_function(srna, "new", "rna_Mesh_polygon_int_property_new");
2716 RNA_def_function_ui_description(func, "Add a integer property layer to Mesh");
2717 RNA_def_string(func, "name", "Int Prop", 0, "", "Int property name");
2718 parm = RNA_def_pointer(
2719 func, "layer", "MeshPolygonIntPropertyLayer", "", "The newly created layer");
2720 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
2721 RNA_def_function_return(func, parm);
2722 }
2723
2724 /* mesh string layers */
rna_def_polygon_string_layers(BlenderRNA * brna,PropertyRNA * cprop)2725 static void rna_def_polygon_string_layers(BlenderRNA *brna, PropertyRNA *cprop)
2726 {
2727 StructRNA *srna;
2728
2729 FunctionRNA *func;
2730 PropertyRNA *parm;
2731
2732 RNA_def_property_srna(cprop, "PolygonStringProperties");
2733 srna = RNA_def_struct(brna, "PolygonStringProperties", NULL);
2734 RNA_def_struct_sdna(srna, "Mesh");
2735 RNA_def_struct_ui_text(srna, "Polygon String Properties", "Collection of string properties");
2736
2737 func = RNA_def_function(srna, "new", "rna_Mesh_polygon_string_property_new");
2738 RNA_def_function_ui_description(func, "Add a string property layer to Mesh");
2739 RNA_def_string(func, "name", "String Prop", 0, "", "String property name");
2740 parm = RNA_def_pointer(
2741 func, "layer", "MeshPolygonStringPropertyLayer", "", "The newly created layer");
2742 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
2743 RNA_def_function_return(func, parm);
2744 }
2745
rna_def_skin_vertices(BlenderRNA * brna,PropertyRNA * UNUSED (cprop))2746 static void rna_def_skin_vertices(BlenderRNA *brna, PropertyRNA *UNUSED(cprop))
2747 {
2748 StructRNA *srna;
2749 PropertyRNA *prop;
2750
2751 srna = RNA_def_struct(brna, "MeshSkinVertexLayer", NULL);
2752 RNA_def_struct_ui_text(
2753 srna, "Mesh Skin Vertex Layer", "Per-vertex skin data for use with the Skin modifier");
2754 RNA_def_struct_sdna(srna, "CustomDataLayer");
2755 RNA_def_struct_path_func(srna, "rna_MeshSkinVertexLayer_path");
2756
2757 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2758 RNA_def_struct_name_property(srna, prop);
2759 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshVertexLayer_name_set");
2760 RNA_def_property_ui_text(prop, "Name", "Name of skin layer");
2761 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2762
2763 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
2764 RNA_def_property_struct_type(prop, "MeshSkinVertex");
2765 RNA_def_property_ui_text(prop, "Data", "");
2766 RNA_def_property_collection_funcs(prop,
2767 "rna_MeshSkinVertexLayer_data_begin",
2768 "rna_iterator_array_next",
2769 "rna_iterator_array_end",
2770 "rna_iterator_array_get",
2771 "rna_MeshSkinVertexLayer_data_length",
2772 NULL,
2773 NULL,
2774 NULL);
2775
2776 /* SkinVertex struct */
2777 srna = RNA_def_struct(brna, "MeshSkinVertex", NULL);
2778 RNA_def_struct_sdna(srna, "MVertSkin");
2779 RNA_def_struct_ui_text(
2780 srna, "Skin Vertex", "Per-vertex skin data for use with the Skin modifier");
2781 RNA_def_struct_path_func(srna, "rna_MeshSkinVertex_path");
2782
2783 prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_UNSIGNED);
2784 RNA_def_property_array(prop, 2);
2785 RNA_def_property_ui_range(prop, 0.001, 100.0, 1, 3);
2786 RNA_def_property_ui_text(prop, "Radius", "Radius of the skin");
2787 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2788
2789 /* Flags */
2790
2791 prop = RNA_def_property(srna, "use_root", PROP_BOOLEAN, PROP_NONE);
2792 RNA_def_property_boolean_sdna(prop, NULL, "flag", MVERT_SKIN_ROOT);
2793 RNA_def_property_ui_text(prop,
2794 "Root",
2795 "Vertex is a root for rotation calculations and armature generation, "
2796 "setting this flag does not clear other roots in the same mesh island");
2797 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2798
2799 prop = RNA_def_property(srna, "use_loose", PROP_BOOLEAN, PROP_NONE);
2800 RNA_def_property_boolean_sdna(prop, NULL, "flag", MVERT_SKIN_LOOSE);
2801 RNA_def_property_ui_text(
2802 prop, "Loose", "If vertex has multiple adjacent edges, it is hulled to them directly");
2803 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2804 }
2805
rna_def_paint_mask(BlenderRNA * brna,PropertyRNA * UNUSED (cprop))2806 static void rna_def_paint_mask(BlenderRNA *brna, PropertyRNA *UNUSED(cprop))
2807 {
2808 StructRNA *srna;
2809 PropertyRNA *prop;
2810
2811 srna = RNA_def_struct(brna, "MeshPaintMaskLayer", NULL);
2812 RNA_def_struct_ui_text(srna, "Mesh Paint Mask Layer", "Per-vertex paint mask data");
2813 RNA_def_struct_sdna(srna, "CustomDataLayer");
2814 RNA_def_struct_path_func(srna, "rna_MeshPaintMaskLayer_path");
2815
2816 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
2817 RNA_def_property_struct_type(prop, "MeshPaintMaskProperty");
2818 RNA_def_property_ui_text(prop, "Data", "");
2819
2820 RNA_def_property_collection_funcs(prop,
2821 "rna_MeshPaintMaskLayer_data_begin",
2822 "rna_iterator_array_next",
2823 "rna_iterator_array_end",
2824 "rna_iterator_array_get",
2825 "rna_MeshPaintMaskLayer_data_length",
2826 NULL,
2827 NULL,
2828 NULL);
2829
2830 srna = RNA_def_struct(brna, "MeshPaintMaskProperty", NULL);
2831 RNA_def_struct_sdna(srna, "MFloatProperty");
2832 RNA_def_struct_ui_text(srna, "Mesh Paint Mask Property", "Floating point paint mask value");
2833 RNA_def_struct_path_func(srna, "rna_MeshPaintMask_path");
2834
2835 prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
2836 RNA_def_property_float_sdna(prop, NULL, "f");
2837 RNA_def_property_ui_text(prop, "Value", "");
2838 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2839 }
2840
rna_def_face_map(BlenderRNA * brna)2841 static void rna_def_face_map(BlenderRNA *brna)
2842 {
2843 StructRNA *srna;
2844 PropertyRNA *prop;
2845
2846 srna = RNA_def_struct(brna, "MeshFaceMapLayer", NULL);
2847 RNA_def_struct_ui_text(srna, "Mesh Face Map Layer", "Per-face map index");
2848 RNA_def_struct_sdna(srna, "CustomDataLayer");
2849 RNA_def_struct_path_func(srna, "rna_MeshFaceMapLayer_path");
2850
2851 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2852 RNA_def_struct_name_property(srna, prop);
2853 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshPolyLayer_name_set");
2854 RNA_def_property_ui_text(prop, "Name", "Name of face-map layer");
2855 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2856
2857 prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
2858 RNA_def_property_struct_type(prop, "MeshFaceMap");
2859 RNA_def_property_ui_text(prop, "Data", "");
2860 RNA_def_property_collection_funcs(prop,
2861 "rna_MeshFaceMapLayer_data_begin",
2862 "rna_iterator_array_next",
2863 "rna_iterator_array_end",
2864 "rna_iterator_array_get",
2865 "rna_MeshFaceMapLayer_data_length",
2866 NULL,
2867 NULL,
2868 NULL);
2869
2870 /* FaceMap struct */
2871 srna = RNA_def_struct(brna, "MeshFaceMap", NULL);
2872 RNA_def_struct_sdna(srna, "MIntProperty");
2873 RNA_def_struct_ui_text(srna, "Int Property", "");
2874 RNA_def_struct_path_func(srna, "rna_MeshFaceMap_path");
2875
2876 prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
2877 RNA_def_property_int_sdna(prop, NULL, "i");
2878 RNA_def_property_ui_text(prop, "Value", "");
2879 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2880 }
2881
rna_def_face_maps(BlenderRNA * brna,PropertyRNA * cprop)2882 static void rna_def_face_maps(BlenderRNA *brna, PropertyRNA *cprop)
2883 {
2884 StructRNA *srna;
2885 PropertyRNA *prop;
2886
2887 RNA_def_property_srna(cprop, "MeshFaceMapLayers");
2888 srna = RNA_def_struct(brna, "MeshFaceMapLayers", NULL);
2889 RNA_def_struct_ui_text(srna, "Mesh Face Map Layer", "Per-face map index");
2890 RNA_def_struct_sdna(srna, "Mesh");
2891 RNA_def_struct_ui_text(srna, "Mesh FaceMaps", "Collection of mesh face-maps");
2892
2893 /* add this since we only ever have one layer anyway, don't bother with active_index */
2894 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2895 RNA_def_property_struct_type(prop, "MeshFaceMapLayer");
2896 RNA_def_property_pointer_funcs(prop, "rna_Mesh_face_map_active_get", NULL, NULL, NULL);
2897 RNA_def_property_ui_text(prop, "Active FaceMap Layer", "");
2898 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
2899
2900 FunctionRNA *func;
2901 PropertyRNA *parm;
2902
2903 func = RNA_def_function(srna, "new", "rna_Mesh_face_map_new");
2904 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2905 RNA_def_function_ui_description(func, "Add a float property layer to Mesh");
2906 RNA_def_string(func, "name", "Face Map", 0, "", "Face map name");
2907 parm = RNA_def_pointer(func, "layer", "MeshFaceMapLayer", "", "The newly created layer");
2908 RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
2909 RNA_def_function_return(func, parm);
2910
2911 func = RNA_def_function(srna, "remove", "rna_Mesh_face_map_remove");
2912 RNA_def_function_ui_description(func, "Remove a face map layer");
2913 RNA_def_function_flag(func, FUNC_USE_REPORTS);
2914 parm = RNA_def_pointer(func, "layer", "MeshFaceMapLayer", "", "The layer to remove");
2915 RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
2916 RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
2917 }
2918
rna_def_mesh(BlenderRNA * brna)2919 static void rna_def_mesh(BlenderRNA *brna)
2920 {
2921 StructRNA *srna;
2922 PropertyRNA *prop;
2923
2924 srna = RNA_def_struct(brna, "Mesh", "ID");
2925 RNA_def_struct_ui_text(srna, "Mesh", "Mesh data-block defining geometric surfaces");
2926 RNA_def_struct_ui_icon(srna, ICON_MESH_DATA);
2927
2928 prop = RNA_def_property(srna, "vertices", PROP_COLLECTION, PROP_NONE);
2929 RNA_def_property_collection_sdna(prop, NULL, "mvert", "totvert");
2930 RNA_def_property_struct_type(prop, "MeshVertex");
2931 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
2932 RNA_def_property_ui_text(prop, "Vertices", "Vertices of the mesh");
2933 rna_def_mesh_vertices(brna, prop);
2934
2935 prop = RNA_def_property(srna, "edges", PROP_COLLECTION, PROP_NONE);
2936 RNA_def_property_collection_sdna(prop, NULL, "medge", "totedge");
2937 RNA_def_property_struct_type(prop, "MeshEdge");
2938 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
2939 RNA_def_property_ui_text(prop, "Edges", "Edges of the mesh");
2940 rna_def_mesh_edges(brna, prop);
2941
2942 prop = RNA_def_property(srna, "loops", PROP_COLLECTION, PROP_NONE);
2943 RNA_def_property_collection_sdna(prop, NULL, "mloop", "totloop");
2944 RNA_def_property_struct_type(prop, "MeshLoop");
2945 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
2946 RNA_def_property_ui_text(prop, "Loops", "Loops of the mesh (polygon corners)");
2947 rna_def_mesh_loops(brna, prop);
2948
2949 prop = RNA_def_property(srna, "polygons", PROP_COLLECTION, PROP_NONE);
2950 RNA_def_property_collection_sdna(prop, NULL, "mpoly", "totpoly");
2951 RNA_def_property_struct_type(prop, "MeshPolygon");
2952 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
2953 RNA_def_property_ui_text(prop, "Polygons", "Polygons of the mesh");
2954 rna_def_mesh_polygons(brna, prop);
2955
2956 prop = RNA_def_property(srna, "loop_triangles", PROP_COLLECTION, PROP_NONE);
2957 RNA_def_property_collection_sdna(prop, NULL, "runtime.looptris.array", "runtime.looptris.len");
2958 RNA_def_property_struct_type(prop, "MeshLoopTriangle");
2959 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
2960 RNA_def_property_ui_text(prop, "Loop Triangles", "Tessellation of mesh polygons into triangles");
2961 rna_def_mesh_looptris(brna, prop);
2962
2963 /* TODO, should this be allowed to be its self? */
2964 prop = RNA_def_property(srna, "texture_mesh", PROP_POINTER, PROP_NONE);
2965 RNA_def_property_pointer_sdna(prop, NULL, "texcomesh");
2966 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
2967 RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
2968 RNA_def_property_ui_text(
2969 prop,
2970 "Texture Mesh",
2971 "Use another mesh for texture indices (vertex indices must be aligned)");
2972
2973 /* UV loop layers */
2974 prop = RNA_def_property(srna, "uv_layers", PROP_COLLECTION, PROP_NONE);
2975 RNA_def_property_collection_sdna(prop, NULL, "ldata.layers", "ldata.totlayer");
2976 RNA_def_property_collection_funcs(prop,
2977 "rna_Mesh_uv_layers_begin",
2978 NULL,
2979 NULL,
2980 NULL,
2981 "rna_Mesh_uv_layers_length",
2982 NULL,
2983 NULL,
2984 NULL);
2985 RNA_def_property_struct_type(prop, "MeshUVLoopLayer");
2986 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
2987 RNA_def_property_ui_text(prop, "UV Loop Layers", "All UV loop layers");
2988 rna_def_uv_layers(brna, prop);
2989
2990 prop = RNA_def_property(srna, "uv_layer_clone", PROP_POINTER, PROP_NONE);
2991 RNA_def_property_struct_type(prop, "MeshUVLoopLayer");
2992 RNA_def_property_pointer_funcs(
2993 prop, "rna_Mesh_uv_layer_clone_get", "rna_Mesh_uv_layer_clone_set", NULL, NULL);
2994 RNA_def_property_flag(prop, PROP_EDITABLE);
2995 RNA_def_property_ui_text(
2996 prop, "Clone UV Loop Layer", "UV loop layer to be used as cloning source");
2997
2998 prop = RNA_def_property(srna, "uv_layer_clone_index", PROP_INT, PROP_UNSIGNED);
2999 RNA_def_property_int_funcs(prop,
3000 "rna_Mesh_uv_layer_clone_index_get",
3001 "rna_Mesh_uv_layer_clone_index_set",
3002 "rna_Mesh_uv_layer_index_range");
3003 RNA_def_property_ui_text(prop, "Clone UV Loop Layer Index", "Clone UV loop layer index");
3004
3005 prop = RNA_def_property(srna, "uv_layer_stencil", PROP_POINTER, PROP_NONE);
3006 RNA_def_property_struct_type(prop, "MeshUVLoopLayer");
3007 RNA_def_property_pointer_funcs(
3008 prop, "rna_Mesh_uv_layer_stencil_get", "rna_Mesh_uv_layer_stencil_set", NULL, NULL);
3009 RNA_def_property_flag(prop, PROP_EDITABLE);
3010 RNA_def_property_ui_text(prop, "Mask UV Loop Layer", "UV loop layer to mask the painted area");
3011
3012 prop = RNA_def_property(srna, "uv_layer_stencil_index", PROP_INT, PROP_UNSIGNED);
3013 RNA_def_property_int_funcs(prop,
3014 "rna_Mesh_uv_layer_stencil_index_get",
3015 "rna_Mesh_uv_layer_stencil_index_set",
3016 "rna_Mesh_uv_layer_index_range");
3017 RNA_def_property_ui_text(prop, "Mask UV Loop Layer Index", "Mask UV loop layer index");
3018 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
3019
3020 /* Vertex colors */
3021
3022 prop = RNA_def_property(srna, "vertex_colors", PROP_COLLECTION, PROP_NONE);
3023 RNA_def_property_collection_sdna(prop, NULL, "ldata.layers", "ldata.totlayer");
3024 RNA_def_property_collection_funcs(prop,
3025 "rna_Mesh_vertex_colors_begin",
3026 NULL,
3027 NULL,
3028 NULL,
3029 "rna_Mesh_vertex_colors_length",
3030 NULL,
3031 NULL,
3032 NULL);
3033 RNA_def_property_struct_type(prop, "MeshLoopColorLayer");
3034 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
3035 RNA_def_property_ui_text(prop, "Vertex Colors", "All vertex colors");
3036 rna_def_loop_colors(brna, prop);
3037
3038 /* Sculpt Vertex colors */
3039
3040 prop = RNA_def_property(srna, "sculpt_vertex_colors", PROP_COLLECTION, PROP_NONE);
3041 RNA_def_property_collection_sdna(prop, NULL, "vdata.layers", "vdata.totlayer");
3042 RNA_def_property_collection_funcs(prop,
3043 "rna_Mesh_sculpt_vertex_colors_begin",
3044 NULL,
3045 NULL,
3046 NULL,
3047 "rna_Mesh_sculpt_vertex_colors_length",
3048 NULL,
3049 NULL,
3050 NULL);
3051 RNA_def_property_struct_type(prop, "MeshVertColorLayer");
3052 RNA_def_property_ui_text(prop, "Sculpt Vertex Colors", "All vertex colors");
3053 rna_def_vert_colors(brna, prop);
3054
3055 /* TODO, edge customdata layers (bmesh py api can access already) */
3056 prop = RNA_def_property(srna, "vertex_layers_float", PROP_COLLECTION, PROP_NONE);
3057 RNA_def_property_collection_sdna(prop, NULL, "vdata.layers", "vdata.totlayer");
3058 RNA_def_property_collection_funcs(prop,
3059 "rna_Mesh_vertex_float_layers_begin",
3060 NULL,
3061 NULL,
3062 NULL,
3063 "rna_Mesh_vertex_float_layers_length",
3064 NULL,
3065 NULL,
3066 NULL);
3067 RNA_def_property_struct_type(prop, "MeshVertexFloatPropertyLayer");
3068 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
3069 RNA_def_property_ui_text(prop, "Float Property Layers", "");
3070 rna_def_vertex_float_layers(brna, prop);
3071
3072 prop = RNA_def_property(srna, "vertex_layers_int", PROP_COLLECTION, PROP_NONE);
3073 RNA_def_property_collection_sdna(prop, NULL, "vdata.layers", "vdata.totlayer");
3074 RNA_def_property_collection_funcs(prop,
3075 "rna_Mesh_vertex_int_layers_begin",
3076 NULL,
3077 NULL,
3078 NULL,
3079 "rna_Mesh_vertex_int_layers_length",
3080 NULL,
3081 NULL,
3082 NULL);
3083 RNA_def_property_struct_type(prop, "MeshVertexIntPropertyLayer");
3084 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
3085 RNA_def_property_ui_text(prop, "Int Property Layers", "");
3086 rna_def_vertex_int_layers(brna, prop);
3087
3088 prop = RNA_def_property(srna, "vertex_layers_string", PROP_COLLECTION, PROP_NONE);
3089 RNA_def_property_collection_sdna(prop, NULL, "vdata.layers", "vdata.totlayer");
3090 RNA_def_property_collection_funcs(prop,
3091 "rna_Mesh_vertex_string_layers_begin",
3092 NULL,
3093 NULL,
3094 NULL,
3095 "rna_Mesh_vertex_string_layers_length",
3096 NULL,
3097 NULL,
3098 NULL);
3099 RNA_def_property_struct_type(prop, "MeshVertexStringPropertyLayer");
3100 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
3101 RNA_def_property_ui_text(prop, "String Property Layers", "");
3102 rna_def_vertex_string_layers(brna, prop);
3103
3104 prop = RNA_def_property(srna, "polygon_layers_float", PROP_COLLECTION, PROP_NONE);
3105 RNA_def_property_collection_sdna(prop, NULL, "pdata.layers", "pdata.totlayer");
3106 RNA_def_property_collection_funcs(prop,
3107 "rna_Mesh_polygon_float_layers_begin",
3108 NULL,
3109 NULL,
3110 NULL,
3111 "rna_Mesh_polygon_float_layers_length",
3112 NULL,
3113 NULL,
3114 NULL);
3115 RNA_def_property_struct_type(prop, "MeshPolygonFloatPropertyLayer");
3116 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
3117 RNA_def_property_ui_text(prop, "Float Property Layers", "");
3118 rna_def_polygon_float_layers(brna, prop);
3119
3120 prop = RNA_def_property(srna, "polygon_layers_int", PROP_COLLECTION, PROP_NONE);
3121 RNA_def_property_collection_sdna(prop, NULL, "pdata.layers", "pdata.totlayer");
3122 RNA_def_property_collection_funcs(prop,
3123 "rna_Mesh_polygon_int_layers_begin",
3124 NULL,
3125 NULL,
3126 NULL,
3127 "rna_Mesh_polygon_int_layers_length",
3128 NULL,
3129 NULL,
3130 NULL);
3131 RNA_def_property_struct_type(prop, "MeshPolygonIntPropertyLayer");
3132 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
3133 RNA_def_property_ui_text(prop, "Int Property Layers", "");
3134 rna_def_polygon_int_layers(brna, prop);
3135
3136 prop = RNA_def_property(srna, "polygon_layers_string", PROP_COLLECTION, PROP_NONE);
3137 RNA_def_property_collection_sdna(prop, NULL, "pdata.layers", "pdata.totlayer");
3138 RNA_def_property_collection_funcs(prop,
3139 "rna_Mesh_polygon_string_layers_begin",
3140 NULL,
3141 NULL,
3142 NULL,
3143 "rna_Mesh_polygon_string_layers_length",
3144 NULL,
3145 NULL,
3146 NULL);
3147 RNA_def_property_struct_type(prop, "MeshPolygonStringPropertyLayer");
3148 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
3149 RNA_def_property_ui_text(prop, "String Property Layers", "");
3150 rna_def_polygon_string_layers(brna, prop);
3151
3152 /* face-maps */
3153 prop = RNA_def_property(srna, "face_maps", PROP_COLLECTION, PROP_NONE);
3154 RNA_def_property_collection_sdna(prop, NULL, "pdata.layers", "pdata.totlayer");
3155 RNA_def_property_collection_funcs(prop,
3156 "rna_Mesh_face_maps_begin",
3157 NULL,
3158 NULL,
3159 NULL,
3160 "rna_Mesh_face_maps_length",
3161 NULL,
3162 NULL,
3163 NULL);
3164 RNA_def_property_struct_type(prop, "MeshFaceMapLayer");
3165 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
3166 RNA_def_property_ui_text(prop, "FaceMap", "");
3167 rna_def_face_maps(brna, prop);
3168
3169 /* Skin vertices */
3170 prop = RNA_def_property(srna, "skin_vertices", PROP_COLLECTION, PROP_NONE);
3171 RNA_def_property_collection_sdna(prop, NULL, "vdata.layers", "vdata.totlayer");
3172 RNA_def_property_collection_funcs(prop,
3173 "rna_Mesh_skin_vertices_begin",
3174 NULL,
3175 NULL,
3176 NULL,
3177 "rna_Mesh_skin_vertices_length",
3178 NULL,
3179 NULL,
3180 NULL);
3181 RNA_def_property_struct_type(prop, "MeshSkinVertexLayer");
3182 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
3183 RNA_def_property_ui_text(prop, "Skin Vertices", "All skin vertices");
3184 rna_def_skin_vertices(brna, prop);
3185 /* End skin vertices */
3186
3187 /* Paint mask */
3188 prop = RNA_def_property(srna, "vertex_paint_masks", PROP_COLLECTION, PROP_NONE);
3189 RNA_def_property_collection_sdna(prop, NULL, "vdata.layers", "vdata.totlayer");
3190 RNA_def_property_collection_funcs(prop,
3191 "rna_Mesh_vertex_paint_masks_begin",
3192 NULL,
3193 NULL,
3194 NULL,
3195 "rna_Mesh_vertex_paint_masks_length",
3196 NULL,
3197 NULL,
3198 NULL);
3199 RNA_def_property_struct_type(prop, "MeshPaintMaskLayer");
3200 RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
3201 RNA_def_property_ui_text(prop, "Vertex Paint Mask", "Vertex paint mask");
3202 rna_def_paint_mask(brna, prop);
3203 /* End paint mask */
3204
3205 /* Attributes */
3206 rna_def_attributes_common(srna);
3207
3208 /* Remesh */
3209 prop = RNA_def_property(srna, "remesh_voxel_size", PROP_FLOAT, PROP_DISTANCE);
3210 RNA_def_property_float_sdna(prop, NULL, "remesh_voxel_size");
3211 RNA_def_property_range(prop, 0.0001f, FLT_MAX);
3212 RNA_def_property_ui_range(prop, 0.0001f, FLT_MAX, 0.01, 4);
3213 RNA_def_property_ui_text(prop,
3214 "Voxel Size",
3215 "Size of the voxel in object space used for volume evaluation. Lower "
3216 "values preserve finer details");
3217 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3218
3219 prop = RNA_def_property(srna, "remesh_voxel_adaptivity", PROP_FLOAT, PROP_DISTANCE);
3220 RNA_def_property_float_sdna(prop, NULL, "remesh_voxel_adaptivity");
3221 RNA_def_property_range(prop, 0.0f, 1.0f);
3222 RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.01, 4);
3223 RNA_def_property_ui_text(
3224 prop,
3225 "Adaptivity",
3226 "Reduces the final face count by simplifying geometry where detail is not needed, "
3227 "generating triangles. A value greater than 0 disables Fix Poles");
3228 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3229
3230 prop = RNA_def_property(srna, "use_remesh_smooth_normals", PROP_BOOLEAN, PROP_NONE);
3231 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_REMESH_SMOOTH_NORMALS);
3232 RNA_def_property_ui_text(prop, "Smooth Normals", "Smooth the normals of the remesher result");
3233 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3234
3235 prop = RNA_def_property(srna, "use_remesh_fix_poles", PROP_BOOLEAN, PROP_NONE);
3236 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_REMESH_FIX_POLES);
3237 RNA_def_property_ui_text(prop, "Fix Poles", "Produces less poles and a better topology flow");
3238 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3239
3240 prop = RNA_def_property(srna, "use_remesh_preserve_volume", PROP_BOOLEAN, PROP_NONE);
3241 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_REMESH_REPROJECT_VOLUME);
3242 RNA_def_property_ui_text(
3243 prop,
3244 "Preserve Volume",
3245 "Projects the mesh to preserve the volume and details of the original mesh");
3246 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3247
3248 prop = RNA_def_property(srna, "use_remesh_preserve_paint_mask", PROP_BOOLEAN, PROP_NONE);
3249 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_REMESH_REPROJECT_PAINT_MASK);
3250 RNA_def_property_boolean_default(prop, false);
3251 RNA_def_property_ui_text(prop, "Preserve Paint Mask", "Keep the current mask on the new mesh");
3252 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3253
3254 prop = RNA_def_property(srna, "use_remesh_preserve_sculpt_face_sets", PROP_BOOLEAN, PROP_NONE);
3255 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_REMESH_REPROJECT_SCULPT_FACE_SETS);
3256 RNA_def_property_boolean_default(prop, false);
3257 RNA_def_property_ui_text(
3258 prop, "Preserve Face Sets", "Keep the current Face Sets on the new mesh");
3259 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3260
3261 prop = RNA_def_property(srna, "use_remesh_preserve_vertex_colors", PROP_BOOLEAN, PROP_NONE);
3262 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_REMESH_REPROJECT_VERTEX_COLORS);
3263 RNA_def_property_boolean_default(prop, false);
3264 RNA_def_property_ui_text(
3265 prop, "Preserve Vertex Colors", "Keep the current vertex colors on the new mesh");
3266 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3267
3268 prop = RNA_def_property(srna, "remesh_mode", PROP_ENUM, PROP_NONE);
3269 RNA_def_property_enum_sdna(prop, NULL, "remesh_mode");
3270 RNA_def_property_enum_items(prop, rna_enum_mesh_remesh_mode_items);
3271 RNA_def_property_ui_text(prop, "Remesh Mode", "");
3272 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3273
3274 /* End remesh */
3275
3276 /* Symmetry */
3277 prop = RNA_def_property(srna, "use_mirror_x", PROP_BOOLEAN, PROP_NONE);
3278 RNA_def_property_boolean_sdna(prop, NULL, "symmetry", ME_SYMMETRY_X);
3279 RNA_def_property_ui_text(prop, "X", "Enable symmetry in the X axis");
3280 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3281
3282 prop = RNA_def_property(srna, "use_mirror_y", PROP_BOOLEAN, PROP_NONE);
3283 RNA_def_property_boolean_sdna(prop, NULL, "symmetry", ME_SYMMETRY_Y);
3284 RNA_def_property_ui_text(prop, "Y", "Enable symmetry in the Y axis");
3285 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3286
3287 prop = RNA_def_property(srna, "use_mirror_z", PROP_BOOLEAN, PROP_NONE);
3288 RNA_def_property_boolean_sdna(prop, NULL, "symmetry", ME_SYMMETRY_Z);
3289 RNA_def_property_ui_text(prop, "Z", "Enable symmetry in the Z axis");
3290 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3291
3292 prop = RNA_def_property(srna, "use_mirror_vertex_group_x", PROP_BOOLEAN, PROP_NONE);
3293 RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_VERTEX_GROUPS_X_SYMMETRY);
3294 RNA_def_property_ui_text(
3295 prop, "Vertex Groups X Symmetry", "Mirror the left/right vertex groups when painting");
3296 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3297 /* End Symmetry */
3298
3299 prop = RNA_def_property(srna, "use_auto_smooth", PROP_BOOLEAN, PROP_NONE);
3300 RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_AUTOSMOOTH);
3301 RNA_def_property_ui_text(
3302 prop,
3303 "Auto Smooth",
3304 "Auto smooth (based on smooth/sharp faces/edges and angle between faces), "
3305 "or use custom split normals data if available");
3306 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
3307
3308 prop = RNA_def_property(srna, "auto_smooth_angle", PROP_FLOAT, PROP_ANGLE);
3309 RNA_def_property_float_sdna(prop, NULL, "smoothresh");
3310 RNA_def_property_range(prop, 0.0f, DEG2RADF(180.0f));
3311 RNA_def_property_ui_text(prop,
3312 "Auto Smooth Angle",
3313 "Maximum angle between face normals that will be considered as smooth "
3314 "(unused if custom split normals data are available)");
3315 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
3316
3317 RNA_define_verify_sdna(false);
3318 prop = RNA_def_property(srna, "has_custom_normals", PROP_BOOLEAN, PROP_NONE);
3319 RNA_def_property_boolean_sdna(prop, NULL, "", 0);
3320 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
3321 RNA_def_property_ui_text(
3322 prop, "Has Custom Normals", "True if there are custom split normals data in this mesh");
3323 RNA_def_property_boolean_funcs(prop, "rna_Mesh_has_custom_normals_get", NULL);
3324 RNA_define_verify_sdna(true);
3325
3326 prop = RNA_def_property(srna, "texco_mesh", PROP_POINTER, PROP_NONE);
3327 RNA_def_property_pointer_sdna(prop, NULL, "texcomesh");
3328 RNA_def_property_flag(prop, PROP_EDITABLE);
3329 RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
3330 RNA_def_property_ui_text(
3331 prop, "Texture Space Mesh", "Derive texture coordinates from another mesh");
3332
3333 prop = RNA_def_property(srna, "shape_keys", PROP_POINTER, PROP_NONE);
3334 RNA_def_property_pointer_sdna(prop, NULL, "key");
3335 RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
3336 RNA_def_property_clear_flag(prop, PROP_PTR_NO_OWNERSHIP);
3337 RNA_def_property_ui_text(prop, "Shape Keys", "");
3338
3339 /* texture space */
3340 prop = RNA_def_property(srna, "use_auto_texspace", PROP_BOOLEAN, PROP_NONE);
3341 RNA_def_property_boolean_sdna(prop, NULL, "texflag", ME_AUTOSPACE);
3342 RNA_def_property_ui_text(
3343 prop,
3344 "Auto Texture Space",
3345 "Adjust active object's texture space automatically when transforming object");
3346 RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
3347
3348 # if 0
3349 prop = RNA_def_property(srna, "texspace_location", PROP_FLOAT, PROP_TRANSLATION);
3350 RNA_def_property_array(prop, 3);
3351 RNA_def_property_ui_text(prop, "Texture Space Location", "Texture space location");
3352 RNA_def_property_editable_func(prop, "rna_Mesh_texspace_editable");
3353 RNA_def_property_float_funcs(
3354 prop, "rna_Mesh_texspace_loc_get", "rna_Mesh_texspace_loc_set", NULL);
3355 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
3356 # endif
3357
3358 /* editflag */
3359 prop = RNA_def_property(srna, "use_mirror_topology", PROP_BOOLEAN, PROP_NONE);
3360 RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_MIRROR_TOPO);
3361 RNA_def_property_ui_text(prop,
3362 "Topology Mirror",
3363 "Use topology based mirroring "
3364 "(for when both sides of mesh have matching, unique topology)");
3365
3366 prop = RNA_def_property(srna, "use_paint_mask", PROP_BOOLEAN, PROP_NONE);
3367 RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_PAINT_FACE_SEL);
3368 RNA_def_property_ui_text(prop, "Paint Mask", "Face selection masking for painting");
3369 RNA_def_property_ui_icon(prop, ICON_FACESEL, 0);
3370 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_Mesh_update_facemask");
3371
3372 prop = RNA_def_property(srna, "use_paint_mask_vertex", PROP_BOOLEAN, PROP_NONE);
3373 RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_PAINT_VERT_SEL);
3374 RNA_def_property_ui_text(prop, "Vertex Selection", "Vertex selection masking for painting");
3375 RNA_def_property_ui_icon(prop, ICON_VERTEXSEL, 0);
3376 RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_Mesh_update_vertmask");
3377
3378 /* customdata flags */
3379 prop = RNA_def_property(srna, "use_customdata_vertex_bevel", PROP_BOOLEAN, PROP_NONE);
3380 RNA_def_property_boolean_sdna(prop, NULL, "cd_flag", ME_CDFLAG_VERT_BWEIGHT);
3381 RNA_def_property_ui_text(prop, "Store Vertex Bevel Weight", "");
3382
3383 prop = RNA_def_property(srna, "use_customdata_edge_bevel", PROP_BOOLEAN, PROP_NONE);
3384 RNA_def_property_boolean_sdna(prop, NULL, "cd_flag", ME_CDFLAG_EDGE_BWEIGHT);
3385 RNA_def_property_ui_text(prop, "Store Edge Bevel Weight", "");
3386
3387 prop = RNA_def_property(srna, "use_customdata_edge_crease", PROP_BOOLEAN, PROP_NONE);
3388 RNA_def_property_boolean_sdna(prop, NULL, "cd_flag", ME_CDFLAG_EDGE_CREASE);
3389 RNA_def_property_ui_text(prop, "Store Edge Crease", "");
3390
3391 /* readonly editmesh info - use for extrude menu */
3392 prop = RNA_def_property(srna, "total_vert_sel", PROP_INT, PROP_UNSIGNED);
3393 RNA_def_property_int_funcs(prop, "rna_Mesh_tot_vert_get", NULL, NULL);
3394 RNA_def_property_ui_text(prop, "Selected Vertex Total", "Selected vertex count in editmode");
3395 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
3396
3397 prop = RNA_def_property(srna, "total_edge_sel", PROP_INT, PROP_UNSIGNED);
3398 RNA_def_property_int_funcs(prop, "rna_Mesh_tot_edge_get", NULL, NULL);
3399 RNA_def_property_ui_text(prop, "Selected Edge Total", "Selected edge count in editmode");
3400 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
3401
3402 prop = RNA_def_property(srna, "total_face_sel", PROP_INT, PROP_UNSIGNED);
3403 RNA_def_property_int_funcs(prop, "rna_Mesh_tot_face_get", NULL, NULL);
3404 RNA_def_property_ui_text(prop, "Selected Face Total", "Selected face count in editmode");
3405 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
3406
3407 prop = RNA_def_property(srna, "is_editmode", PROP_BOOLEAN, PROP_NONE);
3408 RNA_def_property_boolean_funcs(prop, "rna_Mesh_is_editmode_get", NULL);
3409 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
3410 RNA_def_property_ui_text(prop, "Is Editmode", "True when used in editmode");
3411
3412 /* pointers */
3413 rna_def_animdata_common(srna);
3414 rna_def_texmat_common(srna, "rna_Mesh_texspace_editable");
3415
3416 RNA_api_mesh(srna);
3417 }
3418
RNA_def_mesh(BlenderRNA * brna)3419 void RNA_def_mesh(BlenderRNA *brna)
3420 {
3421 rna_def_mesh(brna);
3422 rna_def_mvert(brna);
3423 rna_def_mvert_group(brna);
3424 rna_def_medge(brna);
3425 rna_def_mlooptri(brna);
3426 rna_def_mloop(brna);
3427 rna_def_mpolygon(brna);
3428 rna_def_mloopuv(brna);
3429 rna_def_mloopcol(brna);
3430 rna_def_MPropCol(brna);
3431 rna_def_mproperties(brna);
3432 rna_def_face_map(brna);
3433 }
3434
3435 #endif
3436