Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rna_mesh.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a560b54a87a0a14e5eb14d3578becdf61e9b56fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
/*
 * $Id$
 *
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor(s): Blender Foundation (2008).
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/makesrna/intern/rna_mesh.c
 *  \ingroup RNA
 */


#include <stdlib.h>

#include "RNA_define.h"

#include "rna_internal.h"

#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"

#include "WM_types.h"

#include "BLI_math_base.h"
#include "BLI_math_rotation.h"

#ifdef RNA_RUNTIME

#include "DNA_scene_types.h"

#include "BLI_editVert.h"
#include "BLI_math.h"

#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_mesh.h"


#include "ED_mesh.h" /* XXX Bad level call */

#include "WM_api.h"
#include "WM_types.h"

static void rna_Mesh_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	ID *id= ptr->id.data;

	/* cheating way for importers to avoid slow updates */
	if(id->us > 0) {
		DAG_id_tag_update(id, 0);
		WM_main_add_notifier(NC_GEOM|ND_DATA, id);
	}
}

static void rna_Mesh_update_select(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	ID *id= ptr->id.data;
	/* cheating way for importers to avoid slow updates */
	if(id->us > 0) {
		WM_main_add_notifier(NC_GEOM|ND_SELECT, id);
	}
}

void rna_Mesh_update_draw(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	ID *id= ptr->id.data;
	/* cheating way for importers to avoid slow updates */
	if(id->us > 0) {
		WM_main_add_notifier(NC_GEOM|ND_DATA, id);
	}
}

static void rna_MeshVertex_normal_get(PointerRNA *ptr, float *value)
{
	MVert *mvert= (MVert*)ptr->data;
	normal_short_to_float_v3(value, mvert->no);
}

static void rna_MeshVertex_normal_set(PointerRNA *ptr, const float *value)
{
	MVert *mvert= (MVert*)ptr->data;
	float no[3];

	copy_v3_v3(no, value);
	normalize_v3(no);
	normal_float_to_short_v3(mvert->no, no);
}

static float rna_MeshVertex_bevel_weight_get(PointerRNA *ptr)
{
	MVert *mvert= (MVert*)ptr->data;
	return mvert->bweight/255.0f;
}

static void rna_MeshVertex_bevel_weight_set(PointerRNA *ptr, float value)
{
	MVert *mvert= (MVert*)ptr->data;
	mvert->bweight= (char)(CLAMPIS(value*255.0f, 0, 255));
}

static float rna_MEdge_bevel_weight_get(PointerRNA *ptr)
{
	MEdge *medge= (MEdge*)ptr->data;
	return medge->bweight/255.0f;
}

static void rna_MEdge_bevel_weight_set(PointerRNA *ptr, float value)
{
	MEdge *medge= (MEdge*)ptr->data;
	medge->bweight= (char)(CLAMPIS(value*255.0f, 0, 255));
}

static float rna_MEdge_crease_get(PointerRNA *ptr)
{
	MEdge *medge= (MEdge*)ptr->data;
	return medge->crease/255.0f;
}

static void rna_MEdge_crease_set(PointerRNA *ptr, float value)
{
	MEdge *medge= (MEdge*)ptr->data;
	medge->crease= (char)(CLAMPIS(value*255.0f, 0, 255));
}

static void rna_MeshFace_normal_get(PointerRNA *ptr, float *values)
{
	Mesh *me= (Mesh*)ptr->id.data;
	MFace *mface= (MFace*)ptr->data;
	
	if(mface->v4)
		normal_quad_v3( values,me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co, me->mvert[mface->v4].co);
	else
		normal_tri_v3( values,me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co);
}

static float rna_MeshFace_area_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	MFace *mface= (MFace*)ptr->data;

	if(mface->v4)
		return area_quad_v3(me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co, me->mvert[mface->v4].co);
	else
		return area_tri_v3(me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co);
}

/* notice red and blue are swapped */
static void rna_MeshColor_color1_get(PointerRNA *ptr, float *values)
{
	MCol *mcol= (MCol*)ptr->data;

	values[2]= (&mcol[0].r)[0]/255.0f;
	values[1]= (&mcol[0].r)[1]/255.0f;
	values[0]= (&mcol[0].r)[2]/255.0f;
}

static void rna_MeshColor_color1_set(PointerRNA *ptr, const float *values)
{
	MCol *mcol= (MCol*)ptr->data;

	(&mcol[0].r)[2]= (char)(CLAMPIS(values[0]*255.0f, 0, 255));
	(&mcol[0].r)[1]= (char)(CLAMPIS(values[1]*255.0f, 0, 255));
	(&mcol[0].r)[0]= (char)(CLAMPIS(values[2]*255.0f, 0, 255));
}

static void rna_MeshColor_color2_get(PointerRNA *ptr, float *values)
{
	MCol *mcol= (MCol*)ptr->data;

	values[2]= (&mcol[1].r)[0]/255.0f;
	values[1]= (&mcol[1].r)[1]/255.0f;
	values[0]= (&mcol[1].r)[2]/255.0f;
}

static void rna_MeshColor_color2_set(PointerRNA *ptr, const float *values)
{
	MCol *mcol= (MCol*)ptr->data;

	(&mcol[1].r)[2]= (char)(CLAMPIS(values[0]*255.0f, 0, 255));
	(&mcol[1].r)[1]= (char)(CLAMPIS(values[1]*255.0f, 0, 255));
	(&mcol[1].r)[0]= (char)(CLAMPIS(values[2]*255.0f, 0, 255));
}

static void rna_MeshColor_color3_get(PointerRNA *ptr, float *values)
{
	MCol *mcol= (MCol*)ptr->data;

	values[2]= (&mcol[2].r)[0]/255.0f;
	values[1]= (&mcol[2].r)[1]/255.0f;
	values[0]= (&mcol[2].r)[2]/255.0f;
}

static void rna_MeshColor_color3_set(PointerRNA *ptr, const float *values)
{
	MCol *mcol= (MCol*)ptr->data;

	(&mcol[2].r)[2]= (char)(CLAMPIS(values[0]*255.0f, 0, 255));
	(&mcol[2].r)[1]= (char)(CLAMPIS(values[1]*255.0f, 0, 255));
	(&mcol[2].r)[0]= (char)(CLAMPIS(values[2]*255.0f, 0, 255));
}

static void rna_MeshColor_color4_get(PointerRNA *ptr, float *values)
{
	MCol *mcol= (MCol*)ptr->data;

	values[2]= (&mcol[3].r)[0]/255.0f;
	values[1]= (&mcol[3].r)[1]/255.0f;
	values[0]= (&mcol[3].r)[2]/255.0f;
}

static void rna_MeshColor_color4_set(PointerRNA *ptr, const float *values)
{
	MCol *mcol= (MCol*)ptr->data;

	(&mcol[3].r)[2]= (char)(CLAMPIS(values[0]*255.0f, 0, 255));
	(&mcol[3].r)[1]= (char)(CLAMPIS(values[1]*255.0f, 0, 255));
	(&mcol[3].r)[0]= (char)(CLAMPIS(values[2]*255.0f, 0, 255));
}

static void rna_Mesh_texspace_set(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	
	if (me->texflag & AUTOSPACE)
		tex_space_mesh(me);
}


static int rna_Mesh_texspace_editable(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	return (me->texflag & AUTOSPACE)? 0: PROP_EDITABLE;
}

static void rna_Mesh_texspace_loc_get(PointerRNA *ptr, float *values)
{
	Mesh *me= (Mesh *)ptr->data;
	
	if (!me->bb)
		tex_space_mesh(me);
	
	copy_v3_v3(values, me->loc);
}

static void rna_Mesh_texspace_loc_set(PointerRNA *ptr, const float *values)
{
	Mesh *me= (Mesh *)ptr->data;
	
	copy_v3_v3(me->loc, values);
}

static void rna_Mesh_texspace_size_get(PointerRNA *ptr, float *values)
{
	Mesh *me= (Mesh *)ptr->data;
	
	if (!me->bb)
		tex_space_mesh(me);
	
	copy_v3_v3(values, me->size);
}

static void rna_Mesh_texspace_size_set(PointerRNA *ptr, const float *values)
{
	Mesh *me= (Mesh *)ptr->data;
	
	copy_v3_v3(me->size, values);
}

static void rna_MeshVertex_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;

	if(me->dvert) {
		MVert *mvert= (MVert*)ptr->data;
		MDeformVert *dvert= me->dvert + (mvert-me->mvert);

		rna_iterator_array_begin(iter, (void*)dvert->dw, sizeof(MDeformWeight), dvert->totweight, 0, NULL);
	}
	else
		rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL);
}

static void rna_MeshFace_material_index_range(PointerRNA *ptr, int *min, int *max)
{
	Mesh *me= (Mesh*)ptr->id.data;
	*min= 0;
	*max= me->totcol-1;
	*max= MAX2(0, *max);
}

static CustomData *rna_mesh_fdata(Mesh *me)
{
	return (me->edit_mesh)? &me->edit_mesh->fdata: &me->fdata;
}

static int rna_CustomDataLayer_length(PointerRNA *ptr, int type)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomData *fdata= rna_mesh_fdata(me);
	CustomDataLayer *layer;
	int i, length= 0;

	for(layer=fdata->layers, i=0; i<fdata->totlayer; layer++, i++)
		if(layer->type == type)
			length++;

	return length;
}

