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
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
-rw-r--r--source/blender/blenkernel/BKE_lightprobe.h1
-rw-r--r--source/blender/blenkernel/intern/lightprobe.c24
-rw-r--r--source/blender/blenkernel/intern/object.c2
-rw-r--r--source/blender/editors/object/object_add.c21
-rw-r--r--source/blender/makesrna/RNA_enum_types.h2
-rw-r--r--source/blender/makesrna/intern/rna_main_api.c11
-rw-r--r--source/blender/makesrna/intern/rna_object.c8
7 files changed, 48 insertions, 21 deletions
diff --git a/source/blender/blenkernel/BKE_lightprobe.h b/source/blender/blenkernel/BKE_lightprobe.h
index bd442c97000..3d59929ada7 100644
--- a/source/blender/blenkernel/BKE_lightprobe.h
+++ b/source/blender/blenkernel/BKE_lightprobe.h
@@ -29,6 +29,7 @@ struct LightProbe;
struct Main;
void BKE_lightprobe_init(struct LightProbe *probe);
+void BKE_lightprobe_configure(struct LightProbe *probe, const short lightprobe_type);
void *BKE_lightprobe_add(struct Main *bmain, const char *name);
void BKE_lightprobe_copy_data(struct Main *bmain,
struct LightProbe *probe_dst,
diff --git a/source/blender/blenkernel/intern/lightprobe.c b/source/blender/blenkernel/intern/lightprobe.c
index 06f1ee5050b..3a9c1c8ae1d 100644
--- a/source/blender/blenkernel/intern/lightprobe.c
+++ b/source/blender/blenkernel/intern/lightprobe.c
@@ -41,6 +41,30 @@ void BKE_lightprobe_init(LightProbe *probe)
MEMCPY_STRUCT_AFTER(probe, DNA_struct_default_get(LightProbe), id);
}
+void BKE_lightprobe_configure(LightProbe *probe, const short lightprobe_type)
+{
+ probe->type = lightprobe_type;
+
+ switch (probe->type) {
+ case LIGHTPROBE_TYPE_GRID:
+ probe->distinf = 0.3f;
+ probe->falloff = 1.0f;
+ probe->clipsta = 0.01f;
+ break;
+ case LIGHTPROBE_TYPE_PLANAR:
+ probe->distinf = 0.1f;
+ probe->falloff = 0.5f;
+ probe->clipsta = 0.001f;
+ break;
+ case LIGHTPROBE_TYPE_CUBE:
+ probe->attenuation_type = LIGHTPROBE_SHAPE_ELIPSOID;
+ break;
+ default:
+ BLI_assert(!"LightProbe type not configured.");
+ break;
+ }
+}
+
void *BKE_lightprobe_add(Main *bmain, const char *name)
{
LightProbe *probe;
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 1378e862034..7f318ab634b 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -804,6 +804,8 @@ static const char *get_obdata_defname(int type)
return DATA_("Empty");
case OB_GPENCIL:
return DATA_("GPencil");
+ case OB_LIGHTPROBE:
+ return DATA_("LightProbe");
default:
CLOG_ERROR(&LOG, "Internal error, bad type: %d", type);
return DATA_("Empty");
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index 5286637afe2..3cd957596f8 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -603,27 +603,8 @@ static int lightprobe_add_exec(bContext *C, wmOperator *op)
copy_v3_fl(ob->scale, radius);
probe = (LightProbe *)ob->data;
- probe->type = type;
- switch (type) {
- case LIGHTPROBE_TYPE_GRID:
- probe->distinf = 0.3f;
- probe->falloff = 1.0f;
- probe->clipsta = 0.01f;
- break;
- case LIGHTPROBE_TYPE_PLANAR:
- probe->distinf = 0.1f;
- probe->falloff = 0.5f;
- probe->clipsta = 0.001f;
- ob->empty_drawsize = 0.5f;
- break;
- case LIGHTPROBE_TYPE_CUBE:
- probe->attenuation_type = LIGHTPROBE_SHAPE_ELIPSOID;
- break;
- default:
- BLI_assert(!"LightProbe type not configured.");
- break;
- }
+ BKE_lightprobe_configure(probe, type);
DEG_relations_tag_update(CTX_data_main(C));
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index d7f6ec1fb5a..5466f396730 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -141,6 +141,8 @@ extern const EnumPropertyItem rna_enum_texture_type_items[];
extern const EnumPropertyItem rna_enum_light_type_items[];
+extern const EnumPropertyItem rna_enum_lightprobes_type_items[];
+
extern const EnumPropertyItem rna_enum_unpack_method_items[];
extern const EnumPropertyItem rna_enum_object_type_items[];
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);
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 75594d1b295..a83a36fbd9d 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -25,6 +25,7 @@
#include "DNA_brush_types.h"
#include "DNA_collection_types.h"
#include "DNA_customdata_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_force_types.h"
@@ -196,6 +197,13 @@ const EnumPropertyItem rna_enum_metaelem_type_items[] = {
{0, NULL, 0, NULL, NULL},
};
+const EnumPropertyItem rna_enum_lightprobes_type_items[] = {
+ {LIGHTPROBE_TYPE_CUBE, "CUBE", ICON_LIGHTPROBE_CUBEMAP, "Cube", ""},
+ {LIGHTPROBE_TYPE_PLANAR, "PLANAR", ICON_LIGHTPROBE_PLANAR, "Planar", ""},
+ {LIGHTPROBE_TYPE_GRID, "GRID", ICON_LIGHTPROBE_GRID, "Grid", ""},
+ {0, NULL, 0, NULL, NULL},
+};
+
/* used for 2 enums */
#define OBTYPE_CU_CURVE \
{ \