diff options
author | Arystanbek Dyussenov <arystan.d@gmail.com> | 2009-07-01 17:37:52 +0400 |
---|---|---|
committer | Arystanbek Dyussenov <arystan.d@gmail.com> | 2009-07-01 17:37:52 +0400 |
commit | 87a7dd377358d129cddcd06efafd7fd191e6f3de (patch) | |
tree | 9da9792368e6bfab421f44d3a04673da965d3212 /source/blender/makesrna | |
parent | 1557736756b41dfa8fff4d7c887a7d6da2b1f468 (diff) | |
parent | 82055c82170885249bf922b05a5c7a3186c07c71 (diff) |
Merge from 2.5 r21160 through r21285
Diffstat (limited to 'source/blender/makesrna')
25 files changed, 1422 insertions, 107 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 9f7559312ed..d69439e25bc 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -174,6 +174,7 @@ extern StructRNA RNA_ExplodeModifier; extern StructRNA RNA_ExpressionController; extern StructRNA RNA_Event; extern StructRNA RNA_FCurve; +extern StructRNA RNA_FileSelectParams; extern StructRNA RNA_FModifier; extern StructRNA RNA_FModifierCycles; extern StructRNA RNA_FModifierEnvelope; @@ -369,6 +370,7 @@ extern StructRNA RNA_SpaceImageEditor; extern StructRNA RNA_SpaceOutliner; extern StructRNA RNA_SpaceSequenceEditor; extern StructRNA RNA_SpaceTextEditor; +extern StructRNA RNA_SpaceFileBrowser; extern StructRNA RNA_SpaceUVEditor; extern StructRNA RNA_SpeedControlSequence; extern StructRNA RNA_SpotLamp; @@ -600,6 +602,14 @@ int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop); int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr); int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr); +/* efficient functions to set properties for arrays */ +int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array); +int RNA_property_collection_raw_get(struct ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *array, RawPropertyType type, int len); +int RNA_property_collection_raw_set(struct ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *array, RawPropertyType type, int len); +int RNA_raw_type_sizeof(RawPropertyType type); +RawPropertyType RNA_property_raw_type(PropertyRNA *prop); + + /* to create ID property groups */ void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop); void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop); diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index 75f52ededd0..923191cba78 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -110,7 +110,9 @@ typedef enum PropertyFlag { PROP_BUILTIN = 128, PROP_EXPORT = 256, PROP_RUNTIME = 512, - PROP_IDPROPERTY = 1024 + PROP_IDPROPERTY = 1024, + PROP_RAW_ACCESS = 8192, + PROP_RAW_ARRAY = 16384, } PropertyFlag; typedef struct CollectionPropertyIterator { @@ -132,6 +134,21 @@ typedef struct CollectionPointerLink { PointerRNA ptr; } CollectionPointerLink; +typedef enum RawPropertyType { + PROP_RAW_CHAR, + PROP_RAW_SHORT, + PROP_RAW_INT, + PROP_RAW_FLOAT, + PROP_RAW_DOUBLE +} RawPropertyType; + +typedef struct RawArray { + void *array; + RawPropertyType type; + int len; + int stride; +} RawArray; + /* Iterator Utility */ typedef struct EnumPropertyItem { diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index f7bf176a325..e779f901b3c 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -248,8 +248,7 @@ static const char *rna_parameter_type_name(PropertyRNA *parm) return rna_find_dna_type((const char *)pparm->type); } case PROP_COLLECTION: { - CollectionPropertyRNA *cparm= (CollectionPropertyRNA*)parm; - return rna_find_dna_type((const char *)cparm->type); + return "ListBase"; } default: return "<error, no type specified>"; @@ -763,6 +762,42 @@ static char *rna_def_property_end_func(FILE *f, StructRNA *srna, PropertyRNA *pr return func; } +static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop) +{ + if(dp->dnapointerlevel != 0) + return; + if(!dp->dnatype || !dp->dnaname || !dp->dnastructname) + return; + + if(strcmp(dp->dnatype, "char") == 0) { + prop->rawtype= PROP_RAW_CHAR; + prop->flag |= PROP_RAW_ACCESS; + } + else if(strcmp(dp->dnatype, "short") == 0) { + prop->rawtype= PROP_RAW_SHORT; + prop->flag |= PROP_RAW_ACCESS; + } + else if(strcmp(dp->dnatype, "int") == 0) { + prop->rawtype= PROP_RAW_INT; + prop->flag |= PROP_RAW_ACCESS; + } + else if(strcmp(dp->dnatype, "float") == 0) { + prop->rawtype= PROP_RAW_FLOAT; + prop->flag |= PROP_RAW_ACCESS; + } + else if(strcmp(dp->dnatype, "double") == 0) { + prop->rawtype= PROP_RAW_DOUBLE; + prop->flag |= PROP_RAW_ACCESS; + } +} + +static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop) +{ + PropertyDefRNA *dp= rna_find_struct_property_def(srna, prop); + + fprintf(f, "\toffsetof(%s, %s), %d", dp->dnastructname, dp->dnaname, prop->rawtype); +} + static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) { PropertyRNA *prop; @@ -774,6 +809,9 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop; if(!prop->arraylength) { + if(!bprop->get && !bprop->set && !dp->booleanbit) + rna_set_raw_property(dp, prop); + bprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)bprop->get); bprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)bprop->set); } @@ -787,10 +825,16 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) IntPropertyRNA *iprop= (IntPropertyRNA*)prop; if(!prop->arraylength) { + if(!iprop->get && !iprop->set) + rna_set_raw_property(dp, prop); + iprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)iprop->get); iprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)iprop->set); } else { + if(!iprop->getarray && !iprop->setarray) + rna_set_raw_property(dp, prop); + iprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)iprop->getarray); iprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)iprop->setarray); } @@ -800,10 +844,16 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; if(!prop->arraylength) { + if(!fprop->get && !fprop->set) + rna_set_raw_property(dp, prop); + fprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)fprop->get); fprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)fprop->set); } else { + if(!fprop->getarray && !fprop->setarray) + rna_set_raw_property(dp, prop); + fprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)fprop->getarray); fprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)fprop->setarray); } @@ -842,6 +892,13 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp) else if(dp->dnalengthname || dp->dnalengthfixed) cprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp, (char*)cprop->length); + /* test if we can allow raw array access, if it is using our standard + * array get/next function, we can be sure it is an actual array */ + if(cprop->next && cprop->get) + if(strcmp((char*)cprop->next, "rna_iterator_array_next") == 0 && + strcmp((char*)cprop->get, "rna_iterator_array_get") == 0) + prop->flag |= PROP_RAW_ARRAY; + cprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)cprop->get); cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp, (char*)cprop->begin); cprop->next= (void*)rna_def_property_next_func(f, srna, prop, dp, (char*)cprop->next); @@ -1116,9 +1173,11 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA funcname= rna_alloc_function_name(srna->identifier, func->identifier, "call"); + /* function definition */ fprintf(f, "void %s(bContext *C, ReportList *reports, PointerRNA *_ptr, ParameterList *_parms)", funcname); fprintf(f, "\n{\n"); + /* variable definitions */ if((func->flag & FUNC_NO_SELF)==0) { if(dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname); else fprintf(f, "\tstruct %s *_self;\n", srna->identifier); @@ -1135,6 +1194,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA fprintf(f, ";\n"); fprintf(f, "\t\n"); + /* assign self */ if((func->flag & FUNC_NO_SELF)==0) { if(dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname); else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier); @@ -1405,6 +1465,7 @@ static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA dsrna= rna_find_struct_def(srna); func= dfunc->func; + /* return type */ for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) { if(dparm->prop==func->ret) { if(dparm->prop->arraylength) @@ -1418,13 +1479,16 @@ static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA } } + /* void if nothing to return */ if(!dparm) fprintf(f, "void "); + /* function name */ fprintf(f, "%s(", dfunc->call); first= 1; + /* self, context and reports parameters */ if((func->flag & FUNC_NO_SELF)==0) { if(dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname); else fprintf(f, "struct %s *_self", srna->identifier); @@ -1443,6 +1507,7 @@ static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA fprintf(f, "ReportList *reports"); } + /* defined parameters */ for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) { if(dparm->prop==func->ret) continue; @@ -1531,7 +1596,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr DefRNA.error= 1; } break; - } + } case PROP_BOOLEAN: { BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop; unsigned int i; @@ -1551,7 +1616,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr fprintf(f, "};\n\n"); } break; - } + } case PROP_INT: { IntPropertyRNA *iprop= (IntPropertyRNA*)prop; unsigned int i; @@ -1571,7 +1636,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr fprintf(f, "};\n\n"); } break; - } + } case PROP_FLOAT: { FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; unsigned int i; @@ -1591,7 +1656,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr fprintf(f, "};\n\n"); } break; - } + } default: break; } @@ -1606,10 +1671,14 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr rna_print_c_string(f, prop->identifier); fprintf(f, ", %d, ", prop->flag); rna_print_c_string(f, prop->name); fprintf(f, ",\n\t"); - rna_print_c_string(f, prop->description); fprintf(f, ",\n"); - fprintf(f, "%d, ", prop->icon); + rna_print_c_string(f, prop->description); fprintf(f, ",\n\t"); + fprintf(f, "%d,\n", prop->icon); fprintf(f, "\t%s, %s, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), prop->arraylength); - fprintf(f, "\t%s, %d, %s},\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable)); + fprintf(f, "\t%s, %d, %s,\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable)); + + if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop); + else fprintf(f, "\t0, 0"); + fprintf(f, "},\n"); switch(prop->type) { case PROP_BOOLEAN: { @@ -1618,7 +1687,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr if(prop->arraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier); else fprintf(f, "NULL\n"); break; - } + } case PROP_INT: { IntPropertyRNA *iprop= (IntPropertyRNA*)prop; fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), rna_function_string(iprop->range)); @@ -1631,7 +1700,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr if(prop->arraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier); else fprintf(f, "NULL\n"); break; - } + } case PROP_FLOAT: { FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop; fprintf(f, "\t%s, %s, %s, %s, %s, ", rna_function_string(fprop->get), rna_function_string(fprop->set), rna_function_string(fprop->getarray), rna_function_string(fprop->setarray), rna_function_string(fprop->range)); @@ -1645,13 +1714,13 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr if(prop->arraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier); else fprintf(f, "NULL\n"); break; - } + } case PROP_STRING: { StringPropertyRNA *sprop= (StringPropertyRNA*)prop; fprintf(f, "\t%s, %s, %s, %d, ", rna_function_string(sprop->get), rna_function_string(sprop->length), rna_function_string(sprop->set), sprop->maxlength); rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n"); break; - } + } case PROP_ENUM: { EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop; fprintf(f, "\t%s, %s, %s, ", rna_function_string(eprop->get), rna_function_string(eprop->set), rna_function_string(eprop->itemf)); @@ -1661,14 +1730,14 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr fprintf(f, "NULL, "); fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue); break; - } + } case PROP_POINTER: { PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop; fprintf(f, "\t%s, %s, %s, ", rna_function_string(pprop->get), rna_function_string(pprop->set), rna_function_string(pprop->typef)); if(pprop->type) fprintf(f, "&RNA_%s\n", (char*)pprop->type); else fprintf(f, "NULL\n"); break; - } + } case PROP_COLLECTION: { CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop; fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, ", rna_function_string(cprop->begin), rna_function_string(cprop->next), rna_function_string(cprop->end), rna_function_string(cprop->get), rna_function_string(cprop->length), rna_function_string(cprop->lookupint), rna_function_string(cprop->lookupstring)); @@ -1883,6 +1952,7 @@ static void rna_generate(BlenderRNA *brna, FILE *f, char *filename, char *api_fi fprintf(f, "#include <float.h>\n"); fprintf(f, "#include <limits.h>\n"); fprintf(f, "#include <string.h>\n\n"); + fprintf(f, "#include <stddef.h>\n\n"); fprintf(f, "#include \"DNA_ID.h\"\n"); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 66127ebc6df..9ebb778707c 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1522,6 +1522,323 @@ int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, co } } +int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, RawArray *array) +{ + CollectionPropertyIterator iter; + ArrayIterator *internal; + char *arrayp; + + if(!(prop->flag & PROP_RAW_ARRAY) || !(itemprop->flag & PROP_RAW_ACCESS)) + return 0; + + RNA_property_collection_begin(ptr, prop, &iter); + + if(iter.valid) { + /* get data from array iterator and item property */ + internal= iter.internal; + arrayp= (iter.valid)? iter.ptr.data: NULL; + + if(internal->skip || !RNA_property_editable(&iter.ptr, itemprop)) { + /* we might skip some items, so it's not a proper array */ + RNA_property_collection_end(&iter); + return 0; + } + + array->array= arrayp + itemprop->rawoffset; + array->stride= internal->itemsize; + array->len= ((char*)internal->endptr - arrayp)/internal->itemsize; + array->type= itemprop->rawtype; + } + else + memset(array, 0, sizeof(RawArray)); + + RNA_property_collection_end(&iter); + + return 1; +} + +#define RAW_GET(dtype, var, raw, a) \ +{ \ + switch(raw.type) { \ + case PROP_RAW_CHAR: var = (dtype)((char*)raw.array)[a]; break; \ + case PROP_RAW_SHORT: var = (dtype)((short*)raw.array)[a]; break; \ + case PROP_RAW_INT: var = (dtype)((int*)raw.array)[a]; break; \ + case PROP_RAW_FLOAT: var = (dtype)((float*)raw.array)[a]; break; \ + case PROP_RAW_DOUBLE: var = (dtype)((double*)raw.array)[a]; break; \ + default: var = (dtype)0; \ + } \ +} + +#define RAW_SET(dtype, raw, a, var) \ +{ \ + switch(raw.type) { \ + case PROP_RAW_CHAR: ((char*)raw.array)[a] = (char)var; break; \ + case PROP_RAW_SHORT: ((short*)raw.array)[a] = (short)var; break; \ + case PROP_RAW_INT: ((int*)raw.array)[a] = (int)var; break; \ + case PROP_RAW_FLOAT: ((float*)raw.array)[a] = (float)var; break; \ + case PROP_RAW_DOUBLE: ((double*)raw.array)[a] = (double)var; break; \ + } \ +} + +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); + default: return 0; + } +} + +static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, char *propname, void *inarray, RawPropertyType intype, int inlen, int set) +{ + StructRNA *ptype; + PointerRNA itemptr; + PropertyRNA *itemprop, *iprop; + PropertyType itemtype; + RawArray in; + int itemlen= 0; + + /* initialize in array, stride assumed 0 in following code */ + in.array= inarray; + in.type= intype; + in.len= inlen; + in.stride= 0; + + ptype= RNA_property_pointer_type(ptr, prop); + + /* try to get item property pointer */ + RNA_pointer_create(NULL, ptype, NULL, &itemptr); + itemprop= RNA_struct_find_property(&itemptr, propname); + + if(itemprop) { + /* we have item property pointer */ + RawArray out; + + /* check type */ + itemtype= RNA_property_type(itemprop); + + if(!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) { + BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported."); + return 0; + } + + /* check item array */ + itemlen= RNA_property_array_length(itemprop); + + /* try to access as raw array */ + if(RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) { + if(in.len != itemlen*out.len) { + BKE_reportf(reports, RPT_ERROR, "Array length mismatch (expected %d, got %d).", out.len*itemlen, in.len); + return 0; + } + + /* matching raw types */ + if(out.type == in.type) { + void *inp= in.array; + void *outp= out.array; + int a, size; + + itemlen= (itemlen == 0)? 1: itemlen; + size= RNA_raw_type_sizeof(out.type) * itemlen; + + for(a=0; a<out.len; a++) { + if(set) memcpy(outp, inp, size); + else memcpy(inp, outp, size); + + inp= (char*)inp + size; + outp= (char*)outp + out.stride; + } + + return 1; + } + + /* could also be faster with non-matching types, + * for now we just do slower loop .. */ + } + } + + { + void *tmparray= NULL; + int tmplen= 0; + int err= 0, j, a= 0; + + /* no item property pointer, can still be id property, or + * property of a type derived from the collection pointer type */ + RNA_PROP_BEGIN(ptr, itemptr, prop) { + if(itemptr.data) { + if(itemprop) { + /* we got the property already */ + iprop= itemprop; + } + else { + /* not yet, look it up and verify if it is valid */ + iprop= RNA_struct_find_property(&itemptr, propname); + + if(iprop) { + itemlen= RNA_property_array_length(iprop); + itemtype= RNA_property_type(iprop); + } + else { + BKE_reportf(reports, RPT_ERROR, "Property named %s not found.", propname); + err= 1; + break; + } + + if(!ELEM3(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) { + BKE_report(reports, RPT_ERROR, "Only boolean, int and float properties supported."); + err= 1; + break; + } + } + + /* editable check */ + if(RNA_property_editable(&itemptr, iprop)) { + if(a+itemlen > in.len) { + BKE_reportf(reports, RPT_ERROR, "Array length mismatch (got %d, expected more).", in.len); + err= 1; + break; + } + + if(itemlen == 0) { + /* handle conversions */ + if(set) { + switch(itemtype) { + case PROP_BOOLEAN: { + int b; + RAW_GET(int, b, in, a); + RNA_property_boolean_set(&itemptr, iprop, b); + break; + } + case PROP_INT: { + int i; + RAW_GET(int, i, in, a); + RNA_property_int_set(&itemptr, iprop, i); + break; + } + case PROP_FLOAT: { + float f; + RAW_GET(float, f, in, a); + RNA_property_float_set(&itemptr, iprop, f); + break; + } + default: + break; + } + } + else { + switch(itemtype) { + case PROP_BOOLEAN: { + int b= RNA_property_boolean_get(&itemptr, iprop); + RAW_SET(int, in, a, b); + break; + } + case PROP_INT: { + int i= RNA_property_int_get(&itemptr, iprop); + RAW_SET(int, in, a, i); + break; + } + case PROP_FLOAT: { + float f= RNA_property_float_get(&itemptr, iprop); + RAW_SET(float, in, a, f); + break; + } + default: + break; + } + } + a++; + } + else { + /* allocate temporary array if needed */ + if(tmparray && tmplen != itemlen) { + MEM_freeN(tmparray); + tmparray= NULL; + } + if(!tmparray) { + tmparray= MEM_callocN(sizeof(float)*itemlen, "RNA tmparray\n"); + tmplen= itemlen; + } + + /* handle conversions */ + if(set) { + switch(itemtype) { + case PROP_BOOLEAN: { + for(j=0; j<itemlen; j++, a++) + RAW_GET(int, ((int*)tmparray)[j], in, a); + RNA_property_boolean_set_array(&itemptr, iprop, tmparray); + break; + } + case PROP_INT: { + for(j=0; j<itemlen; j++, a++) + RAW_GET(int, ((int*)tmparray)[j], in, a); + RNA_property_int_set_array(&itemptr, iprop, tmparray); + break; + } + case PROP_FLOAT: { + for(j=0; j<itemlen; j++, a++) + RAW_GET(float, ((float*)tmparray)[j], in, a); + RNA_property_float_set_array(&itemptr, iprop, tmparray); + break; + } + default: + break; + } + } + else { + switch(itemtype) { + case PROP_BOOLEAN: { + RNA_property_boolean_get_array(&itemptr, iprop, tmparray); + for(j=0; j<itemlen; j++, a++) + RAW_SET(int, in, a, ((int*)tmparray)[j]); + break; + } + case PROP_INT: { + RNA_property_int_get_array(&itemptr, iprop, tmparray); + for(j=0; j<itemlen; j++, a++) + RAW_SET(int, in, a, ((int*)tmparray)[j]); + break; + } + case PROP_FLOAT: { + RNA_property_float_get_array(&itemptr, iprop, tmparray); + for(j=0; j<itemlen; j++, a++) + RAW_SET(float, in, a, ((float*)tmparray)[j]); + break; + } + default: + break; + } + } + } + } + } + } + RNA_PROP_END; + + if(tmparray) + MEM_freeN(tmparray); + + return !err; + } +} + +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); +} + +int RNA_property_collection_raw_set(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, 1); +} + /* Standard iterator functions */ void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip) @@ -2457,6 +2774,17 @@ ParameterList *RNA_parameter_list_create(PointerRNA *ptr, FunctionRNA *func) void RNA_parameter_list_free(ParameterList *parms) { + PropertyRNA *parm; + int tot; + + parm= parms->func->cont.properties.first; + for(tot= 0; parm; parm= parm->next) { + if(parm->type == PROP_COLLECTION) + BLI_freelistN((ListBase*)((char*)parms->data+tot)); + + tot+= rna_parameter_size(parm); + } + MEM_freeN(parms->data); parms->data= NULL; diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 0f437f8f1a8..caa970eff57 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -443,6 +443,30 @@ void rna_EditBone_tail_selected_set(PointerRNA *ptr, int value) else data->flag &= ~BONE_TIPSEL; } +static void rna_Armature_bones_next(CollectionPropertyIterator *iter) +{ + ListBaseIterator *internal= iter->internal; + Bone *bone= (Bone*)internal->link; + + if(bone->childbase.first) + internal->link= (Link*)bone->childbase.first; + else if(bone->next) + internal->link= (Link*)bone->next; + else { + internal->link= NULL; + + do { + bone= bone->parent; + if(bone && bone->next) { + internal->link= (Link*)bone->next; + break; + } + } while(bone); + } + + iter->valid= (internal->link != NULL); +} + #else static void rna_def_bone_common(StructRNA *srna, int editbone) @@ -660,6 +684,7 @@ void rna_def_armature(BlenderRNA *brna) /* Collections */ prop= RNA_def_property(srna, "bones", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "bonebase", NULL); + RNA_def_property_collection_funcs(prop, 0, "rna_Armature_bones_next", 0, 0, 0, 0, 0, 0, 0); RNA_def_property_struct_type(prop, "Bone"); RNA_def_property_ui_text(prop, "Bones", ""); diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 90617d01833..7355261c5aa 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -184,6 +184,10 @@ void rna_def_brush(BlenderRNA *brna) prop= RNA_def_property(srna, "space", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_SPACE); RNA_def_property_ui_text(prop, "Space", "Limit brush application to the distance specified by spacing."); + + prop= RNA_def_property(srna, "smooth_stroke", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", BRUSH_SMOOTH_STROKE); + RNA_def_property_ui_text(prop, "Smooth Stroke", "Brush lags behind mouse and follows a smoother path."); /* not exposed in the interface yet prop= RNA_def_property(srna, "fixed_tex", PROP_BOOLEAN, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c index 361c1b61303..cefd2316fbf 100644 --- a/source/blender/makesrna/intern/rna_cloth.c +++ b/source/blender/makesrna/intern/rna_cloth.c @@ -34,9 +34,24 @@ #include "BKE_modifier.h" #include "DNA_cloth_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "WM_types.h" #ifdef RNA_RUNTIME +#include "BKE_context.h" +#include "BKE_depsgraph.h" + +static void rna_cloth_update(bContext *C, PointerRNA *ptr) +{ + Scene *scene = CTX_data_scene(C); + Object *ob = ptr->id.data; + + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); +} + static void rna_ClothSettings_max_bend_set(struct PointerRNA *ptr, float value) { ClothSimSettings *settings = (ClothSimSettings*)ptr->data; @@ -165,42 +180,50 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "mingoal"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Goal Minimum", "Goal minimum, vertex group weights are scaled to match this range."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "goal_max", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "maxgoal"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Goal Maximum", "Goal maximum, vertex group weights are scaled to match this range."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "goal_default", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "defgoal"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Goal Default", "Default Goal (vertex target position) value, when no Vertex Group used."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "goal_spring", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "goalspring"); RNA_def_property_range(prop, 0.0f, 0.999f); RNA_def_property_ui_text(prop, "Goal Stiffness", "Goal (vertex target position) spring stiffness."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "goal_friction", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "goalfrict"); RNA_def_property_range(prop, 0.0f, 50.0f); RNA_def_property_ui_text(prop, "Goal Damping", "Goal (vertex target position) friction."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); /* mass */ prop= RNA_def_property(srna, "mass", PROP_FLOAT, PROP_NONE); RNA_def_property_range(prop, 0.0f, 10.0f); RNA_def_property_ui_text(prop, "Mass", "Mass of cloth material."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "mass_vertex_group", PROP_STRING, PROP_NONE); RNA_def_property_string_funcs(prop, "rna_ClothSettings_mass_vgroup_get", "rna_ClothSettings_mass_vgroup_length", "rna_ClothSettings_mass_vgroup_set"); RNA_def_property_ui_text(prop, "Mass Vertex Group", "Vertex group for fine control over mass distribution."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "gravity", PROP_FLOAT, PROP_VECTOR); RNA_def_property_array(prop, 3); RNA_def_property_range(prop, -100.0, 100.0); RNA_def_property_float_funcs(prop, "rna_ClothSettings_gravity_get", "rna_ClothSettings_gravity_set", NULL); RNA_def_property_ui_text(prop, "Gravity", "Gravity or external force vector."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); /* various */ @@ -208,61 +231,73 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "Cvi"); RNA_def_property_range(prop, 0.0f, 10.0f); RNA_def_property_ui_text(prop, "Air Damping", "Air has normally some thickness which slows falling things down."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "pin_cloth", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flags", CLOTH_SIMSETTINGS_FLAG_GOAL); RNA_def_property_ui_text(prop, "Pin Cloth", "Define forces for vertices to stick to animated position."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "pin_stiffness", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "goalspring"); RNA_def_property_range(prop, 0.0f, 50.0); RNA_def_property_ui_text(prop, "Pin Stiffness", "Pin (vertex target position) spring stiffness."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "quality", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "stepsPerFrame"); RNA_def_property_range(prop, 4, 80); RNA_def_property_ui_text(prop, "Quality", "Quality of the simulation in steps per frame (higher is better quality but slower)."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); /* springs */ prop= RNA_def_property(srna, "stiffness_scaling", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flags", CLOTH_SIMSETTINGS_FLAG_SCALING); RNA_def_property_ui_text(prop, "Stiffness Scaling", "If enabled, stiffness can be scaled along a weight painted vertex group."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "spring_damping", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "Cdis"); RNA_def_property_range(prop, 0.0f, 50.0f); RNA_def_property_ui_text(prop, "Spring Damping", "Damping of cloth velocity (higher = more smooth, less jiggling)"); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "structural_stiffness", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "structural"); RNA_def_property_range(prop, 1.0f, 10000.0f); RNA_def_property_ui_text(prop, "Structural Stiffness", "Overall stiffness of structure."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "structural_stiffness_max", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "max_struct"); RNA_def_property_range(prop, 0.0f, 10000.0f); RNA_def_property_float_funcs(prop, NULL, "rna_ClothSettings_max_struct_set", NULL); RNA_def_property_ui_text(prop, "Structural Stiffness Maximum", "Maximum structural stiffness value."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "structural_stiffness_vertex_group", PROP_STRING, PROP_NONE); RNA_def_property_string_funcs(prop, "rna_ClothSettings_struct_vgroup_get", "rna_ClothSettings_struct_vgroup_length", "rna_ClothSettings_struct_vgroup_set"); RNA_def_property_ui_text(prop, "Structural Stiffness Vertex Group", "Vertex group for fine control over structural stiffness."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "bending_stiffness", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "bending"); RNA_def_property_range(prop, 0.0f, 10000.0f); RNA_def_property_ui_text(prop, "Bending Stiffness", "Wrinkle coefficient (higher = less smaller but more big wrinkles)."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "bending_stiffness_max", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "max_bend"); RNA_def_property_range(prop, 0.0f, 10000.0f); RNA_def_property_float_funcs(prop, NULL, "rna_ClothSettings_max_bend_set", NULL); RNA_def_property_ui_text(prop, "Bending Stiffness Maximum", "Maximum bending stiffness value."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "bending_vertex_group", PROP_STRING, PROP_NONE); RNA_def_property_string_funcs(prop, "rna_ClothSettings_bend_vgroup_get", "rna_ClothSettings_bend_vgroup_length", "rna_ClothSettings_bend_vgroup_set"); RNA_def_property_ui_text(prop, "Bending Stiffness Vertex Group", "Vertex group for fine control over bending stiffness."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); /* unused */ @@ -323,40 +358,48 @@ static void rna_def_cloth_collision_settings(BlenderRNA *brna) prop= RNA_def_property(srna, "enable_collision", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flags", CLOTH_COLLSETTINGS_FLAG_ENABLED); RNA_def_property_ui_text(prop, "Enable Collision", "Enable collisions with other objects."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "min_distance", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "epsilon"); RNA_def_property_range(prop, 0.001f, 1.0f); RNA_def_property_ui_text(prop, "Minimum Distance", "Minimum distance between collision objects before collision response takes in, can be changed for each frame."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "friction", PROP_FLOAT, PROP_NONE); RNA_def_property_range(prop, 0.0f, 80.0f); RNA_def_property_ui_text(prop, "Friction", "Friction force if a collision happened (0=movement not changed, 100=no movement left)"); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "collision_quality", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "loop_count"); RNA_def_property_range(prop, 1, 20); RNA_def_property_ui_text(prop, "Collision Quality", "How many collision iterations should be done. (higher is better quality but slower)"); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); /* self collision */ prop= RNA_def_property(srna, "enable_self_collision", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flags", CLOTH_COLLSETTINGS_FLAG_SELF); RNA_def_property_ui_text(prop, "Enable Self Collision", "Enable self collisions."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "self_min_distance", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "selfepsilon"); RNA_def_property_range(prop, 0.5f, 1.0f); RNA_def_property_ui_text(prop, "Self Minimum Distance", "0.5 means no distance at all, 1.0 is maximum distance"); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "self_friction", PROP_FLOAT, PROP_NONE); RNA_def_property_range(prop, 0.0f, 80.0f); RNA_def_property_ui_text(prop, "Self Friction", "Friction/damping with self contact."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); prop= RNA_def_property(srna, "self_collision_quality", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "self_loop_count"); RNA_def_property_range(prop, 1, 10); RNA_def_property_ui_text(prop, "Self Collision Quality", "How many self collision iterations should be done. (higher is better quality but slower), can be changed for each frame."); + RNA_def_property_update(prop, NC_OBJECT|ND_GEOM_DATA, "rna_cloth_update"); } void RNA_def_cloth(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c index 80c145911b1..8200a21f4ac 100644 --- a/source/blender/makesrna/intern/rna_constraint.c +++ b/source/blender/makesrna/intern/rna_constraint.c @@ -534,6 +534,14 @@ static void rna_def_constraint_locate_like(BlenderRNA *brna) srna= RNA_def_struct(brna, "CopyLocationConstraint", "Constraint"); RNA_def_struct_ui_text(srna, "Copy Location Constraint", "Copies the location of the target."); + + RNA_def_struct_sdna(srna, "bConstraint"); + + prop= RNA_def_property(srna, "head_tail", PROP_FLOAT, PROP_PERCENTAGE); + RNA_def_property_float_sdna(prop, NULL, "headtail"); + RNA_def_property_ui_text(prop, "Head/Tail", "Target along length of bone: Head=0, Tail=1."); + RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update"); + RNA_def_struct_sdna_from(srna, "bLocateLikeConstraint", "data"); prop= RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE); @@ -582,13 +590,6 @@ static void rna_def_constraint_locate_like(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", LOCLIKE_OFFSET); RNA_def_property_ui_text(prop, "Offset", "Add original location into copied location."); RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update"); - - RNA_def_struct_sdna(srna, "bConstraint"); - - prop= RNA_def_property(srna, "head_tail", PROP_FLOAT, PROP_PERCENTAGE); - RNA_def_property_float_sdna(prop, NULL, "headtail"); - RNA_def_property_ui_text(prop, "Head/Tail", "Target along length of bone: Head=0, Tail=1."); - RNA_def_property_update(prop, NC_OBJECT|ND_CONSTRAINT, "rna_Constraint_update"); } static void rna_def_constraint_minmax(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_context.c b/source/blender/makesrna/intern/rna_context.c index 07a50235733..378498c8e0a 100644 --- a/source/blender/makesrna/intern/rna_context.c +++ b/source/blender/makesrna/intern/rna_context.c @@ -40,11 +40,11 @@ static PointerRNA rna_Context_manager_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_WindowManager, CTX_wm_manager(C)); } -/*static PointerRNA rna_Context_window_get(PointerRNA *ptr) +static PointerRNA rna_Context_window_get(PointerRNA *ptr) { bContext *C= (bContext*)ptr->data; return rna_pointer_inherit_refine(ptr, &RNA_Window, CTX_wm_window(C)); -}*/ +} static PointerRNA rna_Context_screen_get(PointerRNA *ptr) { @@ -113,10 +113,10 @@ void RNA_def_context(BlenderRNA *brna) RNA_def_property_struct_type(prop, "WindowManager"); RNA_def_property_pointer_funcs(prop, "rna_Context_manager_get", NULL, NULL); - /* prop= RNA_def_property(srna, "window", PROP_POINTER, PROP_NONE); + prop= RNA_def_property(srna, "window", PROP_POINTER, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_struct_type(prop, "Window"); - RNA_def_property_pointer_funcs(prop, "rna_Context_window_get", NULL, NULL); */ + RNA_def_property_pointer_funcs(prop, "rna_Context_window_get", NULL, NULL); prop= RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index bd449acc050..715f03bb3f1 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -112,7 +112,7 @@ StructDefRNA *rna_find_struct_def(StructRNA *srna) return NULL; } -PropertyDefRNA *rna_find_struct_property_def(PropertyRNA *prop) +PropertyDefRNA *rna_find_struct_property_def(StructRNA *srna, PropertyRNA *prop) { StructDefRNA *dsrna; PropertyDefRNA *dprop; @@ -123,7 +123,7 @@ PropertyDefRNA *rna_find_struct_property_def(PropertyRNA *prop) return NULL; } - dsrna= rna_find_struct_def(DefRNA.laststruct); + dsrna= rna_find_struct_def(srna); dprop= dsrna->cont.properties.last; for (; dprop; dprop= dprop->prev) if (dprop->prop==prop) @@ -150,7 +150,7 @@ PropertyDefRNA *rna_find_property_def(PropertyRNA *prop) return NULL; } - dprop= rna_find_struct_property_def(prop); + dprop= rna_find_struct_property_def(DefRNA.laststruct, prop); if (dprop) return dprop; @@ -1311,7 +1311,7 @@ static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop, const char *stru StructDefRNA *ds; PropertyDefRNA *dp; - dp= rna_find_struct_property_def(prop); + dp= rna_find_struct_property_def(DefRNA.laststruct, prop); if (dp==NULL) return NULL; ds= rna_find_struct_def((StructRNA*)dp->cont); @@ -1371,7 +1371,7 @@ void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *struc RNA_def_property_boolean_sdna(prop, structname, propname, booleanbit); - dp= rna_find_struct_property_def(prop); + dp= rna_find_struct_property_def(DefRNA.laststruct, prop); if(dp) dp->booleannegative= 1; @@ -1468,7 +1468,7 @@ void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structnam RNA_def_property_enum_sdna(prop, structname, propname); - dp= rna_find_struct_property_def(prop); + dp= rna_find_struct_property_def(DefRNA.laststruct, prop); if(dp) dp->enumbitflags= 1; @@ -2249,7 +2249,6 @@ int rna_parameter_size(PropertyRNA *parm) #endif } case PROP_COLLECTION: - /* XXX does not work yet */ return sizeof(ListBase); } } diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index 4a6fdf5a734..c74e46c17da 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -39,6 +39,8 @@ #ifdef RNA_RUNTIME +#include "IMB_imbuf_types.h" + static void rna_Image_animated_update(bContext *C, PointerRNA *ptr) { Image *ima= (Image*)ptr->data; @@ -52,6 +54,18 @@ static void rna_Image_animated_update(bContext *C, PointerRNA *ptr) } } +static int rna_Image_dirty_get(PointerRNA *ptr) +{ + Image *ima= (Image*)ptr->data; + ImBuf *ibuf; + + for(ibuf=ima->ibufs.first; ibuf; ibuf=ibuf->next) + if(ibuf->userflags & IB_BITMAPDIRTY) + return 1; + + return 0; +} + #else static void rna_def_imageuser(BlenderRNA *brna) @@ -174,6 +188,11 @@ static void rna_def_image(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Premultiply", "Convert RGB from key alpha to premultiplied alpha."); RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL); + prop= RNA_def_property(srna, "dirty", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_Image_dirty_get", NULL); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Dirty", "Image has changed and is not saved."); + /* generated image (image_generated_change_cb) */ prop= RNA_def_property(srna, "generated_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "gen_type"); diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 09b46a32cb9..f465e733d68 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -256,6 +256,7 @@ void rna_freelistN(struct ListBase *listbase); StructDefRNA *rna_find_struct_def(StructRNA *srna); FunctionDefRNA *rna_find_function_def(FunctionRNA *func); PropertyDefRNA *rna_find_parameter_def(PropertyRNA *parm); +PropertyDefRNA *rna_find_struct_property_def(StructRNA *srna, PropertyRNA *prop); /* Pointer Handling */ diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index 8bae21cca2b..401b430ebc9 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -146,6 +146,10 @@ struct PropertyRNA { /* callback for testing if editable/evaluated */ EditableFunc editable; + + /* raw access */ + int rawoffset; + RawPropertyType rawtype; }; /* Property Types */ diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index 8d98036290a..26fc3c2941e 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -264,7 +264,7 @@ void RNA_def_main(BlenderRNA *brna) { prop= RNA_def_property(srna, lists[i][0], PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, lists[i][1]); - RNA_def_property_collection_funcs(prop, lists[i][2], "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, "add_mesh", "remove_mesh"); + RNA_def_property_collection_funcs(prop, lists[i][2], "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, 0, 0); RNA_def_property_ui_text(prop, lists[i][3], lists[i][4]); } diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 4b4c9b97871..2133ff26157 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -259,19 +259,25 @@ static int rna_Mesh_uv_layers_length(PointerRNA *ptr) static PointerRNA rna_Mesh_active_uv_layer_get(PointerRNA *ptr) { - CustomDataLayer *active_layer; - Mesh *me; - int layer_index; + Mesh *me= (Mesh*)ptr->data; + int index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); + CustomDataLayer *cdl= (index == -1)? NULL: &me->fdata.layers[index]; - active_layer= NULL; - me= (Mesh*)ptr->data; + return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl); +} - if (CustomData_has_layer(&me->fdata, CD_MTFACE)) { - layer_index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE); - active_layer= &me->fdata.layers[layer_index]; - } +static void rna_Mesh_active_uv_layer_set(PointerRNA *ptr, PointerRNA value) +{ + Mesh *me= (Mesh*)ptr->data; + CustomDataLayer *cdl; + int a; - return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, active_layer); + for(cdl=me->fdata.layers, a=0; a<me->fdata.totlayer; cdl++, a++) { + if(value.data == cdl) { + CustomData_set_layer_active_index(&me->fdata, CD_MTFACE, a); + return; + } + } } static void rna_MeshTextureFace_uv1_get(PointerRNA *ptr, float *values) @@ -388,6 +394,29 @@ static int rna_Mesh_vcol_layers_length(PointerRNA *ptr) return rna_CustomDataLayer_length(ptr, CD_MCOL); } +static PointerRNA rna_Mesh_active_vcol_layer_get(PointerRNA *ptr) +{ + Mesh *me= (Mesh*)ptr->data; + int index= CustomData_get_active_layer_index(&me->fdata, CD_MCOL); + CustomDataLayer *cdl= (index == -1)? NULL: &me->fdata.layers[index]; + + return rna_pointer_inherit_refine(ptr, &RNA_MeshColorLayer, cdl); +} + +static void rna_Mesh_active_vcol_layer_set(PointerRNA *ptr, PointerRNA value) +{ + Mesh *me= (Mesh*)ptr->data; + CustomDataLayer *cdl; + int a; + + for(cdl=me->fdata.layers, a=0; a<me->fdata.totlayer; cdl++, a++) { + if(value.data == cdl) { + CustomData_set_layer_active_index(&me->fdata, CD_MCOL, a); + return; + } + } +} + static void rna_MeshColorLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Mesh *me= (Mesh*)ptr->id.data; @@ -710,8 +739,8 @@ static void rna_def_medge(BlenderRNA *brna) prop= RNA_def_property(srna, "verts", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "v1"); RNA_def_property_array(prop, 2); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); 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); @@ -757,8 +786,8 @@ static void rna_def_mface(BlenderRNA *brna) prop= RNA_def_property(srna, "verts", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "v1"); RNA_def_property_array(prop, 4); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Vertices", "Vertex indices"); + // XXX allows creating invalid meshes prop= RNA_def_property(srna, "material_index", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "mat_nr"); @@ -1109,7 +1138,6 @@ static void rna_def_mesh(BlenderRNA *brna) 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."); - // XXX RNA_def_property_collection_funcs(prop, "rna_Mesh_verts_begin", 0, 0, 0, 0, 0, 0, "add_verts", "remove_verts"); prop= RNA_def_property(srna, "edges", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "medge", "totedge"); @@ -1126,16 +1154,21 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_struct_type(prop, "MeshSticky"); RNA_def_property_ui_text(prop, "Sticky", "Sticky texture coordinates."); + /* UV layers */ + prop= RNA_def_property(srna, "uv_layers", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer"); RNA_def_property_collection_funcs(prop, "rna_Mesh_uv_layers_begin", 0, 0, 0, "rna_Mesh_uv_layers_length", 0, 0, 0, 0); RNA_def_property_struct_type(prop, "MeshTextureFaceLayer"); RNA_def_property_ui_text(prop, "UV Layers", ""); - prop= RNA_def_property(srna, "active_uv_layer", PROP_POINTER, PROP_NONE); + prop= RNA_def_property(srna, "active_uv_layer", PROP_POINTER, PROP_UNSIGNED); RNA_def_property_struct_type(prop, "MeshTextureFaceLayer"); - RNA_def_property_pointer_funcs(prop, "rna_Mesh_active_uv_layer_get", NULL, NULL); - RNA_def_property_ui_text(prop, "Active UV layer", "Active UV layer."); + RNA_def_property_pointer_funcs(prop, "rna_Mesh_active_uv_layer_get", "rna_Mesh_active_uv_layer_set", NULL); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Active UV Layer", "Active UV layer."); + + /* VCol layers */ prop= RNA_def_property(srna, "vcol_layers", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "fdata.layers", "fdata.totlayer"); @@ -1143,6 +1176,12 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_property_struct_type(prop, "MeshColorLayer"); RNA_def_property_ui_text(prop, "Vertex Color Layers", ""); + prop= RNA_def_property(srna, "active_vcol_layer", PROP_POINTER, PROP_UNSIGNED); + RNA_def_property_struct_type(prop, "MeshColorLayer"); + RNA_def_property_pointer_funcs(prop, "rna_Mesh_active_vcol_layer_get", "rna_Mesh_active_vcol_layer_set", NULL); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Active Vertex Color Layer", "Active vertex color layer."); + prop= RNA_def_property(srna, "float_layers", 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, 0, 0); diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c index f4bc52bc517..00d5bacfef0 100644 --- a/source/blender/makesrna/intern/rna_mesh_api.c +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -34,31 +34,97 @@ #ifdef RNA_RUNTIME +#include "DNA_mesh_types.h" +#include "DNA_scene_types.h" + #include "BKE_customdata.h" +#include "BKE_depsgraph.h" #include "BKE_DerivedMesh.h" +#include "BKE_main.h" #include "BKE_mesh.h" -#include "BLI_arithb.h" - #include "DNA_mesh_types.h" #include "DNA_scene_types.h" -/* -void rna_Mesh_copy(Mesh *me, Mesh *from) +#include "BLI_arithb.h" +#include "BLI_edgehash.h" + +#include "WM_api.h" +#include "WM_types.h" + +static void rna_Mesh_calc_edges(Mesh *mesh) { - copy_mesh_data(me, from); + CustomData edata; + EdgeHashIterator *ehi; + MFace *mf = mesh->mface; + MEdge *med; + EdgeHash *eh = BLI_edgehash_new(); + int i, *index, totedge, totface = mesh->totface; + + for (i = 0; i < totface; i++, mf++) { + if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2)) + BLI_edgehash_insert(eh, mf->v1, mf->v2, NULL); + if (!BLI_edgehash_haskey(eh, mf->v2, mf->v3)) + BLI_edgehash_insert(eh, mf->v2, mf->v3, NULL); + + if (mf->v4) { + if (!BLI_edgehash_haskey(eh, mf->v3, mf->v4)) + BLI_edgehash_insert(eh, mf->v3, mf->v4, NULL); + if (!BLI_edgehash_haskey(eh, mf->v4, mf->v1)) + BLI_edgehash_insert(eh, mf->v4, mf->v1, NULL); + } else { + if (!BLI_edgehash_haskey(eh, mf->v3, mf->v1)) + BLI_edgehash_insert(eh, mf->v3, mf->v1, NULL); + } + } + + totedge = BLI_edgehash_size(eh); + + /* write new edges into a temporary CustomData */ + memset(&edata, 0, sizeof(edata)); + CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge); + + ehi = BLI_edgehashIterator_new(eh); + med = CustomData_get_layer(&edata, CD_MEDGE); + for(i = 0; !BLI_edgehashIterator_isDone(ehi); + BLI_edgehashIterator_step(ehi), ++i, ++med, ++index) { + BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, (int*)&med->v2); + + med->flag = ME_EDGEDRAW|ME_EDGERENDER; + } + BLI_edgehashIterator_free(ehi); + + /* free old CustomData and assign new one */ + CustomData_free(&mesh->edata, mesh->totedge); + mesh->edata = edata; + mesh->totedge = totedge; + + mesh->medge = CustomData_get_layer(&mesh->edata, CD_MEDGE); + + BLI_edgehash_free(eh, NULL); } -void rna_Mesh_copy_applied(Mesh *me, Scene *sce, Object *ob) +static void rna_Mesh_update(Mesh *mesh, bContext *C) { - DerivedMesh *dm= mesh_create_derived_view(sce, ob, CD_MASK_MESH); - DM_to_mesh(dm, me); - dm->release(dm); + Main *bmain= CTX_data_main(C); + Object *ob; + + if(mesh->totface && mesh->totedge == 0) + rna_Mesh_calc_edges(mesh); + + mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mface, mesh->totface, NULL); + + for(ob=bmain->object.first; ob; ob=ob->id.next) { + if(ob->data == mesh) { + ob->recalc |= OB_RECALC_DATA; + WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_DATA, ob); + } + } } -*/ -void rna_Mesh_transform(Mesh *me, float *mat) +static void rna_Mesh_transform(Mesh *me, float *mat) { + /* TODO: old API transform had recalc_normals option */ int i; MVert *mvert= me->mvert; @@ -68,6 +134,36 @@ void rna_Mesh_transform(Mesh *me, float *mat) } } +static void rna_Mesh_add_verts(Mesh *mesh, int len) +{ + CustomData vdata; + MVert *mvert; + int i, totvert; + + if(len == 0) + return; + + totvert= mesh->totvert + len; + CustomData_copy(&mesh->vdata, &vdata, CD_MASK_MESH, CD_DEFAULT, totvert); + CustomData_copy_data(&mesh->vdata, &vdata, 0, 0, mesh->totvert); + + if(!CustomData_has_layer(&vdata, CD_MVERT)) + CustomData_add_layer(&vdata, CD_MVERT, CD_CALLOC, NULL, totvert); + + CustomData_free(&mesh->vdata, mesh->totvert); + mesh->vdata= vdata; + mesh_update_customdata_pointers(mesh); + + /* scan the input list and insert the new vertices */ + + mvert= &mesh->mvert[mesh->totvert]; + for(i=0; i<len; i++, mvert++) + mvert->flag |= SELECT; + + /* set final vertex list size */ + mesh->totvert= totvert; +} + Mesh *rna_Mesh_create_copy(Mesh *me) { Mesh *ret= copy_mesh(me); @@ -76,28 +172,75 @@ Mesh *rna_Mesh_create_copy(Mesh *me) return ret; } -#if 0 -/* extern struct EditVert *addvertlist(EditMesh *em, float *vec, struct EditVert *example); */ +static void rna_Mesh_add_edges(Mesh *mesh, int len) +{ + CustomData edata; + MEdge *medge; + int i, totedge; + + if(len == 0) + return; + + totedge= mesh->totedge+len; + + /* update customdata */ + CustomData_copy(&mesh->edata, &edata, CD_MASK_MESH, CD_DEFAULT, totedge); + CustomData_copy_data(&mesh->edata, &edata, 0, 0, mesh->totedge); + + if(!CustomData_has_layer(&edata, CD_MEDGE)) + CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, NULL, totedge); + + CustomData_free(&mesh->edata, mesh->totedge); + mesh->edata= edata; + mesh_update_customdata_pointers(mesh); + + /* set default flags */ + medge= &mesh->medge[mesh->totedge]; + for(i=0; i<len; i++, medge++) + medge->flag= ME_EDGEDRAW|ME_EDGERENDER|SELECT; + + mesh->totedge= totedge; +} -static void rna_Mesh_verts_add(PointerRNA *ptr, PointerRNA *ptr_item) +static void rna_Mesh_add_faces(Mesh *mesh, int len) { - //Mesh *me= (Mesh*)ptr->data; + CustomData fdata; + MFace *mface; + int i, totface; - /* - // XXX if item is not MVert we fail silently - if (item->type == RNA_MeshVertex) + if(len == 0) return; - // XXX this must be slow... - EditMesh *em= BKE_mesh_get_editmesh(me); + totface= mesh->totface + len; /* new face count */ - MVert *v = (MVert*)ptr_item->ptr->data; - addvertlist(em, v->co, NULL); + /* update customdata */ + CustomData_copy(&mesh->fdata, &fdata, CD_MASK_MESH, CD_DEFAULT, totface); + CustomData_copy_data(&mesh->fdata, &fdata, 0, 0, mesh->totface); - BKE_mesh_end_editmesh(me, em); - */ + if(!CustomData_has_layer(&fdata, CD_MFACE)) + CustomData_add_layer(&fdata, CD_MFACE, CD_CALLOC, NULL, totface); + + CustomData_free(&mesh->fdata, mesh->totface); + mesh->fdata= fdata; + mesh_update_customdata_pointers(mesh); + + /* set default flags */ + mface= &mesh->mface[mesh->totface]; + for(i=0; i<len; i++, mface++) + mface->flag= SELECT; + + mesh->totface= totface; +} + +static void rna_Mesh_add_geometry(Mesh *mesh, int verts, int edges, int faces) +{ + if(verts) + rna_Mesh_add_verts(mesh, verts); + if(edges) + rna_Mesh_add_edges(mesh, edges); + if(faces) + rna_Mesh_add_faces(mesh, faces); } -#endif #else @@ -111,6 +254,14 @@ void RNA_api_mesh(StructRNA *srna) parm= RNA_def_float_matrix(func, "matrix", 16, NULL, 0.0f, 0.0f, "", "Matrix.", 0.0f, 0.0f); RNA_def_property_flag(parm, PROP_REQUIRED); + func= RNA_def_function(srna, "add_geometry", "rna_Mesh_add_geometry"); + parm= RNA_def_int(func, "verts", 0, 0, INT_MAX, "Number", "Number of vertices to add.", 0, INT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_int(func, "edges", 0, 0, INT_MAX, "Number", "Number of edges to add.", 0, INT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_int(func, "faces", 0, 0, INT_MAX, "Number", "Number of faces to add.", 0, INT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); + func= RNA_def_function(srna, "create_copy", "rna_Mesh_create_copy"); RNA_def_function_ui_description(func, "Create a copy of this Mesh datablock."); parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh, remove it if it is only used for export."); @@ -124,6 +275,9 @@ void RNA_api_mesh(StructRNA *srna) prop= RNA_def_collection(func, "faces", "?", "", "Faces."); RNA_def_property_flag(prop, PROP_REQUIRED); */ + + func= RNA_def_function(srna, "update", "rna_Mesh_update"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); } #endif diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 76553e09fb2..4166eb9bc2c 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -33,6 +33,7 @@ #include "DNA_customdata_types.h" #include "DNA_material_types.h" #include "DNA_mesh_types.h" +#include "DNA_object_force.h" #include "DNA_object_types.h" #include "DNA_property_types.h" #include "DNA_scene_types.h" @@ -240,6 +241,25 @@ static PointerRNA rna_Object_active_material_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_MaterialSlot, ob->mat+ob->actcol); } +static void rna_Object_active_particle_system_index_range(PointerRNA *ptr, int *min, int *max) +{ + Object *ob= (Object*)ptr->id.data; + *min= 1; + *max= BLI_countlist(&ob->particlesystem); +} + +static int rna_Object_active_particle_system_index_get(PointerRNA *ptr) +{ + Object *ob= (Object*)ptr->id.data; + return psys_get_current_num(ob) + 1; +} + +static void rna_Object_active_particle_system_index_set(struct PointerRNA *ptr, int value) +{ + Object *ob= (Object*)ptr->id.data; + psys_set_current_num(ob, value); +} + #if 0 static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value) { @@ -936,6 +956,10 @@ static void rna_def_object(BlenderRNA *brna) RNA_def_property_pointer_funcs(prop, "rna_Object_active_particle_system_get", NULL, NULL); RNA_def_property_ui_text(prop, "Active Particle System", "Active particle system being displayed"); + prop= RNA_def_property(srna, "active_particle_system_index", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_funcs(prop, "rna_Object_active_particle_system_index_get", "rna_Object_active_particle_system_index_set", "rna_Object_active_particle_system_index_range"); + RNA_def_property_ui_text(prop, "Active Particle System Index", "Index of active particle system slot."); + /* restrict */ prop= RNA_def_property(srna, "restrict_view", PROP_BOOLEAN, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_object_force.c b/source/blender/makesrna/intern/rna_object_force.c index bc3f0733a0d..4d8c728db12 100644 --- a/source/blender/makesrna/intern/rna_object_force.c +++ b/source/blender/makesrna/intern/rna_object_force.c @@ -31,6 +31,7 @@ #include "DNA_object_types.h" #include "DNA_object_force.h" +#include "DNA_scene_types.h" #include "WM_types.h" @@ -40,9 +41,38 @@ #include "BKE_context.h" #include "BKE_pointcache.h" +#include "BKE_depsgraph.h" #include "BLI_blenlib.h" +static void rna_Cache_change(bContext *C, PointerRNA *ptr) +{ + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_active_object(C); + PointCache *cache = (PointCache*)ptr->data; + PTCacheID *pid = NULL; + ListBase pidlist; + + if(!ob) + return; + + cache->flag |= PTCACHE_OUTDATED; + + BKE_ptcache_ids_from_object(&pidlist, ob); + + DAG_object_flush_update(scene, ob, OB_RECALC_DATA); + + for(pid=pidlist.first; pid; pid=pid->next) { + if(pid->cache==cache) + break; + } + + if(pid) + BKE_ptcache_update_info(pid); + + BLI_freelistN(&pidlist); +} + static void rna_Cache_toggle_disk_cache(bContext *C, PointerRNA *ptr) { Object *ob = CTX_data_active_object(C); @@ -113,6 +143,113 @@ static void rna_Cache_idname_change(bContext *C, PointerRNA *ptr) BLI_freelistN(&pidlist); } + +static int rna_SoftBodySettings_use_edges_get(PointerRNA *ptr) +{ + Object *data= (Object*)(ptr->data); + return (((data->softflag) & OB_SB_EDGES) != 0); +} + +static void rna_SoftBodySettings_use_edges_set(PointerRNA *ptr, int value) +{ + Object *data= (Object*)(ptr->data); + if(value) data->softflag |= OB_SB_EDGES; + else data->softflag &= ~OB_SB_EDGES; +} + +static int rna_SoftBodySettings_use_goal_get(PointerRNA *ptr) +{ + Object *data= (Object*)(ptr->data); + return (((data->softflag) & OB_SB_GOAL) != 0); +} + +static void rna_SoftBodySettings_use_goal_set(PointerRNA *ptr, int value) +{ + Object *data= (Object*)(ptr->data); + if(value) data->softflag |= OB_SB_GOAL; + else data->softflag &= ~OB_SB_GOAL; +} + +static int rna_SoftBodySettings_stiff_quads_get(PointerRNA *ptr) +{ + Object *data= (Object*)(ptr->data); + return (((data->softflag) & OB_SB_QUADS) != 0); +} + +static void rna_SoftBodySettings_stiff_quads_set(PointerRNA *ptr, int value) +{ + Object *data= (Object*)(ptr->data); + if(value) data->softflag |= OB_SB_QUADS; + else data->softflag &= ~OB_SB_QUADS; +} + +static int rna_SoftBodySettings_self_collision_get(PointerRNA *ptr) +{ + Object *data= (Object*)(ptr->data); + return (((data->softflag) & OB_SB_SELF) != 0); +} + +static void rna_SoftBodySettings_self_collision_set(PointerRNA *ptr, int value) +{ + Object *data= (Object*)(ptr->data); + if(value) data->softflag |= OB_SB_SELF; + else data->softflag &= ~OB_SB_SELF; +} + +static int rna_SoftBodySettings_new_aero_get(PointerRNA *ptr) +{ + Object *data= (Object*)(ptr->data); + return (((data->softflag) & OB_SB_AERO_ANGLE) != 0); +} + +static void rna_SoftBodySettings_new_aero_set(PointerRNA *ptr, int value) +{ + Object *data= (Object*)(ptr->data); + if(value) data->softflag |= OB_SB_AERO_ANGLE; + else data->softflag &= ~OB_SB_AERO_ANGLE; +} + +static int rna_SoftBodySettings_enabled_get(PointerRNA *ptr) +{ + Object *data= (Object*)(ptr->data); + return (((data->softflag) & OB_SB_ENABLE) != 0); +} + +#if 0 +static void rna_SoftBodySettings_enabled_set(PointerRNA *ptr, int value) +{ + Object *data= (Object*)(ptr->data); + if(value) data->softflag |= OB_SB_ENABLE; + else data->softflag &= ~OB_SB_ENABLE; +} +#endif + +static int rna_SoftBodySettings_face_collision_get(PointerRNA *ptr) +{ + Object *data= (Object*)(ptr->data); + return (((data->softflag) & OB_SB_FACECOLL) != 0); +} + +static void rna_SoftBodySettings_face_collision_set(PointerRNA *ptr, int value) +{ + Object *data= (Object*)(ptr->data); + if(value) data->softflag |= OB_SB_FACECOLL; + else data->softflag &= ~OB_SB_FACECOLL; +} + +static int rna_SoftBodySettings_edge_collision_get(PointerRNA *ptr) +{ + Object *data= (Object*)(ptr->data); + return (((data->softflag) & OB_SB_EDGECOLL) != 0); +} + +static void rna_SoftBodySettings_edge_collision_set(PointerRNA *ptr, int value) +{ + Object *data= (Object*)(ptr->data); + if(value) data->softflag |= OB_SB_EDGECOLL; + else data->softflag &= ~OB_SB_EDGECOLL; +} + #else static void rna_def_pointcache(BlenderRNA *brna) @@ -133,6 +270,12 @@ static void rna_def_pointcache(BlenderRNA *brna) RNA_def_property_range(prop, 1, 300000); RNA_def_property_ui_text(prop, "End", "Frame on which the simulation stops."); + prop= RNA_def_property(srna, "step", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "step"); + RNA_def_property_range(prop, 1, 20); + RNA_def_property_ui_text(prop, "Cache Step", "Number of frames between cached frames."); + RNA_def_property_update(prop, NC_OBJECT, "rna_Cache_change"); + /* flags */ prop= RNA_def_property(srna, "baked", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", PTCACHE_BAKED); @@ -150,21 +293,24 @@ static void rna_def_pointcache(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Cache is outdated", ""); + prop= RNA_def_property(srna, "frames_skipped", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", PTCACHE_FRAMES_SKIPPED); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "name"); RNA_def_property_ui_text(prop, "Name", "Cache name"); RNA_def_property_update(prop, NC_OBJECT, "rna_Cache_idname_change"); - prop= RNA_def_property(srna, "autocache", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", PTCACHE_AUTOCACHE); - RNA_def_property_ui_text(prop, "Auto Cache", "Cache changes automatically"); - //RNA_def_property_update(prop, NC_OBJECT, "rna_Cache_toggle_autocache"); + prop= RNA_def_property(srna, "quick_cache", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", PTCACHE_QUICK_CACHE); + RNA_def_property_ui_text(prop, "Quick Cache", "Update simulation with cache steps"); + RNA_def_property_update(prop, NC_OBJECT, "rna_Cache_change"); prop= RNA_def_property(srna, "info", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "info"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Cache Info", "Info on current cache status."); - } static void rna_def_collision(BlenderRNA *brna) @@ -268,6 +414,7 @@ static void rna_def_field(BlenderRNA *brna) srna= RNA_def_struct(brna, "FieldSettings", NULL); RNA_def_struct_sdna(srna, "PartDeflect"); RNA_def_struct_ui_text(srna, "Field Settings", "Field settings for an object in physics simulation."); + RNA_def_struct_ui_icon(srna, ICON_PHYSICS); /* Enums */ @@ -410,10 +557,206 @@ static void rna_def_game_softbody(BlenderRNA *brna) static void rna_def_softbody(BlenderRNA *brna) { StructRNA *srna; + PropertyRNA *prop; + + static EnumPropertyItem collision_type_items[] = { + {SBC_MODE_MANUAL, "MANUAL", 0, "Manual", "Manual adjust"}, + {SBC_MODE_AVG, "AVERAGE", 0, "Average", "Average Spring lenght * Ball Size"}, + {SBC_MODE_MIN, "MINIMAL", 0, "Minimal", "Minimal Spring lenght * Ball Size"}, + {SBC_MODE_MAX, "MAXIMAL", 0, "Maximal", "Maximal Spring lenght * Ball Size"}, + {SBC_MODE_AVGMINMAX, "MINMAX", 0, "AvMinMax", "(Min+Max)/2 * Ball Size"}, + {0, NULL, 0, NULL, NULL}}; srna= RNA_def_struct(brna, "SoftBodySettings", NULL); RNA_def_struct_sdna(srna, "SoftBody"); RNA_def_struct_ui_text(srna, "Soft Body Settings", "Soft body simulation settings for an object."); + + /* General Settings */ + + prop= RNA_def_property(srna, "friction", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "mediafrict"); + RNA_def_property_range(prop, 0.0f, 50.0f); + RNA_def_property_ui_text(prop, "Friction", "General media friction for point movements"); + + prop= RNA_def_property(srna, "mass", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "nodemass"); + RNA_def_property_range(prop, 0.0f, 50000.0f); + RNA_def_property_ui_text(prop, "Mass", ""); + + prop= RNA_def_property(srna, "gravity", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "grav"); + RNA_def_property_range(prop, -10.0f, 10.0f); + RNA_def_property_ui_text(prop, "Gravitation", "Apply gravitation to point movement"); + + prop= RNA_def_property(srna, "speed", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "physics_speed"); + RNA_def_property_range(prop, 0.01f, 100.0f); + RNA_def_property_ui_text(prop, "Speed", "Tweak timing for physics to control frequency and speed"); + + /* Goal */ + + /*prop= RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "vertgroup"); + RNA_def_property_ui_text(prop, "Vertex Group", "Use control point weight values");*/ + + prop= RNA_def_property(srna, "goal_min", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "mingoal"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Goal Minimum", "Goal minimum, vertex group weights are scaled to match this range."); + + prop= RNA_def_property(srna, "goal_max", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "maxgoal"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Goal Maximum", "Goal maximum, vertex group weights are scaled to match this range."); + + prop= RNA_def_property(srna, "goal_default", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "defgoal"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Goal Default", "Default Goal (vertex target position) value, when no Vertex Group used."); + + prop= RNA_def_property(srna, "goal_spring", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "goalspring"); + RNA_def_property_range(prop, 0.0f, 0.999f); + RNA_def_property_ui_text(prop, "Goal Stiffness", "Goal (vertex target position) spring stiffness."); + + prop= RNA_def_property(srna, "goal_friction", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "goalfrict"); + RNA_def_property_range(prop, 0.0f, 50.0f); + RNA_def_property_ui_text(prop, "Goal Damping", "Goal (vertex target position) friction."); + + /* Edge Spring Settings */ + + prop= RNA_def_property(srna, "pull", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "inspring"); + RNA_def_property_range(prop, 0.0f, 0.999f); + RNA_def_property_ui_text(prop, "Pull", "Edge spring stiffness when longer than rest length"); + + prop= RNA_def_property(srna, "push", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "inpush"); + RNA_def_property_range(prop, 0.0f, 0.999f); + RNA_def_property_ui_text(prop, "Push", "Edge spring stiffness when shorter than rest length"); + + prop= RNA_def_property(srna, "damp", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "infrict"); + RNA_def_property_range(prop, 0.0f, 50.0f); + RNA_def_property_ui_text(prop, "Damp", "Edge spring friction"); + + prop= RNA_def_property(srna, "spring_lenght", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "springpreload"); + RNA_def_property_range(prop, 0.0f, 200.0f); + RNA_def_property_ui_text(prop, "SL", "Alter spring lenght to shrink/blow up (unit %) 0 to disable"); + + prop= RNA_def_property(srna, "aero", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "aeroedge"); + RNA_def_property_range(prop, 0.0f, 30000.0f); + RNA_def_property_ui_text(prop, "Aero", "Make edges 'sail'"); + + prop= RNA_def_property(srna, "plastic", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "plastic"); + RNA_def_property_range(prop, 0.0f, 100.0f); + RNA_def_property_ui_text(prop, "Plastic", "Permanent deform"); + + prop= RNA_def_property(srna, "bending", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "secondspring"); + RNA_def_property_range(prop, 0.0f, 10.0f); + RNA_def_property_ui_text(prop, "Bending", "Bending Stiffness"); + + prop= RNA_def_property(srna, "shear", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "shearstiff"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Shear", "Shear Stiffness"); + + /* Collision */ + + prop= RNA_def_property(srna, "collision_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "sbc_mode"); + RNA_def_property_enum_items(prop, collision_type_items); + RNA_def_property_ui_text(prop, "Collision Type", "Choose Collision Type"); + + prop= RNA_def_property(srna, "ball_size", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "colball"); + RNA_def_property_range(prop, -10.0f, 10.0f); + RNA_def_property_ui_text(prop, "Ball Size", "Absolute ball size or factor if not manual adjusted"); + + prop= RNA_def_property(srna, "ball_stiff", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "ballstiff"); + RNA_def_property_range(prop, 0.001f, 100.0f); + RNA_def_property_ui_text(prop, "Ball Size", "Ball inflating presure"); + + prop= RNA_def_property(srna, "ball_damp", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "balldamp"); + RNA_def_property_range(prop, 0.001f, 1.0f); + RNA_def_property_ui_text(prop, "Ball Size", "Blending to inelastic collision"); + + /* Solver */ + + prop= RNA_def_property(srna, "error_limit", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "rklimit"); + RNA_def_property_range(prop, 0.001f, 10.0f); + RNA_def_property_ui_text(prop, "Error Limit", "The Runge-Kutta ODE solver error limit, low value gives more precision, high values speed"); + + prop= RNA_def_property(srna, "minstep", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "minloops"); + RNA_def_property_range(prop, 0, 30000); + RNA_def_property_ui_text(prop, "Min Step", "Minimal # solver steps/frame"); + + prop= RNA_def_property(srna, "maxstep", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "maxloops"); + RNA_def_property_range(prop, 0, 30000); + RNA_def_property_ui_text(prop, "Max Step", "Maximal # solver steps/frame"); + + prop= RNA_def_property(srna, "choke", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "choke"); + RNA_def_property_range(prop, 0, 100); + RNA_def_property_ui_text(prop, "Choke", "'Viscosity' inside collision target"); + + prop= RNA_def_property(srna, "fuzzy", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "fuzzyness"); + RNA_def_property_range(prop, 1, 100); + RNA_def_property_ui_text(prop, "Fuzzy", "Fuzzyness while on collision, high values make collsion handling faster but less stable"); + + prop= RNA_def_property(srna, "auto_step", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "solverflags", SBSO_OLDERR); + RNA_def_property_ui_text(prop, "V", "Use velocities for automagic step sizes"); + + prop= RNA_def_property(srna, "diagnose", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "solverflags", SBSO_MONITOR); + RNA_def_property_ui_text(prop, "Print Performance to Console", "Turn on SB diagnose console prints"); + + /* Flags */ + + prop= RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_SoftBodySettings_enabled_get", "rna_SoftBodySettings_enabled_set"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Enable", "Sets object to become soft body."); + + prop= RNA_def_property(srna, "use_goal", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_SoftBodySettings_use_goal_get", "rna_SoftBodySettings_use_goal_set"); + RNA_def_property_ui_text(prop, "Use Goal", "Define forces for vertices to stick to animated position."); + + prop= RNA_def_property(srna, "use_edges", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_SoftBodySettings_use_edges_get", "rna_SoftBodySettings_use_edges_set"); + RNA_def_property_ui_text(prop, "Use Edges", "Use Edges as springs"); + + prop= RNA_def_property(srna, "stiff_quads", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_SoftBodySettings_stiff_quads_get", "rna_SoftBodySettings_stiff_quads_set"); + RNA_def_property_ui_text(prop, "Stiff Quads", "Adds diagonal springs on 4-gons."); + + prop= RNA_def_property(srna, "edge_collision", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_SoftBodySettings_edge_collision_get", "rna_SoftBodySettings_edge_collision_set"); + RNA_def_property_ui_text(prop, "Edge Collision", "Edges collide too."); + + prop= RNA_def_property(srna, "face_collision", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_SoftBodySettings_face_collision_get", "rna_SoftBodySettings_face_collision_set"); + RNA_def_property_ui_text(prop, "Face Collision", "Faces collide too, SLOOOOOW warning."); + + prop= RNA_def_property(srna, "new_aero", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_SoftBodySettings_new_aero_get", "rna_SoftBodySettings_new_aero_set"); + RNA_def_property_ui_text(prop, "N", "New aero(uses angle and length)."); + + prop= RNA_def_property(srna, "self_collision", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_SoftBodySettings_self_collision_get", "rna_SoftBodySettings_self_collision_set"); + RNA_def_property_ui_text(prop, "Self Collision", "Enable naive vertex ball self collision."); } void RNA_def_object_force(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index ae53c815ed9..d60a215b498 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -81,13 +81,11 @@ static void rna_Particle_reset(bContext *C, PointerRNA *ptr) if(ob) { DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - //WM_event_add_notifier(C, NC_SCENE|ND_CACHE_PHYSICS, scene); } } else { part = ptr->id.data; psys_flush_particle_settings(scene, part, PSYS_RECALC_RESET); - //WM_event_add_notifier(C, NC_SCENE|ND_CACHE_PHYSICS, scene); } } @@ -104,13 +102,11 @@ static void rna_Particle_change_type(bContext *C, PointerRNA *ptr) if(ob) { DAG_object_flush_update(scene, ob, OB_RECALC_DATA); - //WM_event_add_notifier(C, NC_SCENE|ND_CACHE_PHYSICS, scene); } } else { part = ptr->id.data; psys_flush_particle_settings(scene, part, PSYS_RECALC_RESET|PSYS_RECALC_TYPE); - //WM_event_add_notifier(C, NC_SCENE|ND_CACHE_PHYSICS, scene); } } @@ -134,6 +130,27 @@ static void rna_Particle_redo_child(bContext *C, PointerRNA *ptr) psys_flush_particle_settings(scene, part, PSYS_RECALC_CHILD); } } +static PointerRNA rna_particle_settings_get(PointerRNA *ptr) +{ + Object *ob= (Object*)ptr->id.data; + ParticleSettings *part = psys_get_current(ob)->part; + + return rna_pointer_inherit_refine(ptr, &RNA_ParticleSettings, part); +} + +static void rna_particle_settings_set(PointerRNA *ptr, PointerRNA value) +{ + Object *ob= (Object*)ptr->id.data; + ParticleSystem *psys = psys_get_current(ob); + + if(psys->part) + psys->part->id.us--; + + psys->part = (ParticleSettings *)value.data; + + if(psys->part) + psys->part->id.us++; +} static void rna_PartSettings_start_set(struct PointerRNA *ptr, float value) { ParticleSettings *settings = (ParticleSettings*)ptr->data; @@ -1493,9 +1510,15 @@ static void rna_def_particle_system(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_struct_name_property(srna, prop); + /* access to particle settings is redirected through functions */ + /* to allow proper id-buttons functionality */ prop= RNA_def_property(srna, "settings", PROP_POINTER, PROP_NEVER_NULL); - RNA_def_property_pointer_sdna(prop, NULL, "part"); + //RNA_def_property_pointer_sdna(prop, NULL, "part"); + RNA_def_property_struct_type(prop, "ParticleSettings"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_pointer_funcs(prop, "rna_particle_settings_get", "rna_particle_settings_set", NULL); RNA_def_property_ui_text(prop, "Settings", "Particle system settings."); + RNA_def_property_update(prop, NC_OBJECT|ND_PARTICLE, "rna_Particle_reset"); prop= RNA_def_property(srna, "particles", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "particles", "totpart"); diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index 6fa275cec91..14db8ea3377 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -309,14 +309,16 @@ PointerRNA rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key } } while((srna=srna->base)); - group= RNA_struct_idproperties(ptr, 0); - - if(group) { - for(idp=group->data.group.first; idp; idp=idp->next) { - if(strcmp(idp->name, key) == 0) { - propptr.type= &RNA_Property; - propptr.data= idp; - return propptr; + if(ptr->data) { + group= RNA_struct_idproperties(ptr, 0); + + if(group) { + for(idp=group->data.group.first; idp; idp=idp->next) { + if(strcmp(idp->name, key) == 0) { + propptr.type= &RNA_Property; + propptr.data= idp; + return propptr; + } } } } diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c index b7279757455..a4ba6ec172b 100644 --- a/source/blender/makesrna/intern/rna_screen.c +++ b/source/blender/makesrna/intern/rna_screen.c @@ -42,6 +42,31 @@ EnumPropertyItem region_type_items[] = { #ifdef RNA_RUNTIME +#include "WM_api.h" +#include "WM_types.h" + +static void rna_Screen_scene_set(PointerRNA *ptr, PointerRNA value) +{ + bScreen *sc= (bScreen*)ptr->data; + + if(value.data == NULL) + return; + + /* exception: can't set screens inside of area/region handers */ + sc->newscene= value.data; +} + +static void rna_Screen_scene_update(bContext *C, PointerRNA *ptr) +{ + bScreen *sc= (bScreen*)ptr->data; + + /* exception: can't set screens inside of area/region handers */ + if(sc->newscene) { + WM_event_add_notifier(C, NC_SCENE|ND_SCENEBROWSE, sc->newscene); + sc->newscene= NULL; + } +} + #else static void rna_def_scrarea(BlenderRNA *brna) @@ -94,6 +119,9 @@ static void rna_def_bscreen(BlenderRNA *brna) prop= RNA_def_property(srna, "scene", PROP_POINTER, PROP_NEVER_NULL); RNA_def_property_ui_text(prop, "Scene", "Active scene to be edited in the screen."); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_pointer_funcs(prop, NULL, "rna_Screen_scene_set", NULL); + RNA_def_property_update(prop, 0, "rna_Screen_scene_update"); prop= RNA_def_property(srna, "areas", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "areabase", NULL); diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index d5ac0d6e427..ae3b249e51f 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -96,8 +96,8 @@ static StructRNA* rna_Space_refine(struct PointerRNA *ptr) return &RNA_SpaceOutliner; case SPACE_BUTS: return &RNA_SpaceButtonsWindow; - /* case SPACE_FILE: - return &RNA_SpaceFileBrowser;*/ + case SPACE_FILE: + return &RNA_SpaceFileBrowser; case SPACE_IMAGE: return &RNA_SpaceImageEditor; /*case SPACE_INFO: @@ -210,6 +210,13 @@ void rna_SpaceTextEditor_text_set(PointerRNA *ptr, PointerRNA value) st->top= 0; } +void rna_SpaceFileBrowser_params_set(PointerRNA *ptr, PointerRNA value) +{ + SpaceFile *sfile= (SpaceFile*)(ptr->data); + + sfile->params= value.data; +} + /* Space Buttons */ StructRNA *rna_SpaceButtonsWindow_pin_id_typef(PointerRNA *ptr) @@ -860,12 +867,124 @@ static void rna_def_space_text(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Replace Text", "Text to replace selected text with using the replace tool."); } +static void rna_def_fileselect_params(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + static EnumPropertyItem file_display_items[] = { + {FILE_SHORTDISPLAY, "FILE_SHORTDISPLAY", ICON_SHORTDISPLAY, "Short List", "Display files as short list"}, + {FILE_LONGDISPLAY, "FILE_LONGDISPLAY", ICON_LONGDISPLAY, "Long List", "Display files as a detailed list"}, + {FILE_IMGDISPLAY, "FILE_IMGDISPLAY", ICON_IMGDISPLAY, "Thumbnails", "Display files as thumbnails"}, + {0, NULL, 0, NULL, NULL}}; + + static EnumPropertyItem file_sort_items[] = { + {FILE_SORT_ALPHA, "FILE_SORT_ALPHA", ICON_SORTALPHA, "Sort alphabetically", "Sort the file list alphabetically."}, + {FILE_SORT_EXTENSION, "FILE_SORT_EXTENSION", ICON_SORTBYEXT, "Sort by extension", "Sort the file list by extension."}, + {FILE_SORT_TIME, "FILE_SORT_TIME", ICON_SORTTIME, "Sort by time", "Sort files by modification time."}, + {FILE_SORT_SIZE, "FILE_SORT_SIZE", ICON_SORTSIZE, "Sort by size", "Sort files by size."}, + {0, NULL, 0, NULL, NULL}}; + + srna= RNA_def_struct(brna, "FileSelectParams", NULL); + RNA_def_struct_ui_text(srna, "File Select Parameters", "File Select Parameters."); + + prop= RNA_def_property(srna, "display", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "display"); + RNA_def_property_enum_items(prop, file_display_items); + RNA_def_property_ui_text(prop, "Display Mode", "Display mode for the file list"); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + prop= RNA_def_property(srna, "do_filter", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", FILE_FILTER); + RNA_def_property_ui_text(prop, "Filter Files", "Enable filtering of files."); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + prop= RNA_def_property(srna, "hide_dot", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", FILE_HIDE_DOT); + RNA_def_property_ui_text(prop, "Hide Dot Files", "Hide hidden dot files."); + RNA_def_property_update(prop, NC_FILE | ND_FILELIST , NULL); + + prop= RNA_def_property(srna, "sort", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "sort"); + RNA_def_property_enum_items(prop, file_sort_items); + RNA_def_property_ui_text(prop, "Sort", ""); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + prop= RNA_def_property(srna, "filter_image", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "filter", IMAGEFILE); + RNA_def_property_ui_text(prop, "Filter Images", "Show image files."); + RNA_def_property_ui_icon(prop, ICON_FILE_IMAGE, 0); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + prop= RNA_def_property(srna, "filter_blender", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "filter", BLENDERFILE); + RNA_def_property_ui_text(prop, "Filter Blender", "Show .blend files."); + RNA_def_property_ui_icon(prop, ICON_FILE_BLEND, 0); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + prop= RNA_def_property(srna, "filter_movie", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "filter", MOVIEFILE); + RNA_def_property_ui_text(prop, "Filter Movies", "Show movie files."); + RNA_def_property_ui_icon(prop, ICON_FILE_MOVIE, 0); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + prop= RNA_def_property(srna, "filter_script", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "filter", PYSCRIPTFILE); + RNA_def_property_ui_text(prop, "Filter Script", "Show script files."); + RNA_def_property_ui_icon(prop, ICON_FILE_SCRIPT, 0); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + prop= RNA_def_property(srna, "filter_font", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "filter", FTFONTFILE); + RNA_def_property_ui_text(prop, "Filter Fonts", "Show font files."); + RNA_def_property_ui_icon(prop, ICON_FILE_FONT, 0); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + prop= RNA_def_property(srna, "filter_sound", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "filter", SOUNDFILE); + RNA_def_property_ui_text(prop, "Filter Sound", "Show sound files."); + RNA_def_property_ui_icon(prop, ICON_FILE_SOUND, 0); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + prop= RNA_def_property(srna, "filter_text", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "filter", TEXTFILE); + RNA_def_property_ui_text(prop, "Filter Text", "Show text files."); + RNA_def_property_ui_icon(prop, ICON_FILE_BLANK, 0); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + prop= RNA_def_property(srna, "filter_folder", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "filter", FOLDERFILE); + RNA_def_property_ui_text(prop, "Filter Folder", "Show folders."); + RNA_def_property_ui_icon(prop, ICON_FILE_FOLDER, 0); + RNA_def_property_update(prop, NC_FILE | ND_PARAMS, NULL); + + +} + +static void rna_def_space_filebrowser(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "SpaceFileBrowser", "Space"); + RNA_def_struct_sdna(srna, "SpaceFile"); + RNA_def_struct_ui_text(srna, "Space File Browser", "File browser space data."); + + prop= RNA_def_property(srna, "params", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "params"); + RNA_def_property_pointer_funcs(prop, NULL, "rna_SpaceFileBrowser_params_set", NULL); + RNA_def_property_ui_text(prop, "Filebrowser Parameter", "Parameters and Settings for the Filebrowser."); + +} + void RNA_def_space(BlenderRNA *brna) { rna_def_space(brna); rna_def_space_image(brna); rna_def_space_sequencer(brna); rna_def_space_text(brna); + rna_def_fileselect_params(brna); + rna_def_space_filebrowser(brna); rna_def_space_outliner(brna); rna_def_background_image(brna); rna_def_space_3dview(brna); diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 825b3711b97..eef221e45a4 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -416,12 +416,12 @@ static int rna_UILayout_active_get(struct PointerRNA *ptr) static void rna_UILayout_active_set(struct PointerRNA *ptr, int value) { - return uiLayoutSetActive(ptr->data, value); + uiLayoutSetActive(ptr->data, value); } static void rna_UILayout_op_context_set(struct PointerRNA *ptr, int value) { - return uiLayoutSetOperatorContext(ptr->data, value); + uiLayoutSetOperatorContext(ptr->data, value); } static int rna_UILayout_op_context_get(struct PointerRNA *ptr) @@ -436,7 +436,7 @@ static int rna_UILayout_enabled_get(struct PointerRNA *ptr) static void rna_UILayout_enabled_set(struct PointerRNA *ptr, int value) { - return uiLayoutSetEnabled(ptr->data, value); + uiLayoutSetEnabled(ptr->data, value); } static int rna_UILayout_red_alert_get(struct PointerRNA *ptr) @@ -446,7 +446,7 @@ static int rna_UILayout_red_alert_get(struct PointerRNA *ptr) static void rna_UILayout_red_alert_set(struct PointerRNA *ptr, int value) { - return uiLayoutSetRedAlert(ptr->data, value); + uiLayoutSetRedAlert(ptr->data, value); } static int rna_UILayout_keep_aspect_get(struct PointerRNA *ptr) @@ -456,7 +456,7 @@ static int rna_UILayout_keep_aspect_get(struct PointerRNA *ptr) static void rna_UILayout_keep_aspect_set(struct PointerRNA *ptr, int value) { - return uiLayoutSetKeepAspect(ptr->data, value); + uiLayoutSetKeepAspect(ptr->data, value); } static int rna_UILayout_alignment_get(struct PointerRNA *ptr) @@ -466,7 +466,7 @@ static int rna_UILayout_alignment_get(struct PointerRNA *ptr) static void rna_UILayout_alignment_set(struct PointerRNA *ptr, int value) { - return uiLayoutSetAlignment(ptr->data, value); + uiLayoutSetAlignment(ptr->data, value); } static float rna_UILayout_scale_x_get(struct PointerRNA *ptr) @@ -476,7 +476,7 @@ static float rna_UILayout_scale_x_get(struct PointerRNA *ptr) static void rna_UILayout_scale_x_set(struct PointerRNA *ptr, float value) { - return uiLayoutSetScaleX(ptr->data, value); + uiLayoutSetScaleX(ptr->data, value); } static float rna_UILayout_scale_y_get(struct PointerRNA *ptr) @@ -486,7 +486,7 @@ static float rna_UILayout_scale_y_get(struct PointerRNA *ptr) static void rna_UILayout_scale_y_set(struct PointerRNA *ptr, float value) { - return uiLayoutSetScaleY(ptr->data, value); + uiLayoutSetScaleY(ptr->data, value); } #else // RNA_RUNTIME diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index 75de9d53766..b70112eebed 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -136,6 +136,14 @@ void RNA_api_ui_layout(StructRNA *srna) parm= RNA_def_string(func, "value", "", 0, "", "Enum property value."); RNA_def_property_flag(parm, PROP_REQUIRED);*/ + func= RNA_def_function(srna, "item_pointerR", "uiItemPointerR"); + api_ui_item_common(func); + api_ui_item_rna_common(func); + parm= RNA_def_pointer(func, "search_data", "AnyType", "", "Data from which to take collection to search in."); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR); + parm= RNA_def_string(func, "search_property", "", 0, "", "Identifier of search collection property."); + RNA_def_property_flag(parm, PROP_REQUIRED); + func= RNA_def_function(srna, "itemO", "uiItemO"); api_ui_item_op_common(func); @@ -211,7 +219,6 @@ void RNA_api_ui_layout(StructRNA *srna) RNA_def_function_flag(func, FUNC_USE_CONTEXT); api_ui_item_rna_common(func); RNA_def_string(func, "new", "", 0, "", "Operator identifier to create a new ID block."); - RNA_def_string(func, "open", "", 0, "", "Operator identifier to open a new ID block."); RNA_def_string(func, "unlink", "", 0, "", "Operator identifier to unlink the ID block."); func= RNA_def_function(srna, "template_modifier", "uiTemplateModifier"); @@ -252,9 +259,18 @@ void RNA_api_ui_layout(StructRNA *srna) func= RNA_def_function(srna, "template_list", "uiTemplateList"); api_ui_item_rna_common(func); - parm= RNA_def_string(func, "active_property", "", 0, "", "Identifier of property in data, indicating the active element."); + parm= RNA_def_string(func, "active_property", "", 0, "", "Identifier of property in data, for the active element."); RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_int(func, "items", 5, 0, INT_MAX, "", "Number of items to display.", 0, INT_MAX); + parm= RNA_def_int(func, "rows", 5, 0, INT_MAX, "", "Number of rows to display.", 0, INT_MAX); + parm= RNA_def_int(func, "columns", 5, 0, INT_MAX, "", "Number of columns to display.", 0, INT_MAX); + parm= RNA_def_boolean(func, "compact", 0, "", "Use compact, single row list template."); + parm= RNA_def_collection(func, "items", 0, "", "Items visible in the list."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "template_running_jobs", "uiTemplateRunningJobs"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + + func= RNA_def_function(srna, "template_operator_search", "uiTemplateOperatorSearch"); } #endif diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 1bfc3b6f8f6..f8ab3a86744 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -147,6 +147,8 @@ EnumPropertyItem event_type_items[] = { #ifdef RNA_RUNTIME +#include "WM_api.h" + #include "BKE_idprop.h" static wmOperator *rna_OperatorProperties_find_operator(PointerRNA *ptr) @@ -215,6 +217,28 @@ static int rna_Event_ascii_length(PointerRNA *ptr) return (event->ascii)? 1 : 0; } +static void rna_Window_screen_set(PointerRNA *ptr, PointerRNA value) +{ + wmWindow *win= (wmWindow*)ptr->data; + + if(value.data == NULL) + return; + + /* exception: can't set screens inside of area/region handers */ + win->newscreen= value.data; +} + +static void rna_Window_screen_update(bContext *C, PointerRNA *ptr) +{ + wmWindow *win= (wmWindow*)ptr->data; + + /* exception: can't set screens inside of area/region handers */ + if(win->newscreen) { + WM_event_add_notifier(C, NC_SCREEN|ND_SCREENBROWSE, win->newscreen); + win->newscreen= NULL; + } +} + #else static void rna_def_operator(BlenderRNA *brna) @@ -349,6 +373,23 @@ static void rna_def_event(BlenderRNA *brna) RNA_def_property_ui_text(prop, "OS Key", "True when the shift key is held."); } +static void rna_def_window(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna= RNA_def_struct(brna, "Window", NULL); + RNA_def_struct_ui_text(srna, "Window", "Open window."); + RNA_def_struct_sdna(srna, "wmWindow"); + + prop= RNA_def_property(srna, "screen", PROP_POINTER, PROP_NEVER_NULL); + RNA_def_property_struct_type(prop, "Screen"); + RNA_def_property_ui_text(prop, "Screen", "Active screen showing in the window."); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_pointer_funcs(prop, NULL, "rna_Window_screen_set", NULL); + RNA_def_property_update(prop, 0, "rna_Window_screen_update"); +} + static void rna_def_windowmanager(BlenderRNA *brna) { StructRNA *srna; @@ -362,6 +403,10 @@ static void rna_def_windowmanager(BlenderRNA *brna) RNA_def_property_struct_type(prop, "Operator"); RNA_def_property_ui_text(prop, "Operators", "Operator registry."); + prop= RNA_def_property(srna, "windows", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_type(prop, "Window"); + RNA_def_property_ui_text(prop, "Windows", "Open windows."); + RNA_api_wm(srna); } @@ -371,6 +416,7 @@ void RNA_def_wm(BlenderRNA *brna) rna_def_operator_utils(brna); rna_def_operator_filelist_element(brna); rna_def_event(brna); + rna_def_window(brna); rna_def_windowmanager(brna); } |