static int rna_CustomDataLayer_active_get(PointerRNA *ptr, int type, int render)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomData *fdata= rna_mesh_fdata(me);
	int n= ((CustomDataLayer*)ptr->data) - fdata->layers;

	if(render) return (n == CustomData_get_render_layer_index(fdata, type));
	else return (n == CustomData_get_active_layer_index(fdata, type));
}

static int rna_CustomDataLayer_clone_get(PointerRNA *ptr, int type, int UNUSED(render))
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomData *fdata= rna_mesh_fdata(me);
	int n= ((CustomDataLayer*)ptr->data) - fdata->layers;

	return (n == CustomData_get_clone_layer_index(fdata, type));
}

static void rna_CustomDataLayer_active_set(PointerRNA *ptr, int value, int type, int render)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomData *fdata= rna_mesh_fdata(me);
	int n= ((CustomDataLayer*)ptr->data) - fdata->layers;

	if(value == 0)
		return;

	if(render) CustomData_set_layer_render_index(fdata, type, n);
	else CustomData_set_layer_active_index(fdata, type, n);
}

static void rna_CustomDataLayer_clone_set(PointerRNA *ptr, int value, int type, int UNUSED(render))
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomData *fdata= rna_mesh_fdata(me);
	int n= ((CustomDataLayer*)ptr->data) - fdata->layers;

	if(value == 0)
		return;

	CustomData_set_layer_clone_index(fdata, type, n);
}

static int rna_uv_texture_check(CollectionPropertyIterator *UNUSED(iter), void *data)
{
	CustomDataLayer *layer= (CustomDataLayer*)data;
	return (layer->type != CD_MTFACE);
}

static void rna_Mesh_uv_textures_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_uv_texture_check);
}

static int rna_Mesh_uv_textures_length(PointerRNA *ptr)
{
	return rna_CustomDataLayer_length(ptr, CD_MTFACE);
}

static PointerRNA rna_Mesh_active_uv_texture_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	int index= CustomData_get_active_layer_index(fdata, CD_MTFACE);
	CustomDataLayer *cdl= (index == -1)? NULL: &fdata->layers[index];

	return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl);
}

static PointerRNA rna_Mesh_uv_texture_clone_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	int index= CustomData_get_clone_layer_index(fdata, CD_MTFACE);
	CustomDataLayer *cdl= (index == -1)? NULL: &fdata->layers[index];

	return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl);
}

static PointerRNA rna_Mesh_uv_texture_stencil_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	int index= CustomData_get_stencil_layer_index(fdata, CD_MTFACE);
	CustomDataLayer *cdl= (index == -1)? NULL: &fdata->layers[index];

	return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl);
}

static void rna_Mesh_active_uv_texture_set(PointerRNA *ptr, PointerRNA value)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	CustomDataLayer *cdl;
	int a;

	for(cdl=fdata->layers, a=0; a<fdata->totlayer; cdl++, a++) {
		if(value.data == cdl) {
			CustomData_set_layer_active_index(fdata, CD_MTFACE, a);
			mesh_update_customdata_pointers(me);
			return;
		}
	}
}

static void rna_Mesh_uv_texture_clone_set(PointerRNA *ptr, PointerRNA value)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	CustomDataLayer *cdl;
	int a;

	for(cdl=fdata->layers, a=0; a<fdata->totlayer; cdl++, a++) {
		if(value.data == cdl) {
			CustomData_set_layer_clone_index(fdata, CD_MTFACE, a);
			return;
		}
	}
}

static void rna_Mesh_uv_texture_stencil_set(PointerRNA *ptr, PointerRNA value)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	CustomDataLayer *cdl;
	int a;

	for(cdl=fdata->layers, a=0; a<fdata->totlayer; cdl++, a++) {
		if(value.data == cdl) {
			CustomData_set_layer_stencil_index(fdata, CD_MTFACE, a);
			return;
		}
	}
}

static int rna_Mesh_active_uv_texture_index_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	return CustomData_get_active_layer(fdata, CD_MTFACE);
}

static int rna_Mesh_uv_texture_clone_index_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	return CustomData_get_clone_layer(fdata, CD_MTFACE);
}

static int rna_Mesh_uv_texture_stencil_index_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	return CustomData_get_stencil_layer(fdata, CD_MTFACE);
}

static void rna_Mesh_active_uv_texture_index_set(PointerRNA *ptr, int value)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);

	CustomData_set_layer_active(fdata, CD_MTFACE, value);
	mesh_update_customdata_pointers(me);
}

static void rna_Mesh_uv_texture_clone_index_set(PointerRNA *ptr, int value)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);

	CustomData_set_layer_clone(fdata, CD_MTFACE, value);
}

static void rna_Mesh_uv_texture_stencil_index_set(PointerRNA *ptr, int value)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);

	CustomData_set_layer_stencil(fdata, CD_MTFACE, value);
}

static void rna_Mesh_active_uv_texture_index_range(PointerRNA *ptr, int *min, int *max)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);

	*min= 0;
	*max= CustomData_number_of_layers(fdata, CD_MTFACE)-1;
	*max= MAX2(0, *max);
}

static PointerRNA rna_Mesh_active_mtface_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	EditMesh *em= BKE_mesh_get_editmesh(me);
	MTFace *tf;

	if (em && EM_texFaceCheck(em))
	{
		tf = EM_get_active_mtface(em, NULL, NULL, 1);

		return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFace, tf);
	}

	return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFace, NULL);
}

static void rna_MeshTextureFace_uv1_get(PointerRNA *ptr, float *values)
{
	MTFace *mtface= (MTFace*)ptr->data;
	
	values[0]= mtface->uv[0][0];
	values[1]= mtface->uv[0][1];
}

static void rna_MeshTextureFace_uv1_set(PointerRNA *ptr, const float *values)
{
	MTFace *mtface= (MTFace*)ptr->data;

	mtface->uv[0][0]= values[0];
	mtface->uv[0][1]= values[1];
}

static void rna_MeshTextureFace_uv2_get(PointerRNA *ptr, float *values)
{
	MTFace *mtface= (MTFace*)ptr->data;

	values[0]= mtface->uv[1][0];
	values[1]= mtface->uv[1][1];
}

static void rna_MeshTextureFace_uv2_set(PointerRNA *ptr, const float *values)
{
	MTFace *mtface= (MTFace*)ptr->data;

	mtface->uv[1][0]= values[0];
	mtface->uv[1][1]= values[1];
}

static void rna_MeshTextureFace_uv3_get(PointerRNA *ptr, float *values)
{
	MTFace *mtface= (MTFace*)ptr->data;

	values[0]= mtface->uv[2][0];
	values[1]= mtface->uv[2][1];
}

static void rna_MeshTextureFace_uv3_set(PointerRNA *ptr, const float *values)
{
	MTFace *mtface= (MTFace*)ptr->data;

	mtface->uv[2][0]= values[0];
	mtface->uv[2][1]= values[1];
}

static void rna_MeshTextureFace_uv4_get(PointerRNA *ptr, float *values)
{
	MTFace *mtface= (MTFace*)ptr->data;

	values[0]= mtface->uv[3][0];
	values[1]= mtface->uv[3][1];
}

static void rna_MeshTextureFace_uv4_set(PointerRNA *ptr, const float *values)
{
	MTFace *mtface= (MTFace*)ptr->data;

	mtface->uv[3][0]= values[0];
	mtface->uv[3][1]= values[1];
}

static int rna_CustomDataData_numverts(PointerRNA *ptr, int type)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomData *fdata= rna_mesh_fdata(me);
	CustomDataLayer *cdl;
	int a, b;

	for(cdl=fdata->layers, a=0; a<fdata->totlayer; cdl++, a++) {
		if(cdl->type == type) {
			b= ((char*)ptr->data - ((char*)cdl->data))/CustomData_sizeof(type);
			if(b >= 0 && b < me->totface)
				return (me->mface[b].v4? 4: 3);
		}
	}

	return 0;
}

static int rna_MeshTextureFace_uv_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
{
	length[0]= rna_CustomDataData_numverts(ptr, CD_MTFACE);
	length[1]= 2;
	return length[0]*length[1];
}

static void rna_MeshTextureFace_uv_get(PointerRNA *ptr, float *values)
{
	MTFace *mtface= (MTFace*)ptr->data;
	int totvert= rna_CustomDataData_numverts(ptr, CD_MTFACE);

	memcpy(values, mtface->uv, totvert * 2 * sizeof(float));
}

static void rna_MeshTextureFace_uv_set(PointerRNA *ptr, const float *values)
{
	MTFace *mtface= (MTFace*)ptr->data;
	int totvert= rna_CustomDataData_numverts(ptr, CD_MTFACE);

	memcpy(mtface->uv, values, totvert * 2 * sizeof(float));
}

static void rna_MeshTextureFaceLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomDataLayer *layer= (CustomDataLayer*)ptr->data;
	rna_iterator_array_begin(iter, layer->data, sizeof(MTFace), (me->edit_mesh)? 0: me->totface, 0, NULL);
}

static int rna_MeshTextureFaceLayer_data_length(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	return (me->edit_mesh)? 0: me->totface;
}

