diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-06-30 16:52:16 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-06-30 16:52:16 +0400 |
commit | 30dcada24d1820e5aed4e1a671543e040918e910 (patch) | |
tree | fac786d2adc97ac939e35d4dd9a94b1f526021d8 /source/blender/makesrna/intern | |
parent | 0c14be3b5820d7130a281e95da664753a0ff2793 (diff) |
python access to RNA arrays.
coords = array.array('f', [0.0]) * len(me.verts) * 3
m.verts.foreach_get('co', coords)
the reverse works with set also.
currently works for python buffers or sequences (slower)
Quick speed test with 1,179,654 verts.
*foreach_get*
list 0.377
array 0.032
py 10.29
*foreach_set*
list 0.184
array 0.028
py 9.79
where python was done like this...
----
i= 0
for v in m.verts:
co = v.co
l[i] = co[0]; l[i+1] = co[0]; l[i+2] = co[0]
i+=3
----
some of the error checking here needs to be cleaned up to account for different invalid bad inputs.
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index d3e4780c7fd..36adc9a7c10 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1580,6 +1580,17 @@ int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, Proper } \ } +int RNA_raw_type_sizeof(RawPropertyType type) +{ + switch(type) { + case PROP_RAW_CHAR: return sizeof(char); + case PROP_RAW_SHORT: return sizeof(short); + case PROP_RAW_INT: return sizeof(int); + case PROP_RAW_FLOAT: return sizeof(float); + case PROP_RAW_DOUBLE: return sizeof(double); + } +} + static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *inarray, RawPropertyType intype, int inlen, int set) { StructRNA *ptype; @@ -1630,14 +1641,7 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro int a, size; itemlen= (itemlen == 0)? 1: itemlen; - - switch(out.type) { - case PROP_RAW_CHAR: size= sizeof(char)*itemlen; break; - case PROP_RAW_SHORT: size= sizeof(short)*itemlen; break; - case PROP_RAW_INT: size= sizeof(int)*itemlen; break; - case PROP_RAW_FLOAT: size= sizeof(float)*itemlen; break; - case PROP_RAW_DOUBLE: size= sizeof(double)*itemlen; break; - } + size= RNA_raw_type_sizeof(out.type) * itemlen; for(a=0; a<out.len; a++) { if(set) memcpy(outp, inp, size); @@ -1819,6 +1823,11 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro } } +RawPropertyType RNA_property_raw_type(PropertyRNA *prop) +{ + return prop->rawtype; +} + int RNA_property_collection_raw_get(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *array, RawPropertyType type, int len) { return rna_raw_access(reports, ptr, prop, propname, array, type, len, 0); |