diff options
author | swann <slumber> | 2020-01-17 21:14:23 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-01-17 21:14:51 +0300 |
commit | e280c0441bd84e73c47dffb66104ed40af9ea592 (patch) | |
tree | 912b3ce096ab25e1eb40c404ab94453e8d443463 /source/blender/blenkernel | |
parent | f185a9b97c45ae23f159f00e78ec3593d26e47b3 (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/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_lightprobe.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lightprobe.c | 24 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 2 |
3 files changed, 27 insertions, 0 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"); |