static int rna_MeshTextureFaceLayer_active_render_get(PointerRNA *ptr)
{
	return rna_CustomDataLayer_active_get(ptr, CD_MTFACE, 1);
}

static int rna_MeshTextureFaceLayer_active_get(PointerRNA *ptr)
{
	return rna_CustomDataLayer_active_get(ptr, CD_MTFACE, 0);
}

static int rna_MeshTextureFaceLayer_clone_get(PointerRNA *ptr)
{
	return rna_CustomDataLayer_clone_get(ptr, CD_MTFACE, 0);
}

static void rna_MeshTextureFaceLayer_active_render_set(PointerRNA *ptr, int value)
{
	rna_CustomDataLayer_active_set(ptr, value, CD_MTFACE, 1);
}

static void rna_MeshTextureFaceLayer_active_set(PointerRNA *ptr, int value)
{
	rna_CustomDataLayer_active_set(ptr, value, CD_MTFACE, 0);
}

static void rna_MeshTextureFaceLayer_clone_set(PointerRNA *ptr, int value)
{
	rna_CustomDataLayer_clone_set(ptr, value, CD_MTFACE, 0);
}

static void rna_MeshTextureFaceLayer_name_set(PointerRNA *ptr, const char *value)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomData *fdata= rna_mesh_fdata(me);
	CustomDataLayer *cdl= (CustomDataLayer*)ptr->data;
	BLI_strncpy_utf8(cdl->name, value, sizeof(cdl->name));
	CustomData_set_layer_unique_name(fdata, cdl - fdata->layers);
}

static int rna_vertex_color_check(CollectionPropertyIterator *UNUSED(iter), void *data)
{
	CustomDataLayer *layer= (CustomDataLayer*)data;
	return (layer->type != CD_MCOL);
}

static void rna_Mesh_vertex_colors_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_vertex_color_check);
}

static int rna_Mesh_vertex_colors_length(PointerRNA *ptr)
{
	return rna_CustomDataLayer_length(ptr, CD_MCOL);
}

static PointerRNA rna_Mesh_active_vertex_color_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	int index= CustomData_get_active_layer_index(fdata, CD_MCOL);
	CustomDataLayer *cdl= (index == -1)? NULL: &fdata->layers[index];

	return rna_pointer_inherit_refine(ptr, &RNA_MeshColorLayer, cdl);
}

static void rna_Mesh_active_vertex_color_set(PointerRNA *ptr, PointerRNA value)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	CustomDataLayer *cdl;
	int a;

	for(cdl=fdata->layers, a=0; a<fdata->totlayer; cdl++, a++) {
		if(value.data == cdl) {
			CustomData_set_layer_active_index(fdata, CD_MCOL, a);
			mesh_update_customdata_pointers(me);
			return;
		}
	}
}

static int rna_Mesh_active_vertex_color_index_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	return CustomData_get_active_layer(fdata, CD_MCOL);
}

static void rna_Mesh_active_vertex_color_index_set(PointerRNA *ptr, int value)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);

	CustomData_set_layer_active(fdata, CD_MCOL, value);
	mesh_update_customdata_pointers(me);
}

static void rna_Mesh_active_vertex_color_index_range(PointerRNA *ptr, int *min, int *max)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);

	*min= 0;
	*max= CustomData_number_of_layers(fdata, CD_MCOL)-1;
	*max= MAX2(0, *max);
}

static void rna_MeshColorLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomDataLayer *layer= (CustomDataLayer*)ptr->data;
	rna_iterator_array_begin(iter, layer->data, sizeof(MCol)*4, (me->edit_mesh)? 0: me->totface, 0, NULL);
}

static int rna_MeshColorLayer_data_length(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	return (me->edit_mesh)? 0: me->totface;
}

static int rna_MeshColorLayer_active_render_get(PointerRNA *ptr)
{
	return rna_CustomDataLayer_active_get(ptr, CD_MCOL, 1);
}

static int rna_MeshColorLayer_active_get(PointerRNA *ptr)
{
	return rna_CustomDataLayer_active_get(ptr, CD_MCOL, 0);
}

static void rna_MeshColorLayer_active_render_set(PointerRNA *ptr, int value)
{
	rna_CustomDataLayer_active_set(ptr, value, CD_MCOL, 1);
}

static void rna_MeshColorLayer_active_set(PointerRNA *ptr, int value)
{
	rna_CustomDataLayer_active_set(ptr, value, CD_MCOL, 0);
}

static void rna_MeshColorLayer_name_set(PointerRNA *ptr, const char *value)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomData *fdata= rna_mesh_fdata(me);
	CustomDataLayer *cdl= (CustomDataLayer*)ptr->data;
	BLI_strncpy_utf8(cdl->name, value, sizeof(cdl->name));
	CustomData_set_layer_unique_name(fdata, cdl - fdata->layers);
}

static void rna_MeshFloatPropertyLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomDataLayer *layer= (CustomDataLayer*)ptr->data;
	rna_iterator_array_begin(iter, layer->data, sizeof(MFloatProperty), (me->edit_mesh)? 0: me->totface, 0, NULL);
}

static int rna_MeshFloatPropertyLayer_data_length(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	return (me->edit_mesh)? 0: me->totface;
}

static int rna_float_layer_check(CollectionPropertyIterator *UNUSED(iter), void *data)
{
	CustomDataLayer *layer= (CustomDataLayer*)data;
	return (layer->type != CD_PROP_FLT);
}

static void rna_Mesh_float_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_float_layer_check);
}

static int rna_Mesh_float_layers_length(PointerRNA *ptr)
{
	return rna_CustomDataLayer_length(ptr, CD_PROP_FLT);
}

static int rna_int_layer_check(CollectionPropertyIterator *UNUSED(iter), void *data)
{
	CustomDataLayer *layer= (CustomDataLayer*)data;
	return (layer->type != CD_PROP_INT);
}

static void rna_MeshIntPropertyLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomDataLayer *layer= (CustomDataLayer*)ptr->data;
	rna_iterator_array_begin(iter, layer->data, sizeof(MIntProperty), (me->edit_mesh)? 0: me->totface, 0, NULL);
}

static int rna_MeshIntPropertyLayer_data_length(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	return (me->edit_mesh)? 0: me->totface;
}

static void rna_Mesh_int_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_int_layer_check);
}

static int rna_Mesh_int_layers_length(PointerRNA *ptr)
{
	return rna_CustomDataLayer_length(ptr, CD_PROP_INT);
}

static int rna_string_layer_check(CollectionPropertyIterator *UNUSED(iter), void *data)
{
	CustomDataLayer *layer= (CustomDataLayer*)data;
	return (layer->type != CD_PROP_STR);
}

static void rna_MeshStringPropertyLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomDataLayer *layer= (CustomDataLayer*)ptr->data;
	rna_iterator_array_begin(iter, layer->data, sizeof(MStringProperty), (me->edit_mesh)? 0: me->totface, 0, NULL);
}

static int rna_MeshStringPropertyLayer_data_length(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	return (me->edit_mesh)? 0: me->totface;
}

static void rna_Mesh_string_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->data;
	CustomData *fdata= rna_mesh_fdata(me);
	rna_iterator_array_begin(iter, (void*)fdata->layers, sizeof(CustomDataLayer), fdata->totlayer, 0, rna_string_layer_check);
}

static int rna_Mesh_string_layers_length(PointerRNA *ptr)
{
	return rna_CustomDataLayer_length(ptr, CD_PROP_STR);
}

static void rna_TextureFace_image_set(PointerRNA *ptr, PointerRNA value)
{
	MTFace *tf= (MTFace*)ptr->data;
	ID *id= value.data;

	if(id) {
		/* special exception here, individual faces don't count
		 * as reference, but we do ensure the refcount is not zero */
		if(id->us == 0)
			id_us_plus(id);
		else
			id_lib_extern(id);
	}

	tf->tpage= (struct Image*)id;
}

static void rna_Mesh_auto_smooth_angle_set(PointerRNA *ptr, float value)
{
	Mesh *me= (Mesh*)ptr->id.data;
	value= RAD2DEGF(value);
	CLAMP(value, 1.0f, 80.0f);
	me->smoothresh= (int)value;
}

static float rna_Mesh_auto_smooth_angle_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	return DEG2RADF((float)me->smoothresh);
}

static int rna_MeshFace_verts_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
{
	MFace *face= (MFace*)ptr->data;

	if(face)
		length[0]= (face->v4)? 4: 3;
	else
		length[0]= 4; // XXX rna_raw_access wants the length of a dummy face. this needs fixing. - Campbell

	return length[0];
}

static void rna_MeshFace_verts_get(PointerRNA *ptr, int *values)
{
	MFace *face= (MFace*)ptr->data;
	memcpy(values, &face->v1, (face->v4 ? 4 : 3) * sizeof(int));
}

static void rna_MeshFace_verts_set(PointerRNA *ptr, const int *values)
{
	MFace *face= (MFace*)ptr->data;
	memcpy(&face->v1, values, (face->v4 ? 4 : 3) * sizeof(int));
}

static int rna_MeshVertex_index_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	MVert *vert= (MVert*)ptr->data;
	return (int)(vert - me->mvert);
}

