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
This commit is contained in:
parent
f185a9b97c
commit
e280c0441b
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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[];
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 \
|
||||
{ \
|
||||
|
|
Loading…
Reference in New Issue