- move: material.add_texture(tex, coords, mapto) --> material.texture_slots.add()
- added material.texture_slots.create(index), material.texture_slots.clear(index)
- texture slot functions also work for lamp and world now.

Other minor changes
- allow rna functions to set FUNC_NO_SELF and FUNC_USE_SELF_ID at once.
- [#23317] Changed some operators' RNA to accept lengths, a modification I made to this patch made it not work as intended, removed this edit so unit buttons appier in the UI for certain operators.
- Sphinx doc gen, 2 columns rather then 3, didnt quite fit in some cases.
This commit is contained in:
Campbell Barton 2010-09-03 14:53:54 +00:00
parent 52cefa4bc1
commit 0cf0f5a622
11 changed files with 183 additions and 110 deletions

@ -183,7 +183,19 @@ def add_texture_to_material(image, texture, material, mapto):
if image:
texture.image = image
material.add_texture(texture, "UV", mapto)
mtex = material.texture_slots.add()
mtex.texture = texture
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = False
if mapto == 'COLOR':
mtex.use_map_color_diffuse = True
elif mapto == 'SPECULARITY':
mtex.use_map_specular = True
elif mapto == 'ALPHA':
mtex.use_map_alpha = True
elif mapto == 'NORMAL':
mtex.use_map_normal = True
def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):

@ -70,6 +70,7 @@ struct Tex *add_texture(const char *name);
void tex_set_type(struct Tex *tex, int type);
void default_mtex(struct MTex *mtex);
struct MTex *add_mtex(void);
struct MTex *add_mtex_id(struct ID *id, int slot);
struct Tex *copy_texture(struct Tex *tex);
void make_local_texture(struct Tex *tex);
void autotexname(struct Tex *tex);

@ -689,6 +689,49 @@ MTex *add_mtex()
return mtex;
}
/* slot -1 for first free ID */
MTex *add_mtex_id(ID *id, int slot)
{
MTex **mtex_ar;
short act;
give_active_mtex(id, &mtex_ar, &act);
if(mtex_ar==NULL) {
return NULL;
}
if(slot==-1) {
/* find first free */
int i;
for (i= 0; i < MAX_MTEX; i++) {
if (!mtex_ar[i]) {
slot= i;
break;
}
}
if(slot == -1) {
return NULL;
}
}
else {
/* make sure slot is valid */
if(slot < 0 || slot >= MAX_MTEX) {
return NULL;
}
}
if (mtex_ar[slot]) {
id_us_min((ID *)mtex_ar[slot]->tex);
MEM_freeN(mtex_ar[slot]);
mtex_ar[slot]= NULL;
}
mtex_ar[slot]= add_mtex();
return mtex_ar[slot];
}
/* ------------------------------------------------------------------------- */
Tex *copy_texture(Tex *tex)