static int rna_MeshEdge_index_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	MEdge *edge= (MEdge*)ptr->data;
	return (int)(edge - me->medge);
}

static int rna_MeshFace_index_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	MFace *face= (MFace*)ptr->data;
	return (int)(face - me->mface);
}

/* path construction */

static char *rna_VertexGroupElement_path(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data; /* XXX not always! */
	MDeformWeight *dw= (MDeformWeight*)ptr->data;
	MDeformVert *dvert;
	int a, b;
	
	/* sanity check: make sure that mesh pointer is valid */
	if (me == NULL) 
		return NULL;
	else if (GS(me->id.name) != ID_ME) {
		/* if object pointer, try to resolve the object's data to mesh pointer */
		if (GS(me->id.name) == ID_OB) {
			Object *ob = (Object *)me;
			
			if (ob->type == OB_MESH)
				me = (Mesh *)ob->data;
			else
				return NULL; /* nothing can be done */
		}
		else
			return NULL; /* nothing can be done */
	}
	
	for(a=0, dvert=me->dvert; a<me->totvert; a++, dvert++) {
		for(b=0; b<dvert->totweight; b++) {
			if(dw == &dvert->dw[b])
				return BLI_sprintfN("vertices[%d].groups[%d]", a, b);
		}
	}

	return NULL;
}

static char *rna_MeshFace_path(PointerRNA *ptr)
{
	return BLI_sprintfN("faces[%d]", (int)((MFace*)ptr->data - ((Mesh*)ptr->id.data)->mface));
}

static char *rna_MeshEdge_path(PointerRNA *ptr)
{
	return BLI_sprintfN("edges[%d]", (int)((MEdge*)ptr->data - ((Mesh*)ptr->id.data)->medge));
}

static char *rna_MeshVertex_path(PointerRNA *ptr)
{
	return BLI_sprintfN("vertices[%d]", (int)((MVert*)ptr->data - ((Mesh*)ptr->id.data)->mvert));
}

static char *rna_MeshTextureFaceLayer_path(PointerRNA *ptr)
{
	return BLI_sprintfN("uv_textures[\"%s\"]", ((CustomDataLayer*)ptr->data)->name);
}

static char *rna_CustomDataData_path(PointerRNA *ptr, char *collection, int type)
{
	Mesh *me= (Mesh*)ptr->id.data;
	CustomData *fdata= rna_mesh_fdata(me);
	CustomDataLayer *cdl;
	int a, b;

	for(cdl=fdata->layers, a=0; a<fdata->totlayer; cdl++, a++) {
		if(cdl->type == type) {
			b= ((char*)ptr->data - ((char*)cdl->data))/CustomData_sizeof(type);
			if(b >= 0 && b < me->totface)
				return BLI_sprintfN("%s[\"%s\"].data[%d]", collection, cdl->name, b);
		}
	}

	return NULL;
}

static char *rna_MeshTextureFace_path(PointerRNA *ptr)
{
	return rna_CustomDataData_path(ptr, "uv_textures", CD_MTFACE);
}

static char *rna_MeshColorLayer_path(PointerRNA *ptr)
{
	return BLI_sprintfN("vertex_colors[\"%s\"]", ((CustomDataLayer*)ptr->data)->name);
}

static char *rna_MeshColor_path(PointerRNA *ptr)
{
	return rna_CustomDataData_path(ptr, "vertex_colors", CD_MCOL);
}

static char *rna_MeshSticky_path(PointerRNA *ptr)
{
	return BLI_sprintfN("sticky[%d]", (int)((MSticky*)ptr->data - ((Mesh*)ptr->id.data)->msticky));
}

static char *rna_MeshIntPropertyLayer_path(PointerRNA *ptr)
{
	return BLI_sprintfN("int_layers[\"%s\"]", ((CustomDataLayer*)ptr->data)->name);
}

static char *rna_MeshIntProperty_path(PointerRNA *ptr)
{
	return rna_CustomDataData_path(ptr, "layers_int", CD_MCOL);
}

static char *rna_MeshFloatPropertyLayer_path(PointerRNA *ptr)
{
	return BLI_sprintfN("float_layers[\"%s\"]", ((CustomDataLayer*)ptr->data)->name);
}

static char *rna_MeshFloatProperty_path(PointerRNA *ptr)
{
	return rna_CustomDataData_path(ptr, "layers_float", CD_MCOL);
}

static char *rna_MeshStringPropertyLayer_path(PointerRNA *ptr)
{
	return BLI_sprintfN("string_layers[\"%s\"]", ((CustomDataLayer*)ptr->data)->name);
}

static char *rna_MeshStringProperty_path(PointerRNA *ptr)
{
	return rna_CustomDataData_path(ptr, "layers_string", CD_MCOL);
}

static int rna_Mesh_tot_vert_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	return me->edit_mesh ? me->edit_mesh->totvertsel : 0;
}
static int rna_Mesh_tot_edge_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	return me->edit_mesh ? me->edit_mesh->totedgesel: 0;
}
static int rna_Mesh_tot_face_get(PointerRNA *ptr)
{
	Mesh *me= (Mesh*)ptr->id.data;
	return me->edit_mesh ? me->edit_mesh->totfacesel : 0;
}

static CustomDataLayer *rna_Mesh_vertex_color_new(struct Mesh *me, struct bContext *C, const char *name)
{
	CustomData *fdata;
	CustomDataLayer *cdl= NULL;
	int index;

	if(ED_mesh_color_add(C, NULL, NULL, me, name, FALSE)) {
		fdata= rna_mesh_fdata(me);
		index= CustomData_get_named_layer_index(fdata, CD_MCOL, name);
		cdl= (index == -1)? NULL: &fdata->layers[index];
	}
	return cdl;
}

static CustomDataLayer *rna_Mesh_uv_texture_new(struct Mesh *me, struct bContext *C, const char *name)
{
	CustomData *fdata;
	CustomDataLayer *cdl= NULL;
	int index;

	if(ED_mesh_uv_texture_add(C, me, name, FALSE)) {
		fdata= rna_mesh_fdata(me);
		index= CustomData_get_named_layer_index(fdata, CD_MTFACE, name);
		cdl= (index == -1)? NULL: &fdata->layers[index];
	}
	return cdl;
}

#else

