From 4df00c670ef2e03d3dc55b67594e96cc49766831 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 3 Jun 2009 23:22:43 +0000 Subject: RNA: * Added a MaterialSlot collection in Object rather than giving the list of materials immediately. This should more correctly reflect how this data is organized, even though there is no equivalent C struct. * Added name properties to MaterialSlot/TextureSlot/ParticleSystem. --- source/blender/makesrna/RNA_access.h | 1 + source/blender/makesrna/intern/rna_object.c | 119 +++++++++++++++++++++----- source/blender/makesrna/intern/rna_particle.c | 32 +++++++ source/blender/makesrna/intern/rna_texture.c | 54 ++++++++++++ 4 files changed, 185 insertions(+), 21 deletions(-) (limited to 'source') diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index f1b52ae49ed..70490259832 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -156,6 +156,7 @@ extern StructRNA RNA_Material; extern StructRNA RNA_MaterialHalo; extern StructRNA RNA_MaterialRaytraceMirror; extern StructRNA RNA_MaterialRaytraceTransparency; +extern StructRNA RNA_MaterialSlot; extern StructRNA RNA_MaterialStrand; extern StructRNA RNA_MaterialSubsurfaceScattering; extern StructRNA RNA_MaterialTextureSlot; diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index bfd3864bddd..d945fb26982 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -22,6 +22,7 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include #include #include "RNA_define.h" @@ -30,6 +31,7 @@ #include "rna_internal.h" #include "DNA_customdata_types.h" +#include "DNA_material_types.h" #include "DNA_mesh_types.h" #include "DNA_object_types.h" #include "DNA_property_types.h" @@ -175,7 +177,7 @@ static void rna_Object_active_material_index_range(PointerRNA *ptr, int *min, in static PointerRNA rna_Object_active_material_get(PointerRNA *ptr) { Object *ob= (Object*)ptr->id.data; - return rna_pointer_inherit_refine(ptr, &RNA_Material, give_current_material(ob, ob->actcol)); + return rna_pointer_inherit_refine(ptr, &RNA_MaterialSlot, ob->mat+ob->actcol); } #if 0 @@ -187,20 +189,68 @@ static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value) } #endif -static int rna_Object_active_material_link_get(PointerRNA *ptr) +static PointerRNA rna_MaterialSlot_material_get(PointerRNA *ptr) { Object *ob= (Object*)ptr->id.data; - return (ob->colbits & 1<<(ob->actcol)) != 0; + Material *ma; + int index= (Material**)ptr->data - ob->mat; + + ma= give_current_material(ob, index+1); + return rna_pointer_inherit_refine(ptr, &RNA_Material, ma); } -static void rna_Object_active_material_link_set(PointerRNA *ptr, int value) +static void rna_MaterialSlot_material_set(PointerRNA *ptr, PointerRNA value) { Object *ob= (Object*)ptr->id.data; + int index= (Material**)ptr->data - ob->mat; + + assign_material(ob, value.data, index+1); +} + +static int rna_MaterialSlot_link_get(PointerRNA *ptr) +{ + Object *ob= (Object*)ptr->id.data; + int index= (Material**)ptr->data - ob->mat; + + return (ob->colbits & (1<id.data; + int index= (Material**)ptr->data - ob->mat; if(value) - ob->colbits |= (1<<(ob->actcol)); + ob->colbits |= (1<colbits &= ~(1<<(ob->actcol)); + ob->colbits &= ~(1<id.data; + Material *ma; + int index= (Material**)ptr->data - ob->mat; + + ma= give_current_material(ob, index+1); + + if(ma) + return strlen(ma->id.name+2) + 10; + + return 10; +} + +static void rna_MaterialSlot_name_get(PointerRNA *ptr, char *str) +{ + Object *ob= (Object*)ptr->id.data; + Material *ma; + int index= (Material**)ptr->data - ob->mat; + + sprintf(str, "%d: ", index+1); + + ma= give_current_material(ob, index+1); + if(ma) + strcat(str, ma->id.name+2); } static PointerRNA rna_Object_active_particle_system_get(PointerRNA *ptr) @@ -275,6 +325,42 @@ static void rna_def_vertex_group(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Index", "Index number of the vertex group."); } +static void rna_def_material_slot(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + static EnumPropertyItem link_items[] = { + {0, "DATA", "Data", ""}, + {1, "OBJECT", "Object", ""}, + {0, NULL, NULL, NULL}}; + + /* NOTE: there is no MaterialSlot equivalent in DNA, so the internal + * pointer data points to ob->mat + index, and we manually implement + * get/set for the properties. */ + + srna= RNA_def_struct(brna, "MaterialSlot", NULL); + RNA_def_struct_ui_text(srna, "Material Slot", "Material slot in an object."); + RNA_def_struct_ui_icon(srna, ICON_MATERIAL_DATA); + + prop= RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "Material"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_pointer_funcs(prop, "rna_MaterialSlot_material_get", "rna_MaterialSlot_material_set"); + RNA_def_property_ui_text(prop, "Material", "Material datablock used by this material slot."); + + prop= RNA_def_property(srna, "link", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, link_items); + RNA_def_property_enum_funcs(prop, "rna_MaterialSlot_link_get", "rna_MaterialSlot_link_set", NULL); + RNA_def_property_ui_text(prop, "Link", "Link material to object or the object's data."); + + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_string_funcs(prop, "rna_MaterialSlot_name_get", "rna_MaterialSlot_name_length", NULL); + RNA_def_property_ui_text(prop, "Name", "Material slot name."); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_struct_name_property(srna, prop); +} + static void rna_def_object_game_settings(BlenderRNA *brna) { StructRNA *srna; @@ -508,11 +594,6 @@ static StructRNA *rna_def_object(BlenderRNA *brna) {OB_BOUND_POLYH, "POLYHEDER", "Polyheder", ""}, {0, NULL, NULL, NULL}}; - static EnumPropertyItem material_link_items[] = { - {0, "DATA", "Data", ""}, - {1, "OBJECT", "Object", ""}, - {0, NULL, NULL, NULL}}; - static EnumPropertyItem dupli_items[] = { {0, "NONE", "None", ""}, {OB_DUPLIFRAMES, "FRAMES", "Frames", "Make copy of object for every frame."}, @@ -590,26 +671,21 @@ static StructRNA *rna_def_object(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Proxy Group", "Library group duplicator object this proxy object controls."); /* materials */ - prop= RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol"); - RNA_def_property_struct_type(prop, "Material"); - RNA_def_property_ui_text(prop, "Materials", ""); + RNA_def_property_struct_type(prop, "MaterialSlot"); + RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_iterator_array_get", 0, 0, 0); /* don't dereference pointer! */ + RNA_def_property_ui_text(prop, "Materials", "Material slots in the object."); prop= RNA_def_property(srna, "active_material", PROP_POINTER, PROP_NONE); - RNA_def_property_struct_type(prop, "Material"); + RNA_def_property_struct_type(prop, "MaterialSlot"); RNA_def_property_pointer_funcs(prop, "rna_Object_active_material_get", NULL); RNA_def_property_ui_text(prop, "Active Material", "Active material being displayed."); prop= RNA_def_property(srna, "active_material_index", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "actcol"); RNA_def_property_int_funcs(prop, NULL, NULL, "rna_Object_active_material_index_range"); - RNA_def_property_ui_text(prop, "Active Material Index", "Index of active material."); - - prop= RNA_def_property(srna, "active_material_link", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_items(prop, material_link_items); - RNA_def_property_enum_funcs(prop, "rna_Object_active_material_link_get", "rna_Object_active_material_link_set", NULL); - RNA_def_property_ui_text(prop, "Active Material Link", "Use material from object or data for the active material."); + RNA_def_property_ui_text(prop, "Active Material Index", "Index of active material slot."); /* transform */ @@ -971,6 +1047,7 @@ void RNA_def_object(BlenderRNA *brna) rna_def_object(brna); rna_def_object_game_settings(brna); rna_def_vertex_group(brna); + rna_def_material_slot(brna); } #endif diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index 40069a995ea..ee755fca27e 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -22,6 +22,7 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include #include #include "limits.h" @@ -33,6 +34,7 @@ #include "DNA_particle_types.h" #include "DNA_object_force.h" +#include "DNA_object_types.h" #ifdef RNA_RUNTIME @@ -86,6 +88,29 @@ static float rna_PartSetting_linelenhead_get(struct PointerRNA *ptr) ParticleSettings *settings = (ParticleSettings*)ptr->data; return settings->draw_line[1]; } + +static int rna_ParticleSystem_name_length(PointerRNA *ptr) +{ + ParticleSystem *psys= ptr->data; + + if(psys->part) + return strlen(psys->part->id.name+2) + 10; + + return 10; +} + +static void rna_ParticleSystem_name_get(PointerRNA *ptr, char *str) +{ + Object *ob= ptr->id.data; + ParticleSystem *psys= ptr->data; + int index= BLI_findindex(&ob->particlesystem, psys); + + sprintf(str, "%d: ", index+1); + + if(psys->part) + strcat(str, psys->part->id.name+2); +} + #else static void rna_def_particle_hair_key(BlenderRNA *brna) @@ -1176,6 +1201,13 @@ static void rna_def_particle_system(BlenderRNA *brna) srna= RNA_def_struct(brna, "ParticleSystem", NULL); RNA_def_struct_ui_text(srna, "Particle System", "Particle system in an object."); + RNA_def_struct_ui_icon(srna, ICON_PARTICLE_DATA); + + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_string_funcs(prop, "rna_ParticleSystem_name_get", "rna_ParticleSystem_name_length", NULL); + RNA_def_property_ui_text(prop, "Name", "Particle system name."); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_struct_name_property(srna, prop); prop= RNA_def_property(srna, "settings", PROP_POINTER, PROP_NEVER_NULL); RNA_def_property_pointer_sdna(prop, NULL, "part"); diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c index be97fd863f5..1d8a63bf83a 100644 --- a/source/blender/makesrna/intern/rna_texture.c +++ b/source/blender/makesrna/intern/rna_texture.c @@ -23,6 +23,7 @@ */ #include +#include #include #include "RNA_define.h" @@ -30,8 +31,11 @@ #include "rna_internal.h" +#include "DNA_brush_types.h" +#include "DNA_lamp_types.h" #include "DNA_material_types.h" #include "DNA_texture_types.h" +#include "DNA_world_types.h" #ifdef RNA_RUNTIME @@ -71,6 +75,50 @@ StructRNA *rna_Texture_refine(struct PointerRNA *ptr) } } +static int rna_texture_slot_index(PointerRNA *ptr) +{ + ID *id= ptr->id.data; + MTex **mtex; + int a; + + if(id) { + switch(GS(id->name)) { + case ID_MA: mtex= ((Material*)id)->mtex; break; + case ID_WO: mtex= ((World*)id)->mtex; break; + case ID_LA: mtex= ((Lamp*)id)->mtex; break; + case ID_BR: mtex= ((Brush*)id)->mtex; break; + default: return 0; + } + + for(a=0; adata) + return a; + } + + return 0; +} + +static int rna_TextureSlot_name_length(PointerRNA *ptr) +{ + MTex *mtex= ptr->data; + + if(mtex->tex) + return strlen(mtex->tex->id.name+2) + 10; + + return 10; +} + +static void rna_TextureSlot_name_get(PointerRNA *ptr, char *str) +{ + MTex *mtex= ptr->data; + int index= rna_texture_slot_index(ptr); + + sprintf(str, "%d: ", index+1); + + if(mtex->tex) + strcat(str, mtex->tex->id.name+2); +} + #else static void rna_def_color_ramp_element(BlenderRNA *brna) @@ -190,6 +238,12 @@ static void rna_def_mtex(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Texture", "Texture datablock used by this texture slot."); + prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); + RNA_def_property_string_funcs(prop, "rna_TextureSlot_name_get", "rna_TextureSlot_name_length", NULL); + RNA_def_property_ui_text(prop, "Name", "Texture slot name."); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_struct_name_property(srna, prop); + /* mapping */ prop= RNA_def_property(srna, "offset", PROP_FLOAT, PROP_VECTOR); RNA_def_property_float_sdna(prop, NULL, "ofs"); -- cgit v1.2.3