@ -1413,10 +1413,12 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
fprintf(f, "\n{\n");
/* variable definitions */
if((func->flag & FUNC_NO_SELF)==0) {
if(func->flag & FUNC_USE_SELF_ID)
fprintf(f, "\tstruct ID *_selfid;\n");
if(func->flag & FUNC_USE_SELF_ID) {
fprintf(f, "\tstruct ID *_selfid;\n");
}
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);
}
@ -1455,10 +1457,11 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
fprintf(f, "\t\n");
/* assign self */
if(func->flag & FUNC_USE_SELF_ID) {
fprintf(f, "\t_selfid= (struct ID*)_ptr->id.data;\n");
}
if((func->flag & FUNC_NO_SELF)==0) {
if(func->flag & FUNC_USE_SELF_ID)
fprintf(f, "\t_selfid= (struct ID*)_ptr->id.data;\n");
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);
}
@ -1521,10 +1524,13 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
first= 1;
if((func->flag & FUNC_NO_SELF)==0) {
if(func->flag & FUNC_USE_SELF_ID)
fprintf(f, "_selfid, ");
if(func->flag & FUNC_USE_SELF_ID) {
fprintf(f, "_selfid");
first= 0;
}
if((func->flag & FUNC_NO_SELF)==0) {
if(!first) fprintf(f, ", ");
fprintf(f, "_self");
first= 0;
}
@ -1826,10 +1832,13 @@ static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA
first= 1;
/* self, context and reports parameters */
if(func->flag & FUNC_USE_SELF_ID) {
fprintf(f, "struct ID *_selfid");
first= 0;
}
if((func->flag & FUNC_NO_SELF)==0) {
if(func->flag & FUNC_USE_SELF_ID)
fprintf(f, "struct ID *_selfid, ");
if(!first) fprintf(f, ", ");
if(dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname);
else fprintf(f, "struct %s *_self", srna->identifier);
first= 0;

@ -2207,7 +2207,7 @@ PropertyRNA *RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *id
PropertyRNA *prop;
prop= RNA_def_float_vector(cont_, identifier, len, default_value, hardmin, hardmax, ui_name, ui_description, softmin, softmax);
prop->subtype = PROP_XYZ;
prop->subtype = PROP_XYZ_LENGTH;
return prop;
}

@ -182,7 +182,7 @@ void rna_def_animviz_common(struct StructRNA *srna);
void rna_def_motionpath_common(struct StructRNA *srna);
void rna_def_texmat_common(struct StructRNA *srna, const char *texspace_editable);
void rna_def_mtex_common(struct StructRNA *srna, const char *begin, const char *activeget, const char *activeset, const char *structname, const char *update);
void rna_def_mtex_common(struct BlenderRNA *brna, struct StructRNA *srna, const char *begin, const char *activeget, const char *activeset, const char *structname, const char *structname_slots, const char *update);
void rna_def_render_layer_common(struct StructRNA *srna, int scene);
void rna_ID_name_get(struct PointerRNA *ptr, char *value);
@ -352,6 +352,10 @@ PointerRNA rna_pointer_inherit_refine(struct PointerRNA *ptr, struct StructRNA *
int rna_parameter_size(struct PropertyRNA *parm);
int rna_parameter_size_alloc(struct PropertyRNA *parm);
// XXX, these should not need to be defined here~!
struct MTex *rna_mtex_texture_slots_add(struct ID *self, struct ReportList *reports);
struct MTex *rna_mtex_texture_slots_create(struct ID *self, struct ReportList *reports, int index);
void rna_mtex_texture_slots_clear(struct ID *self, struct ReportList *reports, int index);
#endif /* RNA_INTERNAL_H */

@ -386,8 +386,8 @@ static void rna_def_lamp(BlenderRNA *brna)
rna_def_animdata_common(srna);
/* textures */
rna_def_mtex_common(srna, "rna_Lamp_mtex_begin", "rna_Lamp_active_texture_get",
"rna_Lamp_active_texture_set", "LampTextureSlot", "rna_Lamp_update");
rna_def_mtex_common(brna, srna, "rna_Lamp_mtex_begin", "rna_Lamp_active_texture_get",
"rna_Lamp_active_texture_set", "LampTextureSlot", "LampTextureSlots", "rna_Lamp_update");
}
static void rna_def_lamp_falloff(StructRNA *srna)

@ -276,6 +276,54 @@ static EnumPropertyItem *rna_Material_texture_coordinates_itemf(bContext *C, Poi
return item;
}
MTex *rna_mtex_texture_slots_add(ID *self_id, ReportList *reports)
{
MTex *mtex= add_mtex_id(self_id, -1);
if (mtex == NULL) {
BKE_reportf(reports, RPT_ERROR, "maximum number of textures added %d", MAX_MTEX);
return NULL;
}
return mtex;
}
MTex *rna_mtex_texture_slots_create(ID *self_id, ReportList *reports, int index)
{
MTex *mtex;
if(index < 0 || index >= MAX_MTEX) {
BKE_reportf(reports, RPT_ERROR, "index %d is invalid", index);
return NULL;
}
mtex= add_mtex_id(self_id, index);
return mtex;
}
void rna_mtex_texture_slots_clear(ID *self_id, ReportList *reports, int index)
{
MTex **mtex_ar;
short act;
give_active_mtex(self_id, &mtex_ar, &act);
if (mtex_ar == NULL) {
BKE_report(reports, RPT_ERROR, "mtex not found for this type");
return;
}
if(index < 0 || index >= MAX_MTEX) {
BKE_reportf(reports, RPT_ERROR, "index %d is invalid", index);
return;
}
if(mtex_ar[index]) {
id_us_min((ID *)mtex_ar[index]->tex);
MEM_freeN(mtex_ar[index]);
mtex_ar[index]= NULL;
}
}
#else
@ -1741,9 +1789,9 @@ void RNA_def_material(BlenderRNA *brna)
/* common */
rna_def_animdata_common(srna);
rna_def_mtex_common(srna, "rna_Material_mtex_begin", "rna_Material_active_texture_get",
"rna_Material_active_texture_set", "MaterialTextureSlot", "rna_Material_update");
rna_def_mtex_common(brna, srna, "rna_Material_mtex_begin", "rna_Material_active_texture_get",
"rna_Material_active_texture_set", "MaterialTextureSlot", "MaterialTextureSlots", "rna_Material_update");
/* only material has this one */
prop= RNA_def_property(srna, "use_textures", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "septex", 1);
@ -1768,7 +1816,43 @@ void RNA_def_material(BlenderRNA *brna)
RNA_api_material(srna);
}
void rna_def_mtex_common(StructRNA *srna, const char *begin, const char *activeget, const char *activeset, const char *structname, const char *update)
/* curve.splines */
static void rna_def_texture_slots(BlenderRNA *brna, PropertyRNA *cprop, const char *structname, const char *structname_slots)
{
StructRNA *srna;
FunctionRNA *func;
PropertyRNA *parm;
RNA_def_property_srna(cprop, structname_slots);
srna= RNA_def_struct(brna, structname_slots, NULL);
RNA_def_struct_sdna(srna, "ID");
RNA_def_struct_ui_text(srna, "Texture Slots", "Collection of texture slots");
/* functions */
func= RNA_def_function(srna, "add", "rna_mtex_texture_slots_add");
RNA_def_function_ui_description(func, "Add a number of points to this spline.");
RNA_def_function_flag(func, FUNC_USE_SELF_ID|FUNC_NO_SELF|FUNC_USE_REPORTS);
parm= RNA_def_pointer(func, "mtex", structname, "", "The newly initialized mtex.");
RNA_def_function_return(func, parm);
func= RNA_def_function(srna, "create", "rna_mtex_texture_slots_create");
RNA_def_function_ui_description(func, "Add a number of points to this spline.");
RNA_def_function_flag(func, FUNC_USE_SELF_ID|FUNC_NO_SELF|FUNC_USE_REPORTS);
parm= RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Slot index to initialize.", 0, INT_MAX);
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_pointer(func, "mtex", structname, "", "The newly initialized mtex.");
RNA_def_function_return(func, parm);
func= RNA_def_function(srna, "clear", "rna_mtex_texture_slots_clear");
RNA_def_function_ui_description(func, "Add a number of points to this spline.");
RNA_def_function_flag(func, FUNC_USE_SELF_ID|FUNC_NO_SELF|FUNC_USE_REPORTS);
parm= RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Slot index to clar.", 0, INT_MAX);
RNA_def_property_flag(parm, PROP_REQUIRED);
}
void rna_def_mtex_common(BlenderRNA *brna, StructRNA *srna, const char *begin, const char *activeget, const char *activeset, const char *structname, const char *structname_slots, const char *update)
{
PropertyRNA *prop;
@ -1777,6 +1861,7 @@ void rna_def_mtex_common(StructRNA *srna, const char *begin, const char *activeg
RNA_def_property_struct_type(prop, structname);
RNA_def_property_collection_funcs(prop, begin, "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_dereference_get", 0, 0, 0);
RNA_def_property_ui_text(prop, "Textures", "Texture slots defining the mapping and influence of textures");
rna_def_texture_slots(brna, prop, structname, structname_slots);
prop= RNA_def_property(srna, "active_texture", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Texture");

@ -35,93 +35,12 @@
#ifdef RNA_RUNTIME
#include "BKE_material.h"
#include "BKE_texture.h"
/*
Adds material to the first free texture slot.
If all slots are busy, replaces the first.
*/
static void rna_Material_add_texture(Material *ma, Tex *tex, int texco, int mapto)
{
int i;
MTex *mtex;
int slot= -1;
for (i= 0; i < MAX_MTEX; i++) {
if (!ma->mtex[i]) {
slot= i;
break;
}
}
if (slot == -1)
slot= 0;
if (ma->mtex[slot]) {
ma->mtex[slot]->tex->id.us--;
}
else {
ma->mtex[slot]= add_mtex();
}
mtex= ma->mtex[slot];
mtex->tex= tex;
if (tex)
id_us_plus(&tex->id);
mtex->texco= texco;
mtex->mapto= mapto;
}
#else
void RNA_api_material(StructRNA *srna)
{
FunctionRNA *func;
PropertyRNA *parm;
/* copied from rna_def_material_mtex (rna_material.c) */
static EnumPropertyItem prop_texture_coordinates_items[] = {
{TEXCO_GLOB, "GLOBAL", 0, "Global", "Uses global coordinates for the texture coordinates"},
{TEXCO_OBJECT, "OBJECT", 0, "Object", "Uses linked object's coordinates for texture coordinates"},
{TEXCO_UV, "UV", 0, "UV", "Uses UV coordinates for texture coordinates"},
{TEXCO_ORCO, "ORCO", 0, "Generated", "Uses the original undeformed coordinates of the object"},
{TEXCO_STRAND, "STRAND", 0, "Strand", "Uses normalized strand texture coordinate (1D)"},
{TEXCO_STICKY, "STICKY", 0, "Sticky", "Uses mesh's sticky coordinates for the texture coordinates"},
{TEXCO_WINDOW, "WINDOW", 0, "Window", "Uses screen coordinates as texture coordinates"},
{TEXCO_NORM, "NORMAL", 0, "Normal", "Uses normal vector as texture coordinates"},
{TEXCO_REFL, "REFLECTION", 0, "Reflection", "Uses reflection vector as texture coordinates"},
{TEXCO_STRESS, "STRESS", 0, "Stress", "Uses the difference of edge lengths compared to original coordinates of the mesh"},
{TEXCO_TANGENT, "TANGENT", 0, "Tangent", "Uses the optional tangent vector as texture coordinates"},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem prop_texture_mapto_items[] = {
{MAP_COL, "COLOR", 0, "Color", "Causes the texture to affect basic color of the material"},
{MAP_NORM, "NORMAL", 0, "Normal", "Causes the texture to affect the rendered normal"},
{MAP_COLSPEC, "SPECULAR_COLOR", 0, "Specularity Color", "Causes the texture to affect the specularity color"},
{MAP_COLMIR, "MIRROR", 0, "Mirror", "Causes the texture to affect the mirror color"},
{MAP_REF, "REFLECTION", 0, "Reflection", "Causes the texture to affect the value of the materials reflectivity"},
{MAP_SPEC, "SPECULARITY", 0, "Specularity", "Causes the texture to affect the value of specularity"},
{MAP_EMIT, "EMIT", 0, "Emit", "Causes the texture to affect the emit value"},
{MAP_ALPHA, "ALPHA", 0, "Alpha", "Causes the texture to affect the alpha value"},
{MAP_HAR, "HARDNESS", 0, "Hardness", "Causes the texture to affect the hardness value"},
{MAP_RAYMIRR, "RAY_MIRROR", 0, "Ray-Mirror", "Causes the texture to affect the ray-mirror value"},
{MAP_TRANSLU, "TRANSLUCENCY", 0, "Translucency", "Causes the texture to affect the translucency value"},
{MAP_AMB, "AMBIENT", 0, "Ambient", "Causes the texture to affect the value of ambient"},
{MAP_DISPLACE, "DISPLACEMENT", 0, "Displacement", "Let the texture displace the surface"},
{MAP_WARP, "WARP", 0, "Warp", "Let the texture warp texture coordinates of next channels"},
{0, NULL, 0, NULL, NULL}};
func= RNA_def_function(srna, "add_texture", "rna_Material_add_texture");
RNA_def_function_ui_description(func, "Add a texture to material's free texture slot.");
parm= RNA_def_pointer(func, "texture", "Texture", "Texture", "Texture to add.");
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_enum(func, "texture_coords", prop_texture_coordinates_items, TEXCO_UV, "", "Source of texture coordinate information."); /* optional */
parm= RNA_def_enum(func, "map_to", prop_texture_mapto_items, MAP_COL, "", "Controls which material property the texture affects."); /* optional */
RNA_def_property_flag(parm, PROP_ENUM_FLAG);
// FunctionRNA *func;
// PropertyRNA *parm;
}
#endif

@ -469,8 +469,8 @@ void RNA_def_world(BlenderRNA *brna)
RNA_def_struct_ui_icon(srna, ICON_WORLD_DATA);
rna_def_animdata_common(srna);
rna_def_mtex_common(srna, "rna_World_mtex_begin", "rna_World_active_texture_get",
"rna_World_active_texture_set", "WorldTextureSlot", "rna_World_update");
rna_def_mtex_common(brna, srna, "rna_World_mtex_begin", "rna_World_active_texture_get",
"rna_World_active_texture_set", "WorldTextureSlot", "WorldTextureSlots", "rna_World_update");
/* colors */
prop= RNA_def_property(srna, "horizon_color", PROP_FLOAT, PROP_COLOR);

@ -443,7 +443,7 @@ def rna2sphinx(BASEPATH):
fw("\n")
fw(" Access to blenders internal data\n")
fw("\n")
fw(" :type: :class:`bpy.types.Main`\n")
fw(" :type: :class:`bpy.types.BlendData`\n")
file.close()
EXAMPLE_SET_USED.add("bpy.data")
@ -655,7 +655,7 @@ def rna2sphinx(BASEPATH):
fw(".. rubric:: Inherited Properties\n\n")
fw(".. hlist::\n")
fw(" :columns: 3\n\n")
fw(" :columns: 2\n\n")
for line in lines:
fw(line)
@ -680,7 +680,7 @@ def rna2sphinx(BASEPATH):
fw(".. rubric:: Inherited Functions\n\n")
fw(".. hlist::\n")
fw(" :columns: 3\n\n")
fw(" :columns: 2\n\n")
for line in lines:
fw(line)
@ -694,7 +694,7 @@ def rna2sphinx(BASEPATH):
fw(".. rubric:: References\n\n")
fw(".. hlist::\n")
fw(" :columns: 3\n\n")
fw(" :columns: 2\n\n")
for ref in struct.references:
ref_split = ref.split(".")