static void rna_def_mvert_group(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna= RNA_def_struct(brna, "VertexGroupElement", NULL);
	RNA_def_struct_sdna(srna, "MDeformWeight");
	RNA_def_struct_path_func(srna, "rna_VertexGroupElement_path");
	RNA_def_struct_ui_text(srna, "Vertex Group Element", "Weight value of a vertex in a vertex group");
	RNA_def_struct_ui_icon(srna, ICON_GROUP_VERTEX);

	/* we can't point to actual group, it is in the object and so
	 * there is no unique group to point to, hence the index */
	prop= RNA_def_property(srna, "group", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_sdna(prop, NULL, "def_nr");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Group Index", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "weight", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_ui_text(prop, "Weight", "Vertex Weight");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
}

static void rna_def_mvert(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna= RNA_def_struct(brna, "MeshVertex", NULL);
	RNA_def_struct_sdna(srna, "MVert");
	RNA_def_struct_ui_text(srna, "Mesh Vertex", "Vertex in a Mesh datablock");
	RNA_def_struct_path_func(srna, "rna_MeshVertex_path");
	RNA_def_struct_ui_icon(srna, ICON_VERTEXSEL);

	prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_ui_text(prop, "Location", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
	// RNA_def_property_float_sdna(prop, NULL, "no");
	RNA_def_property_array(prop, 3);
	RNA_def_property_range(prop, -1.0f, 1.0f);
	RNA_def_property_float_funcs(prop, "rna_MeshVertex_normal_get", "rna_MeshVertex_normal_set", NULL);
	RNA_def_property_ui_text(prop, "Normal", "Vertex Normal");

	prop= RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
	RNA_def_property_ui_text(prop, "Select", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_select");

	prop= RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_HIDE);
	RNA_def_property_ui_text(prop, "Hide", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_select");

	prop= RNA_def_property(srna, "bevel_weight", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_funcs(prop, "rna_MeshVertex_bevel_weight_get", "rna_MeshVertex_bevel_weight_set", NULL);
	RNA_def_property_ui_text(prop, "Bevel Weight", "Weight used by the Bevel modifier 'Only Vertices' option");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "groups", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_funcs(prop, "rna_MeshVertex_groups_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", 0, 0, 0);
	RNA_def_property_struct_type(prop, "VertexGroupElement");
	RNA_def_property_ui_text(prop, "Groups", "Weights for the vertex groups this vertex is member of");

	prop= RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_int_funcs(prop, "rna_MeshVertex_index_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Index", "Index number of the vertex");
}

static void rna_def_medge(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna= RNA_def_struct(brna, "MeshEdge", NULL);
	RNA_def_struct_sdna(srna, "MEdge");
	RNA_def_struct_ui_text(srna, "Mesh Edge", "Edge in a Mesh datablock");
	RNA_def_struct_path_func(srna, "rna_MeshEdge_path");
	RNA_def_struct_ui_icon(srna, ICON_EDGESEL);

	prop= RNA_def_property(srna, "vertices", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_sdna(prop, NULL, "v1");
	RNA_def_property_array(prop, 2);
	RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");
	// XXX allows creating invalid meshes

	prop= RNA_def_property(srna, "crease", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_funcs(prop, "rna_MEdge_crease_get", "rna_MEdge_crease_set", NULL);
	RNA_def_property_ui_text(prop, "Crease", "Weight used by the Subsurf modifier for creasing");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "bevel_weight", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_funcs(prop, "rna_MEdge_bevel_weight_get", "rna_MEdge_bevel_weight_set", NULL);
	RNA_def_property_ui_text(prop, "Bevel Weight", "Weight used by the Bevel modifier");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
	RNA_def_property_ui_text(prop, "Select", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_select");

	prop= RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_HIDE);
	RNA_def_property_ui_text(prop, "Hide", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_select");

	prop= RNA_def_property(srna, "use_seam", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_SEAM);
	RNA_def_property_ui_text(prop, "Seam", "Seam edge for UV unwrapping");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_select");

	prop= RNA_def_property(srna, "use_edge_sharp", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_SHARP);
	RNA_def_property_ui_text(prop, "Sharp", "Sharp edge for the EdgeSplit modifier");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "is_loose", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_LOOSEEDGE);
	RNA_def_property_ui_text(prop, "Loose", "Loose edge");

	prop= RNA_def_property(srna, "is_fgon", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_FGON);
	RNA_def_property_ui_text(prop, "Fgon", "Fgon edge");

	prop= RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_int_funcs(prop, "rna_MeshEdge_index_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Index", "Index number of the vertex");
}

static void rna_def_mface(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna= RNA_def_struct(brna, "MeshFace", NULL);
	RNA_def_struct_sdna(srna, "MFace");
	RNA_def_struct_ui_text(srna, "Mesh Face", "Face in a Mesh datablock");
	RNA_def_struct_path_func(srna, "rna_MeshFace_path");
	RNA_def_struct_ui_icon(srna, ICON_FACESEL);

	// XXX allows creating invalid meshes
	prop= RNA_def_property(srna, "vertices", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_array(prop, 4);
	RNA_def_property_flag(prop, PROP_DYNAMIC);
	RNA_def_property_dynamic_array_funcs(prop, "rna_MeshFace_verts_get_length");
	RNA_def_property_int_funcs(prop, "rna_MeshFace_verts_get", "rna_MeshFace_verts_set", NULL);
	RNA_def_property_ui_text(prop, "Vertices", "Vertex indices");

	/* leaving this fixed size array for foreach_set used in import scripts */
	prop= RNA_def_property(srna, "vertices_raw", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_sdna(prop, NULL, "v1");
	RNA_def_property_array(prop, 4);
	RNA_def_property_ui_text(prop, "Vertices", "Fixed size vertex indices array");

	prop= RNA_def_property(srna, "material_index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_sdna(prop, NULL, "mat_nr");
	RNA_def_property_ui_text(prop, "Material Index", "");
	RNA_def_property_int_funcs(prop, NULL, NULL, "rna_MeshFace_material_index_range");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_FACE_SEL);
	RNA_def_property_ui_text(prop, "Select", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_select");

	prop= RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_HIDE);
	RNA_def_property_ui_text(prop, "Hide", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_select");

	prop= RNA_def_property(srna, "use_smooth", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_SMOOTH);
	RNA_def_property_ui_text(prop, "Smooth", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
	
	prop= RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
	RNA_def_property_array(prop, 3);
	RNA_def_property_range(prop, -1.0f, 1.0f);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_float_funcs(prop, "rna_MeshFace_normal_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "face normal", "local space unit length normal vector for this face");

	prop= RNA_def_property(srna, "area", PROP_FLOAT, PROP_UNSIGNED);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_float_funcs(prop, "rna_MeshFace_area_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "face area", "read only area of the face");

	prop= RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_int_funcs(prop, "rna_MeshFace_index_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Index", "Index number of the vertex");
}

static void rna_def_mtface(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	static const EnumPropertyItem transp_items[]= {
		{TF_SOLID, "OPAQUE", 0, "Opaque", "Render color of textured face as color"},
		{TF_ADD, "ADD", 0, "Add", "Render face transparent and add color of face"},
		{TF_ALPHA, "ALPHA", 0, "Alpha", "Render polygon transparent, depending on alpha channel of the texture"},
		{TF_CLIP, "CLIPALPHA", 0, "Clip Alpha", "Use the images alpha values clipped with no blending (binary alpha)"},
		{0, NULL, 0, NULL, NULL}};
	const int uv_dim[]= {4, 2};

	srna= RNA_def_struct(brna, "MeshTextureFaceLayer", NULL);
	RNA_def_struct_ui_text(srna, "Mesh Texture Face Layer", "Layer of texture faces in a Mesh datablock");
	RNA_def_struct_sdna(srna, "CustomDataLayer");
	RNA_def_struct_path_func(srna, "rna_MeshTextureFaceLayer_path");
	RNA_def_struct_ui_icon(srna, ICON_GROUP_UVS);

	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_struct_name_property(srna, prop);
	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshTextureFaceLayer_name_set");
	RNA_def_property_ui_text(prop, "Name", "Name of UV unwrapping layer");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_funcs(prop, "rna_MeshTextureFaceLayer_active_get", "rna_MeshTextureFaceLayer_active_set");
	RNA_def_property_ui_text(prop, "Active", "Sets the layer as active for display and editing");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "active_render", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "active_rnd", 0);
	RNA_def_property_boolean_funcs(prop, "rna_MeshTextureFaceLayer_active_render_get", "rna_MeshTextureFaceLayer_active_render_set");
	RNA_def_property_ui_text(prop, "Active Render", "Sets the layer as active for rendering");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "active_clone", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "active_clone", 0);
	RNA_def_property_boolean_funcs(prop, "rna_MeshTextureFaceLayer_clone_get", "rna_MeshTextureFaceLayer_clone_set");
	RNA_def_property_ui_text(prop, "Active Clone", "Sets the layer as active for cloning");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "MeshTextureFace");
	RNA_def_property_ui_text(prop, "Data", "");
	RNA_def_property_collection_funcs(prop, "rna_MeshTextureFaceLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshTextureFaceLayer_data_length", 0, 0);

	srna= RNA_def_struct(brna, "MeshTextureFace", NULL);
	RNA_def_struct_sdna(srna, "MTFace");
	RNA_def_struct_ui_text(srna, "Mesh Texture Face", "UV mapping, texturing and game engine data for a face");
	RNA_def_struct_path_func(srna, "rna_MeshTextureFace_path");
	RNA_def_struct_ui_icon(srna, ICON_FACESEL_HLT);

	prop= RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "tpage");
	RNA_def_property_pointer_funcs(prop, NULL, "rna_TextureFace_image_set", NULL, NULL);
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Image", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_image", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_TEX);
	RNA_def_property_ui_text(prop, "Tex", "Render face with texture");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_light", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_LIGHT);
	RNA_def_property_ui_text(prop, "Light", "Use light for face");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_INVISIBLE);
	RNA_def_property_ui_text(prop, "Invisible", "Make face invisible");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_collision", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_DYNAMIC);
	RNA_def_property_ui_text(prop, "Collision", "Use face for collision and ray-sensor detection");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_blend_shared", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_SHAREDCOL);
	RNA_def_property_ui_text(prop, "Shared", "Blend vertex colors across face when vertices are shared");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_twoside", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_TWOSIDE);
	RNA_def_property_ui_text(prop, "Two-side", "Render face two-sided");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_object_color", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_OBCOL);
	RNA_def_property_ui_text(prop, "Object Color", "Use ObColor instead of vertex colors");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_halo", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_BILLBOARD);
	RNA_def_property_ui_text(prop, "Halo", "Screen aligned billboard");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_billboard", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_BILLBOARD2);
	RNA_def_property_ui_text(prop, "Billboard", "Billboard with Z-axis constraint");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_shadow_cast", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_SHADOW);
	RNA_def_property_ui_text(prop, "Shadow", "Face is used for shadow");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_bitmap_text", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_BMFONT);
	RNA_def_property_ui_text(prop, "Text", "Enable bitmap text on face");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "use_alpha_sort", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "mode", TF_ALPHASORT);
	RNA_def_property_ui_text(prop, "Alpha Sort", "Enable sorting of faces for correct alpha drawing (slow, use Clip Alpha instead when possible)");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "blend_type", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "transp");
	RNA_def_property_enum_items(prop, transp_items);
	RNA_def_property_ui_text(prop, "Transparency", "Transparency blending mode");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "select_uv", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", TF_SEL1);
	RNA_def_property_array(prop, 4);
	RNA_def_property_ui_text(prop, "UV Selected", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_select");

	prop= RNA_def_property(srna, "pin_uv", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "unwrap", TF_PIN1);
	RNA_def_property_array(prop, 4);
	RNA_def_property_ui_text(prop, "UV Pinned", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_select");

	prop= RNA_def_property(srna, "uv1", PROP_FLOAT, PROP_XYZ);
	RNA_def_property_array(prop, 2);
	RNA_def_property_float_funcs(prop, "rna_MeshTextureFace_uv1_get", "rna_MeshTextureFace_uv1_set", NULL);
	RNA_def_property_ui_text(prop, "UV 1", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "uv2", PROP_FLOAT, PROP_XYZ);
	RNA_def_property_array(prop, 2);
	RNA_def_property_float_funcs(prop, "rna_MeshTextureFace_uv2_get", "rna_MeshTextureFace_uv2_set", NULL);
	RNA_def_property_ui_text(prop, "UV 2", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "uv3", PROP_FLOAT, PROP_XYZ);
	RNA_def_property_array(prop, 2);
	RNA_def_property_float_funcs(prop, "rna_MeshTextureFace_uv3_get", "rna_MeshTextureFace_uv3_set", NULL);
	RNA_def_property_ui_text(prop, "UV 3", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "uv4", PROP_FLOAT, PROP_XYZ);
	RNA_def_property_array(prop, 2);
	RNA_def_property_float_funcs(prop, "rna_MeshTextureFace_uv4_get", "rna_MeshTextureFace_uv4_set", NULL);
	RNA_def_property_ui_text(prop, "UV 4", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
	RNA_def_property_multi_array(prop, 2, uv_dim);
	RNA_def_property_flag(prop, PROP_DYNAMIC);
	RNA_def_property_dynamic_array_funcs(prop, "rna_MeshTextureFace_uv_get_length");
	RNA_def_property_float_funcs(prop, "rna_MeshTextureFace_uv_get", "rna_MeshTextureFace_uv_set", NULL);
	RNA_def_property_ui_text(prop, "UV", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "uv_raw", PROP_FLOAT, PROP_NONE);
	RNA_def_property_multi_array(prop, 2, uv_dim);
	RNA_def_property_float_sdna(prop, NULL, "uv");
	RNA_def_property_ui_text(prop, "UV", "Fixed size UV coordinates array");

}

static void rna_def_msticky(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna= RNA_def_struct(brna, "MeshSticky", NULL);
	RNA_def_struct_sdna(srna, "MSticky");
	RNA_def_struct_ui_text(srna, "Mesh Vertex Sticky Texture Coordinate", "Stricky texture coordinate");
	RNA_def_struct_path_func(srna, "rna_MeshSticky_path");

	prop= RNA_def_property(srna, "co", PROP_FLOAT, PROP_XYZ);
	RNA_def_property_ui_text(prop, "Location", "Sticky texture coordinate location");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
}

static void rna_def_mcol(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna= RNA_def_struct(brna, "MeshColorLayer", NULL);
	RNA_def_struct_ui_text(srna, "Mesh Vertex Color Layer", "Layer of vertex colors in a Mesh datablock");
	RNA_def_struct_sdna(srna, "CustomDataLayer");
	RNA_def_struct_path_func(srna, "rna_MeshColorLayer_path");
	RNA_def_struct_ui_icon(srna, ICON_GROUP_VCOL);

	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_struct_name_property(srna, prop);
	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshColorLayer_name_set");
	RNA_def_property_ui_text(prop, "Name", "Name of Vertex color layer");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_funcs(prop, "rna_MeshColorLayer_active_get", "rna_MeshColorLayer_active_set");
	RNA_def_property_ui_text(prop, "Active", "Sets the layer as active for display and editing");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "active_render", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "active_rnd", 0);
	RNA_def_property_boolean_funcs(prop, "rna_MeshColorLayer_active_render_get", "rna_MeshColorLayer_active_render_set");
	RNA_def_property_ui_text(prop, "Active Render", "Sets the layer as active for rendering");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "MeshColor");
	RNA_def_property_ui_text(prop, "Data", "");
	RNA_def_property_collection_funcs(prop, "rna_MeshColorLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshColorLayer_data_length", 0, 0);

	srna= RNA_def_struct(brna, "MeshColor", NULL);
	RNA_def_struct_sdna(srna, "MCol");
	RNA_def_struct_ui_text(srna, "Mesh Vertex Color", "Vertex colors for a face in a Mesh");
	RNA_def_struct_path_func(srna, "rna_MeshColor_path");

	prop= RNA_def_property(srna, "color1", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_array(prop, 3);
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_float_funcs(prop, "rna_MeshColor_color1_get", "rna_MeshColor_color1_set", NULL);
	RNA_def_property_ui_text(prop, "Color 1", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "color2", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_array(prop, 3);
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_float_funcs(prop, "rna_MeshColor_color2_get", "rna_MeshColor_color2_set", NULL);
	RNA_def_property_ui_text(prop, "Color 2", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "color3", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_array(prop, 3);
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_float_funcs(prop, "rna_MeshColor_color3_get", "rna_MeshColor_color3_set", NULL);
	RNA_def_property_ui_text(prop, "Color 3", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "color4", PROP_FLOAT, PROP_COLOR);
	RNA_def_property_array(prop, 3);
	RNA_def_property_range(prop, 0.0f, 1.0f);
	RNA_def_property_float_funcs(prop, "rna_MeshColor_color4_get", "rna_MeshColor_color4_set", NULL);
	RNA_def_property_ui_text(prop, "Color 4", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
}

static void rna_def_mproperties(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	/* Float */
	srna= RNA_def_struct(brna, "MeshFloatPropertyLayer", NULL);
	RNA_def_struct_sdna(srna, "CustomDataLayer");
	RNA_def_struct_ui_text(srna, "Mesh Float Property Layer", "User defined layer of floating pointer number values");
	RNA_def_struct_path_func(srna, "rna_MeshFloatPropertyLayer_path");

	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_struct_name_property(srna, prop);
	RNA_def_property_ui_text(prop, "Name", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "MeshFloatProperty");
	RNA_def_property_ui_text(prop, "Data", "");
	RNA_def_property_collection_funcs(prop, "rna_MeshFloatPropertyLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshFloatPropertyLayer_data_length", 0, 0);

	srna= RNA_def_struct(brna, "MeshFloatProperty", NULL);
	RNA_def_struct_sdna(srna, "MFloatProperty");
	RNA_def_struct_ui_text(srna, "Mesh Float Property", "User defined floating point number value in a float properties layer");
	RNA_def_struct_path_func(srna, "rna_MeshFloatProperty_path");

	prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
	RNA_def_property_float_sdna(prop, NULL, "f");
	RNA_def_property_ui_text(prop, "Value", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	/* Int */
	srna= RNA_def_struct(brna, "MeshIntPropertyLayer", NULL);
	RNA_def_struct_sdna(srna, "CustomDataLayer");
	RNA_def_struct_ui_text(srna, "Mesh Int Property Layer", "User defined layer of integer number values");
	RNA_def_struct_path_func(srna, "rna_MeshIntPropertyLayer_path");

	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_struct_name_property(srna, prop);
	RNA_def_property_ui_text(prop, "Name", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "MeshIntProperty");
	RNA_def_property_ui_text(prop, "Data", "");
	RNA_def_property_collection_funcs(prop, "rna_MeshIntPropertyLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshIntPropertyLayer_data_length", 0, 0);

	srna= RNA_def_struct(brna, "MeshIntProperty", NULL);
	RNA_def_struct_sdna(srna, "MIntProperty");
	RNA_def_struct_ui_text(srna, "Mesh Int Property", "User defined integer number value in an integer properties layer");
	RNA_def_struct_path_func(srna, "rna_MeshIntProperty_path");

	prop= RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "i");
	RNA_def_property_ui_text(prop, "Value", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	/* String */
	srna= RNA_def_struct(brna, "MeshStringPropertyLayer", NULL);
	RNA_def_struct_sdna(srna, "CustomDataLayer");
	RNA_def_struct_ui_text(srna, "Mesh String Property Layer", "User defined layer of string text values");
	RNA_def_struct_path_func(srna, "rna_MeshStringPropertyLayer_path");

	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_struct_name_property(srna, prop);
	RNA_def_property_ui_text(prop, "Name", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "MeshStringProperty");
	RNA_def_property_ui_text(prop, "Data", "");
	RNA_def_property_collection_funcs(prop, "rna_MeshStringPropertyLayer_data_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_MeshStringPropertyLayer_data_length", 0, 0);

	srna= RNA_def_struct(brna, "MeshStringProperty", NULL);
	RNA_def_struct_sdna(srna, "MStringProperty");
	RNA_def_struct_ui_text(srna, "Mesh String Property", "User defined string text value in a string properties layer");
	RNA_def_struct_path_func(srna, "rna_MeshStringProperty_path");

	prop= RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
	RNA_def_property_string_sdna(prop, NULL, "s");
	RNA_def_property_ui_text(prop, "Value", "");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
}

/* mesh.vertices */
static void rna_def_mesh_vertices(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
//	PropertyRNA *prop;

	FunctionRNA *func;
//	PropertyRNA *parm;

	RNA_def_property_srna(cprop, "MeshVertices");
	srna= RNA_def_struct(brna, "MeshVertices", NULL);
	RNA_def_struct_sdna(srna, "Mesh");
	RNA_def_struct_ui_text(srna, "Mesh Vertices", "Collection of mesh vertices");

	func= RNA_def_function(srna, "add", "ED_mesh_vertices_add");
	RNA_def_function_flag(func, FUNC_USE_REPORTS);
	RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
}

/* mesh.edges */
static void rna_def_mesh_edges(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
//	PropertyRNA *prop;

	FunctionRNA *func;
//	PropertyRNA *parm;

	RNA_def_property_srna(cprop, "MeshEdges");
	srna= RNA_def_struct(brna, "MeshEdges", NULL);
	RNA_def_struct_sdna(srna, "Mesh");
	RNA_def_struct_ui_text(srna, "Mesh Edges", "Collection of mesh edges");

	func= RNA_def_function(srna, "add", "ED_mesh_edges_add");
	RNA_def_function_flag(func, FUNC_USE_REPORTS);
	RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
}

/* mesh.faces */
static void rna_def_mesh_faces(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	PropertyRNA *prop;

	FunctionRNA *func;
	/*PropertyRNA *parm;*/

	RNA_def_property_srna(cprop, "MeshFaces");
	srna= RNA_def_struct(brna, "MeshFaces", NULL);
	RNA_def_struct_sdna(srna, "Mesh");
	RNA_def_struct_ui_text(srna, "Mesh Faces", "Collection of mesh faces");

	prop= RNA_def_property(srna, "active", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "act_face");
	RNA_def_property_ui_text(prop, "Active Face", "The active face for this mesh");

	prop= RNA_def_property(srna, "active_tface", PROP_POINTER, PROP_UNSIGNED);
	RNA_def_property_struct_type(prop, "MeshTextureFace");
	RNA_def_property_pointer_funcs(prop, "rna_Mesh_active_mtface_get", NULL, NULL, NULL);
	RNA_def_property_ui_text(prop, "Active Texture Face", "Active Texture Face");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	func= RNA_def_function(srna, "add", "ED_mesh_faces_add");
	RNA_def_function_flag(func, FUNC_USE_REPORTS);
	RNA_def_int(func, "count", 0, 0, INT_MAX, "Count", "Number of vertices to add", 0, INT_MAX);
}

/* mesh.vertex_colors */
static void rna_def_vertex_colors(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	PropertyRNA *prop;

	FunctionRNA *func;
	PropertyRNA *parm;

	RNA_def_property_srna(cprop, "VertexColors");
	srna= RNA_def_struct(brna, "VertexColors", NULL);
	RNA_def_struct_sdna(srna, "Mesh");
	RNA_def_struct_ui_text(srna, "Vertex Colors", "Collection of vertex colors");
	
	func= RNA_def_function(srna, "new", "rna_Mesh_vertex_color_new");
	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
	RNA_def_function_ui_description(func, "Add a vertex color layer to Mesh");
	RNA_def_string(func, "name", "Col", 0, "", "Vertex color name");
	parm= RNA_def_pointer(func, "layer", "MeshColorLayer", "", "The newly created layer");
	RNA_def_function_return(func, parm);
	
/*
	func= RNA_def_function(srna, "remove", "rna_Mesh_vertex_color_remove");
	RNA_def_function_ui_description(func, "Remove a vertex color layer");
	RNA_def_function_flag(func, FUNC_USE_REPORTS);
	parm= RNA_def_pointer(func, "layer", "Layer", "", "The layer to remove");
	RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
*/
	prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_UNSIGNED);
	RNA_def_property_struct_type(prop, "MeshColorLayer");
	RNA_def_property_pointer_funcs(prop, "rna_Mesh_active_vertex_color_get", "rna_Mesh_active_vertex_color_set", NULL, NULL);
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Active Vertex Color Layer", "Active vertex color layer");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
	
	prop= RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_funcs(prop, "rna_Mesh_active_vertex_color_index_get", "rna_Mesh_active_vertex_color_index_set", "rna_Mesh_active_vertex_color_index_range");
	RNA_def_property_ui_text(prop, "Active Vertex Color Index", "Active vertex color index");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
}

/* mesh.uv_layers */
static void rna_def_uv_textures(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	PropertyRNA *prop;

	FunctionRNA *func;
	PropertyRNA *parm;

	RNA_def_property_srna(cprop, "UVTextures");
	srna= RNA_def_struct(brna, "UVTextures", NULL);
	RNA_def_struct_sdna(srna, "Mesh");
	RNA_def_struct_ui_text(srna, "UV Textures", "Collection of uv textures");
	
	func= RNA_def_function(srna, "new", "rna_Mesh_uv_texture_new");
	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
	RNA_def_function_ui_description(func, "Add a UV texture layer to Mesh");
	RNA_def_string(func, "name", "UVTex", 0, "", "UV Texture name");
	parm= RNA_def_pointer(func, "layer", "MeshTextureFaceLayer", "", "The newly created layer");
	RNA_def_function_return(func, parm);

/*
	func= RNA_def_function(srna, "remove", "rna_Mesh_uv_layers_remove");
	RNA_def_function_ui_description(func, "Remove a vertex color layer");
	RNA_def_function_flag(func, FUNC_USE_REPORTS);
	parm= RNA_def_pointer(func, "layer", "Layer", "", "The layer to remove");
	RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
*/
	prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_UNSIGNED);
	RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
	RNA_def_property_pointer_funcs(prop, "rna_Mesh_active_uv_texture_get", "rna_Mesh_active_uv_texture_set", NULL, NULL);
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Active UV Texture", "Active UV texture");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_funcs(prop, "rna_Mesh_active_uv_texture_index_get", "rna_Mesh_active_uv_texture_index_set", "rna_Mesh_active_uv_texture_index_range");
	RNA_def_property_ui_text(prop, "Active UV Texture Index", "Active UV texture index");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
}

static void rna_def_mesh(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;

	srna= RNA_def_struct(brna, "Mesh", "ID");
	RNA_def_struct_ui_text(srna, "Mesh", "Mesh datablock defining geometric surfaces");
	RNA_def_struct_ui_icon(srna, ICON_MESH_DATA);

	prop= RNA_def_property(srna, "vertices", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "mvert", "totvert");
	RNA_def_property_struct_type(prop, "MeshVertex");
	RNA_def_property_ui_text(prop, "Vertices", "Vertices of the mesh");
	rna_def_mesh_vertices(brna, prop);

	prop= RNA_def_property(srna, "edges", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "medge", "totedge");
	RNA_def_property_struct_type(prop, "MeshEdge");
	RNA_def_property_ui_text(prop, "Edges", "Edges of the mesh");
	rna_def_mesh_edges(brna, prop);

	prop= RNA_def_property(srna, "faces", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "mface", "totface");
	RNA_def_property_struct_type(prop, "MeshFace");
	RNA_def_property_ui_text(prop, "Faces", "Faces of the mesh");
	rna_def_mesh_faces(brna, prop);

	prop= RNA_def_property(srna, "sticky", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "msticky", "totvert");
	RNA_def_property_struct_type(prop, "MeshSticky");
	RNA_def_property_ui_text(prop, "Sticky", "Sticky texture coordinates");

	/* TODO, should this be allowed to be its self? */
	prop= RNA_def_property(srna, "texture_mesh", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "texcomesh");
	RNA_def_property_flag(prop, PROP_EDITABLE|PROP_ID_SELF_CHECK);
	RNA_def_property_ui_text(prop, "Texture Mesh", "Use another mesh for texture indices (vertex indices must be aligned)");

	/* UV textures */
	prop= RNA_def_property(srna, "uv_textures", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer");
	RNA_def_property_collection_funcs(prop, "rna_Mesh_uv_textures_begin", 0, 0, 0, "rna_Mesh_uv_textures_length", 0, 0);
	RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
	RNA_def_property_ui_text(prop, "UV Textures", "");
	rna_def_uv_textures(brna, prop);

	prop= RNA_def_property(srna, "uv_texture_clone", PROP_POINTER, PROP_UNSIGNED);
	RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
	RNA_def_property_pointer_funcs(prop, "rna_Mesh_uv_texture_clone_get", "rna_Mesh_uv_texture_clone_set", NULL, NULL);
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Clone UV Texture", "UV texture to be used as cloning source");

	prop= RNA_def_property(srna, "uv_texture_clone_index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_funcs(prop, "rna_Mesh_uv_texture_clone_index_get", "rna_Mesh_uv_texture_clone_index_set", "rna_Mesh_active_uv_texture_index_range");
	RNA_def_property_ui_text(prop, "Clone UV Texture Index", "Clone UV texture index");

	prop= RNA_def_property(srna, "uv_texture_stencil", PROP_POINTER, PROP_UNSIGNED);
	RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
	RNA_def_property_pointer_funcs(prop, "rna_Mesh_uv_texture_stencil_get", "rna_Mesh_uv_texture_stencil_set", NULL, NULL);
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Mask UV Texture", "UV texture to mask the painted area");

	prop= RNA_def_property(srna, "uv_texture_stencil_index", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_funcs(prop, "rna_Mesh_uv_texture_stencil_index_get", "rna_Mesh_uv_texture_stencil_index_set", "rna_Mesh_active_uv_texture_index_range");
	RNA_def_property_ui_text(prop, "Mask UV Texture Index", "Mask UV texture index");

	/* Vertex colors */

	prop= RNA_def_property(srna, "vertex_colors", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer");
	RNA_def_property_collection_funcs(prop, "rna_Mesh_vertex_colors_begin", 0, 0, 0, "rna_Mesh_vertex_colors_length", 0, 0);
	RNA_def_property_struct_type(prop, "MeshColorLayer");
	RNA_def_property_ui_text(prop, "Vertex Colors", "");
	rna_def_vertex_colors(brna, prop);

	prop= RNA_def_property(srna, "layers_float", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer");
	RNA_def_property_collection_funcs(prop, "rna_Mesh_float_layers_begin", 0, 0, 0, "rna_Mesh_float_layers_length", 0, 0);
	RNA_def_property_struct_type(prop, "MeshFloatPropertyLayer");
	RNA_def_property_ui_text(prop, "Float Property Layers", "");

	prop= RNA_def_property(srna, "layers_int", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer");
	RNA_def_property_collection_funcs(prop, "rna_Mesh_int_layers_begin", 0, 0, 0, "rna_Mesh_int_layers_length", 0, 0);
	RNA_def_property_struct_type(prop, "MeshIntPropertyLayer");
	RNA_def_property_ui_text(prop, "Int Property Layers", "");

	prop= RNA_def_property(srna, "layers_string", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer");
	RNA_def_property_collection_funcs(prop, "rna_Mesh_string_layers_begin", 0, 0, 0, "rna_Mesh_string_layers_length", 0, 0);
	RNA_def_property_struct_type(prop, "MeshStringPropertyLayer");
	RNA_def_property_ui_text(prop, "String Property Layers", "");

	prop= RNA_def_property(srna, "use_auto_smooth", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_AUTOSMOOTH);
	RNA_def_property_ui_text(prop, "Auto Smooth", "Treats all set-smoothed faces with angles less than the specified angle as 'smooth' during render");

#if 1 /* expose as radians */
	prop= RNA_def_property(srna, "auto_smooth_angle", PROP_FLOAT, PROP_ANGLE);
	RNA_def_property_float_funcs(prop, "rna_Mesh_auto_smooth_angle_get", "rna_Mesh_auto_smooth_angle_set", NULL);
	RNA_def_property_ui_range(prop, DEG2RAD(1.0), DEG2RAD(80), 1.0, 1);
#else
	prop= RNA_def_property(srna, "auto_smooth_angle", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "smoothresh");
	RNA_def_property_range(prop, 1, 80);
#endif
	RNA_def_property_ui_text(prop, "Auto Smooth Angle", "Defines maximum angle between face normals that 'Auto Smooth' will operate on");

	prop= RNA_def_property(srna, "show_double_sided", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_TWOSIDED);
	RNA_def_property_ui_text(prop, "Double Sided", "Render/display the mesh with double or single sided lighting");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_data");

	prop= RNA_def_property(srna, "texco_mesh", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "texcomesh");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Texture Space Mesh", "Derive texture coordinates from another mesh");

	prop= RNA_def_property(srna, "shape_keys", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "key");
	RNA_def_property_ui_text(prop, "Shape Keys", "");
	
	/* texture space */
	prop= RNA_def_property(srna, "use_auto_texspace", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "texflag", AUTOSPACE);
	RNA_def_property_ui_text(prop, "Auto Texture Space", "Adjusts active object's texture space automatically when transforming object");
	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Mesh_texspace_set");
	
	prop= RNA_def_property(srna, "texspace_location", PROP_FLOAT, PROP_TRANSLATION);
	RNA_def_property_array(prop, 3);
	RNA_def_property_ui_text(prop, "Texture Space Location", "Texture space location");
	RNA_def_property_editable_func(prop, "rna_Mesh_texspace_editable");
	RNA_def_property_float_funcs(prop, "rna_Mesh_texspace_loc_get", "rna_Mesh_texspace_loc_set", NULL);	
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	prop= RNA_def_property(srna, "texspace_size", PROP_FLOAT, PROP_XYZ);
	RNA_def_property_array(prop, 3);
	RNA_def_property_ui_text(prop, "Texture Space Size", "Texture space size");
	RNA_def_property_editable_func(prop, "rna_Mesh_texspace_editable");
	RNA_def_property_float_funcs(prop, "rna_Mesh_texspace_size_get", "rna_Mesh_texspace_size_set", NULL);
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	/* not supported yet
	 prop= RNA_def_property(srna, "texspace_rot", PROP_FLOAT, PROP_EULER);
	 RNA_def_property_float(prop, NULL, "rot");
	 RNA_def_property_ui_text(prop, "Texture Space Rotation", "Texture space rotation");
	 RNA_def_property_editable_func(prop, texspace_editable);
	 RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");*/
	
	/* materials */
	prop= RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
	RNA_def_property_struct_type(prop, "Material");
	RNA_def_property_ui_text(prop, "Materials", "");
	RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */

	/* Mesh Draw Options for Edit Mode*/
	
	prop= RNA_def_property(srna, "show_edges", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWEDGES);
	RNA_def_property_ui_text(prop, "Draw Edges", "Displays selected edges using highlights in the 3D view and UV editor");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	prop= RNA_def_property(srna, "show_all_edges", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_ALLEDGES);
	RNA_def_property_ui_text(prop, "All Edges", "Displays all edges for wireframe in all view modes in the 3D view");
	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);

	prop= RNA_def_property(srna, "show_faces", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWFACES);
	RNA_def_property_ui_text(prop, "Draw Faces", "Displays all faces as shades in the 3D view and UV editor");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	prop= RNA_def_property(srna, "show_normal_face", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWNORMALS);
	RNA_def_property_ui_text(prop, "Draw Normals", "Displays face normals as lines");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	prop= RNA_def_property(srna, "show_normal_vertex", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAW_VNORMALS);
	RNA_def_property_ui_text(prop, "Draw Vertex Normals", "Displays vertex normals as lines");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	prop= RNA_def_property(srna, "show_edge_crease", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWCREASES);
	RNA_def_property_ui_text(prop, "Draw Creases", "Displays creases created for subsurf weighting");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	prop= RNA_def_property(srna, "show_edge_bevel_weight", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWBWEIGHTS);
	RNA_def_property_ui_text(prop, "Draw Bevel Weights", "Displays weights created for the Bevel modifier");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	prop= RNA_def_property(srna, "show_edge_seams", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWSEAMS);
	RNA_def_property_ui_text(prop, "Draw Seams", "Displays UV unwrapping seams");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	prop= RNA_def_property(srna, "show_edge_sharp", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWSHARP);
	RNA_def_property_ui_text(prop, "Draw Sharp", "Displays sharp edges, used with the EdgeSplit modifier");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");

	prop= RNA_def_property(srna, "show_extra_edge_length", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWEXTRA_EDGELEN);
	RNA_def_property_ui_text(prop, "Edge Length", "Displays selected edge lengths, Using global values when set in the transform panel");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	prop= RNA_def_property(srna, "show_extra_face_angle", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWEXTRA_FACEANG);
	RNA_def_property_ui_text(prop, "Faces Angles", "Displays the angles in the selected edges in degrees, Using global values when set in the transform panel");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
	
	prop= RNA_def_property(srna, "show_extra_face_area", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWEXTRA_FACEAREA);
	RNA_def_property_ui_text(prop, "Face Area", "Displays the area of selected faces, Using global values when set in the transform panel");
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");

	/* editflag */
	prop= RNA_def_property(srna, "use_mirror_x", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_MIRROR_X);
	RNA_def_property_ui_text(prop, "X Mirror", "X Axis mirror editing");

	/*
	prop= RNA_def_property(srna, "use_mirror_y", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_MIRROR_Y);
	RNA_def_property_ui_text(prop, "Y Mirror", "Y Axis mirror editing");

	prop= RNA_def_property(srna, "use_mirror_x", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_MIRROR_Z);
	RNA_def_property_ui_text(prop, "Z Mirror", "Z Axis mirror editing");
	 */

	prop= RNA_def_property(srna, "use_mirror_topology", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_MIRROR_TOPO);
	RNA_def_property_ui_text(prop, "Topology Mirror", "Use topology based mirroring. For when both sides of mesh have matching, unique topology");

	prop= RNA_def_property(srna, "use_paint_mask", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_PAINT_MASK);
	RNA_def_property_ui_text(prop, "Paint Mask", "Face selection masking for painting");
	RNA_def_property_ui_icon(prop, ICON_FACESEL_HLT, 0);
	RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");


	/* readonly editmesh info - use for extrude menu */
	prop= RNA_def_property(srna, "total_vert_sel", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_funcs(prop, "rna_Mesh_tot_vert_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Selected Vert Total", "Selected vertex count in editmode");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);

	prop= RNA_def_property(srna, "total_edge_sel", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_funcs(prop, "rna_Mesh_tot_edge_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Selected Edge Total", "Selected edge count in editmode");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);

	prop= RNA_def_property(srna, "total_face_sel", PROP_INT, PROP_UNSIGNED);
	RNA_def_property_int_funcs(prop, "rna_Mesh_tot_face_get", NULL, NULL);
	RNA_def_property_ui_text(prop, "Selected Face Total", "Selected face count in editmode");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);

	/* pointers */
	rna_def_animdata_common(srna);

	RNA_api_mesh(srna);
}

void RNA_def_mesh(BlenderRNA *brna)
{
	rna_def_mesh(brna);
	rna_def_mvert(brna);
	rna_def_mvert_group(brna);
	rna_def_medge(brna);
	rna_def_mface(brna);
	rna_def_mtface(brna);
	rna_def_msticky(brna);
	rna_def_mcol(brna);
	rna_def_mproperties(brna);
}

#endif