Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorswann <slumber>2020-01-17 21:14:23 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-01-17 21:14:51 +0300
commite280c0441bd84e73c47dffb66104ed40af9ea592 (patch)
tree912b3ce096ab25e1eb40c404ab94453e8d443463 /source/blender/makesrna/intern/rna_main_api.c
parentf185a9b97c45ae23f159f00e78ec3593d26e47b3 (diff)
Fix lightprobe creation from python data API
### Description of the problem Until now, it is only possible to correctly add a lightprobe in python via an operator: `bpy.ops.object.lightprobe_add()` ### Description of the proposed solution The idea of this patch is to fix the lack of consistency lightprobe creation without operator. It allow creation of different lightprobe type directly via `bpy.data.lightprobes.new(name, type)` (such as for curves). In order to make it possible I had to: 1. Add a function `BKE_lightprobe_configure` in charge of lightprobe settings configuration (avoid code redundancy) 2. Allow an object to take lightprobe datablock as data during is initialization. ### A short example of this patch usage ``` lp = bpy.data.lightprobes.new('some_name','PLANAR') bpy.data.objects.new('toto', lp) ``` Reviewed By: fclem Differential Revision: https://developer.blender.org/D6396
Diffstat (limited to 'source/blender/makesrna/intern/rna_main_api.c')
-rw-r--r--source/blender/makesrna/intern/rna_main_api.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index d85c5c5f249..cc11263ad5a 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -250,6 +250,9 @@ static Object *rna_Main_objects_new(Main *bmain, ReportList *reports, const char
case ID_AR:
type = OB_ARMATURE;
break;
+ case ID_LP:
+ type = OB_LIGHTPROBE;
+ break;
default: {
const char *idname;
if (RNA_enum_id_from_value(rna_enum_id_type_items, GS(data->name), &idname) == 0) {
@@ -665,12 +668,15 @@ static FreestyleLineStyle *rna_Main_linestyles_new(Main *bmain, const char *name
return linestyle;
}
-static LightProbe *rna_Main_lightprobe_new(Main *bmain, const char *name)
+static LightProbe *rna_Main_lightprobe_new(Main *bmain, const char *name, int type)
{
char safe_name[MAX_ID_NAME - 2];
rna_idname_validate(name, safe_name);
LightProbe *probe = BKE_lightprobe_add(bmain, safe_name);
+
+ BKE_lightprobe_configure(probe, type);
+
id_us_min(&probe->id);
return probe;
}
@@ -2079,6 +2085,9 @@ void RNA_def_main_lightprobes(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_function_ui_description(func, "Add a new probe to the main database");
parm = RNA_def_string(func, "name", "Probe", 0, "", "New name for the data-block");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_enum(
+ func, "type", rna_enum_lightprobes_type_items, 0, "Type", "The type of lightprobe to add");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
/* return type */
parm = RNA_def_pointer(func, "lightprobe", "LightProbe", "", "New light probe data-block");
RNA_def_function_return(func, parm);