From 35e68e97850b00e75a1488a59e7e9b85d240c37f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 11 Jan 2011 02:30:01 +0000 Subject: - bpy.data.lamps.new() now takes a type argument since lamp type also sets class type this avoids needing to use ugly lamp.type_recast() after changing type. - default vertex color layer name was UTTex when added from python. --- release/scripts/op/io_scene_3ds/import_3ds.py | 9 +++------ release/scripts/templates/background_job.py | 2 +- source/blender/makesrna/RNA_enum_types.h | 2 ++ source/blender/makesrna/intern/rna_lamp.c | 18 +++++++++--------- source/blender/makesrna/intern/rna_main_api.c | 5 ++++- source/blender/makesrna/intern/rna_mesh.c | 2 +- source/blender/python/intern/bpy_rna.c | 6 ++---- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/release/scripts/op/io_scene_3ds/import_3ds.py b/release/scripts/op/io_scene_3ds/import_3ds.py index 7ffdcd3c853..26093078335 100644 --- a/release/scripts/op/io_scene_3ds/import_3ds.py +++ b/release/scripts/op/io_scene_3ds/import_3ds.py @@ -529,13 +529,10 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): new_chunk.bytes_read += STRUCT_SIZE_3FLOAT # no lamp in dict that would be confusing - ob = bpy.data.objects.new("Lamp", bpy.data.lamps.new("Lamp")) - SCN.objects.link(ob) + contextLamp[1] = bpy.data.lamps.new("Lamp", 'POINT') + contextLamp[0] = ob = bpy.data.objects.new("Lamp", contextLamp[1]) - contextLamp[1]= ob.data -# contextLamp[1]= bpy.data.lamps.new() - contextLamp[0]= ob -# contextLamp[0]= SCN_OBJECTS.new(contextLamp[1]) + SCN.objects.link(ob) importedObjects.append(contextLamp[0]) #print 'number of faces: ', num_faces diff --git a/release/scripts/templates/background_job.py b/release/scripts/templates/background_job.py index 5705e8ef53e..bf29de63830 100644 --- a/release/scripts/templates/background_job.py +++ b/release/scripts/templates/background_job.py @@ -34,7 +34,7 @@ def example_function(body_text, save_path, render_path): cam_ob.location = 0.0, 0.0, 10.0 # Lamp - lamp_data = bpy.data.lamps.new("MyLamp") + lamp_data = bpy.data.lamps.new("MyLamp", 'POINT') lamp_ob = bpy.data.objects.new(name="MyCam", object_data=lamp_data) scene.objects.link(lamp_ob) lamp_ob.location = 2.0, 2.0, 5.0 diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index 8e5463d5990..0f98296e6f7 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -75,6 +75,8 @@ extern EnumPropertyItem brush_imagepaint_tool_items[]; extern EnumPropertyItem texture_type_items[]; +extern EnumPropertyItem lamp_type_items[]; + extern EnumPropertyItem unpack_method_items[]; extern EnumPropertyItem object_type_items[]; diff --git a/source/blender/makesrna/intern/rna_lamp.c b/source/blender/makesrna/intern/rna_lamp.c index 68ff80f83dc..f2dc0decf29 100644 --- a/source/blender/makesrna/intern/rna_lamp.c +++ b/source/blender/makesrna/intern/rna_lamp.c @@ -144,6 +144,14 @@ static void rna_Lamp_spot_size_set(PointerRNA *ptr, float value) #else +EnumPropertyItem lamp_type_items[] = { + {LA_LOCAL, "POINT", 0, "Point", "Omnidirectional point light source"}, + {LA_SUN, "SUN", 0, "Sun", "Constant direction parallel ray light source"}, + {LA_SPOT, "SPOT", 0, "Spot", "Directional cone light source"}, + {LA_HEMI, "HEMI", 0, "Hemi", "180 degree constant light source"}, + {LA_AREA, "AREA", 0, "Area", "Directional area light source"}, + {0, NULL, 0, NULL, NULL}}; + static void rna_def_lamp_mtex(BlenderRNA *brna) { StructRNA *srna; @@ -326,21 +334,13 @@ static void rna_def_lamp(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; - static EnumPropertyItem prop_type_items[] = { - {LA_LOCAL, "POINT", 0, "Point", "Omnidirectional point light source"}, - {LA_SUN, "SUN", 0, "Sun", "Constant direction parallel ray light source"}, - {LA_SPOT, "SPOT", 0, "Spot", "Directional cone light source"}, - {LA_HEMI, "HEMI", 0, "Hemi", "180 degree constant light source"}, - {LA_AREA, "AREA", 0, "Area", "Directional area light source"}, - {0, NULL, 0, NULL, NULL}}; - srna= RNA_def_struct(brna, "Lamp", "ID"); RNA_def_struct_refine_func(srna, "rna_Lamp_refine"); RNA_def_struct_ui_text(srna, "Lamp", "Lamp datablock for lighting a scene"); RNA_def_struct_ui_icon(srna, ICON_LAMP_DATA); prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_items(prop, prop_type_items); + RNA_def_property_enum_items(prop, lamp_type_items); RNA_def_property_ui_text(prop, "Type", "Type of Lamp"); RNA_def_property_update(prop, 0, "rna_Lamp_draw_update"); diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 20d76b4f386..797baf07605 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -236,9 +236,10 @@ void rna_Main_meshes_remove(Main *bmain, ReportList *reports, Mesh *mesh) /* XXX python now has invalid pointer? */ } -Lamp *rna_Main_lamps_new(Main *bmain, const char *name) +Lamp *rna_Main_lamps_new(Main *bmain, const char *name, int type) { Lamp *lamp= add_lamp(name); + lamp->type= type; id_us_min(&lamp->id); return lamp; } @@ -716,6 +717,8 @@ void RNA_def_main_lamps(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_ui_description(func, "Add a new lamp to the main database"); parm= RNA_def_string(func, "name", "Lamp", 0, "", "New name for the datablock."); RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_enum(func, "type", lamp_type_items, 0, "Type", "The type of texture to add"); + RNA_def_property_flag(parm, PROP_REQUIRED); /* return type */ parm= RNA_def_pointer(func, "lamp", "Lamp", "", "New lamp datablock."); RNA_def_function_return(func, parm); diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 846c612fc97..6490e4e1dfb 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -1727,7 +1727,7 @@ static void rna_def_vertex_colors(BlenderRNA *brna, PropertyRNA *cprop) func= RNA_def_function(srna, "new", "rna_Mesh_vertex_color_new"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); RNA_def_function_ui_description(func, "Add a vertex color layer to Mesh."); - RNA_def_string(func, "name", "UVTex", 0, "", "UV Texture name."); + RNA_def_string(func, "name", "Col", 0, "", "Vertex color name."); parm= RNA_def_pointer(func, "layer", "MeshColorLayer", "", "The newly created layer."); RNA_def_function_return(func, parm); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 10b029084c8..d248499656a 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1312,12 +1312,10 @@ static PyObject * pyrna_prop_array_to_py_index(BPy_PropertyArrayRNA *self, int i static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, PyObject *value) { int ret = 0; - int totdim; PointerRNA *ptr= &self->ptr; PropertyRNA *prop= self->prop; - int type = RNA_property_type(prop); - totdim= RNA_property_array_dimension(ptr, prop, NULL); + const int totdim= RNA_property_array_dimension(ptr, prop, NULL); if (totdim > 1) { /* char error_str[512]; */ @@ -1328,7 +1326,7 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P } else { /* see if we can coorce into a python type - PropertyType */ - switch (type) { + switch (RNA_property_type(prop)) { case PROP_BOOLEAN: { int param = PyLong_AsLong( value ); -- cgit v1.2.3