T55406: Flip Matcap
- Icon represent the flipped matcap in the shading menu - Added template_icon to display any icon in scale.
This commit is contained in:
parent
fecec7dd68
commit
17b029d80e
|
@ -1609,7 +1609,7 @@ class StudioLightPanelMixin():
|
|||
box = layout.box()
|
||||
row = box.row()
|
||||
|
||||
row.template_icon_view(studio_light, "icon_id")
|
||||
row.template_icon(layout.icon(studio_light), scale=6.0)
|
||||
op = row.operator('wm.studiolight_uninstall', text="", icon='ZOOMOUT')
|
||||
op.index = studio_light.index
|
||||
|
||||
|
|
|
@ -51,8 +51,11 @@
|
|||
#define STUDIOLIGHT_Y_NEG 3
|
||||
#define STUDIOLIGHT_Z_POS 4
|
||||
#define STUDIOLIGHT_Z_NEG 5
|
||||
#define STUDIOLIGHT_ICON_ID_TYPE_RADIANCE 0
|
||||
#define STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE 1
|
||||
|
||||
#define STUDIOLIGHT_ICON_ID_TYPE_RADIANCE 0
|
||||
#define STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE 1
|
||||
#define STUDIOLIGHT_ICON_ID_TYPE_MATCAP 2
|
||||
#define STUDIOLIGHT_ICON_ID_TYPE_MATCAP_FLIPPED 3
|
||||
|
||||
struct GPUTexture;
|
||||
|
||||
|
@ -83,8 +86,10 @@ typedef struct StudioLight {
|
|||
char name[FILE_MAXFILE];
|
||||
char path[FILE_MAX];
|
||||
char *path_irr;
|
||||
int irradiance_icon_id;
|
||||
int radiance_icon_id;
|
||||
int icon_id_irradiance;
|
||||
int icon_id_radiance;
|
||||
int icon_id_matcap;
|
||||
int icon_id_matcap_flipped;
|
||||
int index;
|
||||
float diffuse_light[6][3];
|
||||
float light_direction[3];
|
||||
|
|
|
@ -99,16 +99,23 @@ static void studiolight_free(struct StudioLight *sl)
|
|||
MEM_freeN(sl);
|
||||
}
|
||||
|
||||
static struct StudioLight *studiolight_create(void)
|
||||
static struct StudioLight *studiolight_create(int flag)
|
||||
{
|
||||
struct StudioLight *sl = MEM_callocN(sizeof(*sl), __func__);
|
||||
sl->path[0] = 0x00;
|
||||
sl->name[0] = 0x00;
|
||||
sl->path_irr = NULL;
|
||||
sl->flag = 0;
|
||||
sl->flag = flag;
|
||||
sl->index = BLI_listbase_count(&studiolights);
|
||||
sl->radiance_icon_id = BKE_icon_ensure_studio_light(sl, STUDIOLIGHT_ICON_ID_TYPE_RADIANCE);
|
||||
sl->irradiance_icon_id = BKE_icon_ensure_studio_light(sl, STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE);
|
||||
if (flag & STUDIOLIGHT_ORIENTATION_VIEWNORMAL)
|
||||
{
|
||||
sl->icon_id_matcap = BKE_icon_ensure_studio_light(sl, STUDIOLIGHT_ICON_ID_TYPE_MATCAP);
|
||||
sl->icon_id_matcap_flipped = BKE_icon_ensure_studio_light(sl, STUDIOLIGHT_ICON_ID_TYPE_MATCAP_FLIPPED);
|
||||
}
|
||||
else {
|
||||
sl->icon_id_radiance = BKE_icon_ensure_studio_light(sl, STUDIOLIGHT_ICON_ID_TYPE_RADIANCE);
|
||||
sl->icon_id_irradiance = BKE_icon_ensure_studio_light(sl, STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE);
|
||||
}
|
||||
|
||||
for (int index = 0 ; index < 6 ; index ++) {
|
||||
sl->radiance_cubemap_buffers[index] = NULL;
|
||||
|
@ -522,8 +529,7 @@ static void studiolight_add_files_from_datafolder(const int folder_id, const cha
|
|||
const char *filename = dir[i].relname;
|
||||
const char *path = dir[i].path;
|
||||
if (BLI_testextensie_array(filename, imb_ext_image)) {
|
||||
sl = studiolight_create();
|
||||
sl->flag = STUDIOLIGHT_EXTERNAL_FILE | flag;
|
||||
sl = studiolight_create(STUDIOLIGHT_EXTERNAL_FILE | flag);
|
||||
BLI_strncpy(sl->name, filename, FILE_MAXFILE);
|
||||
BLI_strncpy(sl->path, path, FILE_MAXFILE);
|
||||
sl->path_irr = BLI_string_joinN(path, ".irr");
|
||||
|
@ -620,7 +626,7 @@ static uint *studiolight_radiance_preview(StudioLight *sl, int icon_size)
|
|||
return rect;
|
||||
}
|
||||
|
||||
static uint *studiolight_matcap_preview(StudioLight *sl, int icon_size)
|
||||
static uint *studiolight_matcap_preview(StudioLight *sl, int icon_size, bool flipped)
|
||||
{
|
||||
BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EXTERNAL_IMAGE_LOADED);
|
||||
|
||||
|
@ -630,10 +636,17 @@ static uint *studiolight_matcap_preview(StudioLight *sl, int icon_size)
|
|||
float fx, fy;
|
||||
int offset = 0;
|
||||
ImBuf *ibuf = sl->equirectangular_radiance_buffer;
|
||||
|
||||
for (int y = 0; y < icon_size; y++) {
|
||||
fy = y * ibuf->y / icon_size;
|
||||
for (int x = 0; x < icon_size; x++) {
|
||||
fx = x * ibuf->x / icon_size;
|
||||
fy = y * ibuf->y / icon_size;
|
||||
if (flipped)
|
||||
{
|
||||
fx = ibuf->x - (x * ibuf->x / icon_size) - 1;
|
||||
}
|
||||
else {
|
||||
fx = x * ibuf->x / icon_size;
|
||||
}
|
||||
nearest_interpolation_color(ibuf, NULL, color, fx, fy);
|
||||
rect[offset++] = rgb_to_cpack(linearrgb_to_srgb(color[0]),
|
||||
linearrgb_to_srgb(color[1]),
|
||||
|
@ -763,9 +776,8 @@ void BKE_studiolight_init(void)
|
|||
/* order studio lights by name */
|
||||
/* Also reserve icon space for it. */
|
||||
/* Add default studio light */
|
||||
sl = studiolight_create();
|
||||
sl = studiolight_create(STUDIOLIGHT_INTERNAL | STUDIOLIGHT_DIFFUSE_LIGHT_CALCULATED | STUDIOLIGHT_ORIENTATION_CAMERA);
|
||||
BLI_strncpy(sl->name, "INTERNAL_01", FILE_MAXFILE);
|
||||
sl->flag = STUDIOLIGHT_INTERNAL | STUDIOLIGHT_DIFFUSE_LIGHT_CALCULATED | STUDIOLIGHT_ORIENTATION_CAMERA;
|
||||
copy_v3_fl(sl->diffuse_light[STUDIOLIGHT_X_POS], 1.5f);
|
||||
copy_v3_fl(sl->diffuse_light[STUDIOLIGHT_X_NEG], 0.0f);
|
||||
copy_v3_fl(sl->diffuse_light[STUDIOLIGHT_Y_POS], 0.8f);
|
||||
|
@ -838,16 +850,17 @@ struct ListBase *BKE_studiolight_listbase(void)
|
|||
|
||||
uint *BKE_studiolight_preview(StudioLight *sl, int icon_size, int icon_id_type)
|
||||
{
|
||||
if (icon_id_type == STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE) {
|
||||
if (sl->flag & STUDIOLIGHT_ORIENTATION_VIEWNORMAL) {
|
||||
return studiolight_matcap_preview(sl, icon_size);
|
||||
}
|
||||
else {
|
||||
switch(icon_id_type)
|
||||
{
|
||||
case STUDIOLIGHT_ICON_ID_TYPE_RADIANCE:
|
||||
default:
|
||||
return studiolight_radiance_preview(sl, icon_size);
|
||||
case STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE:
|
||||
return studiolight_irradiance_preview(sl, icon_size);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return studiolight_radiance_preview(sl, icon_size);
|
||||
case STUDIOLIGHT_ICON_ID_TYPE_MATCAP:
|
||||
return studiolight_matcap_preview(sl, icon_size, false);
|
||||
case STUDIOLIGHT_ICON_ID_TYPE_MATCAP_FLIPPED:
|
||||
return studiolight_matcap_preview(sl, icon_size, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1031,6 +1031,7 @@ uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
|
|||
void uiTemplatePreview(uiLayout *layout, struct bContext *C, struct ID *id, int show_buttons, struct ID *parent,
|
||||
struct MTex *slot, const char *preview_id);
|
||||
void uiTemplateColorRamp(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int expand);
|
||||
void uiTemplateIcon(uiLayout *layout, int icon_value, float icon_scale);
|
||||
void uiTemplateIconView(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int show_labels, float icon_scale);
|
||||
void uiTemplateHistogram(uiLayout *layout, struct PointerRNA *ptr, const char *propname);
|
||||
void uiTemplateWaveform(uiLayout *layout, struct PointerRNA *ptr, const char *propname);
|
||||
|
|
|
@ -1444,6 +1444,19 @@ int UI_rnaptr_icon_get(bContext *C, PointerRNA *ptr, int rnaicon, const bool big
|
|||
else if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ)
|
||||
return ICON_FILE_IMAGE;
|
||||
}
|
||||
else if (RNA_struct_is_a(ptr->type, &RNA_StudioLight)) {
|
||||
StudioLight *sl = (StudioLight *)ptr->data;
|
||||
switch (sl->flag & STUDIOLIGHT_FLAG_ORIENTATIONS)
|
||||
{
|
||||
case STUDIOLIGHT_ORIENTATION_CAMERA:
|
||||
return sl->icon_id_irradiance;
|
||||
case STUDIOLIGHT_ORIENTATION_WORLD:
|
||||
default:
|
||||
return sl->icon_id_radiance;
|
||||
case STUDIOLIGHT_ORIENTATION_VIEWNORMAL:
|
||||
return sl->icon_id_matcap;
|
||||
}
|
||||
}
|
||||
|
||||
/* get icon from ID */
|
||||
if (id) {
|
||||
|
|
|
@ -2185,6 +2185,19 @@ void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname
|
|||
MEM_freeN(cb);
|
||||
}
|
||||
|
||||
/********************* Icon Template ************************/
|
||||
/**
|
||||
* \param icon_scale: Scale of the icon, 1x == button height.
|
||||
*/
|
||||
void uiTemplateIcon(uiLayout *layout, int icon_value, float icon_scale)
|
||||
{
|
||||
uiBlock *block;
|
||||
uiBut *but;
|
||||
|
||||
block = uiLayoutAbsoluteBlock(layout);
|
||||
but = uiDefIconBut(block, UI_BTYPE_LABEL, 0, ICON_X, 0, 0, UI_UNIT_X * icon_scale, UI_UNIT_Y * icon_scale, NULL, 0.0, 0.0, 0.0, 0.0, "");
|
||||
ui_def_but_icon(but, icon_value, UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
|
||||
}
|
||||
|
||||
/********************* Icon viewer Template ************************/
|
||||
typedef struct IconViewMenuArgs {
|
||||
|
|
|
@ -594,6 +594,7 @@ extern StructRNA RNA_StretchToConstraint;
|
|||
extern StructRNA RNA_StringProperty;
|
||||
extern StructRNA RNA_Struct;
|
||||
extern StructRNA RNA_StucciTexture;
|
||||
extern StructRNA RNA_StudioLight;
|
||||
extern StructRNA RNA_SubsurfModifier;
|
||||
extern StructRNA RNA_SunLamp;
|
||||
extern StructRNA RNA_SurfaceCurve;
|
||||
|
|
|
@ -763,7 +763,7 @@ static const EnumPropertyItem *rna_View3DShading_studio_light_itemf(
|
|||
const int flags = (STUDIOLIGHT_EXTERNAL_FILE | STUDIOLIGHT_ORIENTATION_VIEWNORMAL);
|
||||
|
||||
LISTBASE_FOREACH(StudioLight *, sl, BKE_studiolight_listbase()) {
|
||||
int icon_id = sl->irradiance_icon_id;
|
||||
int icon_id = (v3d->shading.flag & V3D_SHADING_MATCAP_FLIP_X) ? sl->icon_id_matcap_flipped: sl->icon_id_matcap;
|
||||
if ((sl->flag & flags) == flags) {
|
||||
EnumPropertyItem tmp = {sl->index, sl->name, icon_id, sl->name, ""};
|
||||
RNA_enum_item_add(&item, &totitem, &tmp);
|
||||
|
@ -772,7 +772,7 @@ static const EnumPropertyItem *rna_View3DShading_studio_light_itemf(
|
|||
}
|
||||
else {
|
||||
LISTBASE_FOREACH(StudioLight *, sl, BKE_studiolight_listbase()) {
|
||||
int icon_id = sl->irradiance_icon_id;
|
||||
int icon_id = sl->icon_id_irradiance;
|
||||
bool show_studiolight = false;
|
||||
|
||||
if ((sl->flag & STUDIOLIGHT_INTERNAL)) {
|
||||
|
@ -788,7 +788,7 @@ static const EnumPropertyItem *rna_View3DShading_studio_light_itemf(
|
|||
|
||||
case OB_MATERIAL:
|
||||
show_studiolight = (sl->flag & STUDIOLIGHT_ORIENTATION_WORLD) > 0;
|
||||
icon_id = sl->radiance_icon_id;
|
||||
icon_id = sl->icon_id_radiance;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -869,6 +869,12 @@ void RNA_api_ui_layout(StructRNA *srna)
|
|||
api_ui_item_rna_common(func);
|
||||
RNA_def_boolean(func, "expand", false, "", "Expand button to show more detail");
|
||||
|
||||
func = RNA_def_function(srna, "template_icon", "uiTemplateIcon");
|
||||
RNA_def_function_ui_description(func, "Display a large icon");
|
||||
parm = RNA_def_int(func, "icon_value", 0, 0, INT_MAX, "Icon to display", "", 0, INT_MAX);
|
||||
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
|
||||
RNA_def_float(func, "scale", 1.0f, 1.0f, 100.0f, "Scale", "Scale the icon size (by the button size)", 1.0f, 100.0f);
|
||||
|
||||
func = RNA_def_function(srna, "template_icon_view", "uiTemplateIconView");
|
||||
RNA_def_function_ui_description(func, "Enum. Large widget showing Icon previews");
|
||||
api_ui_item_rna_common(func);
|
||||
|
|
|
@ -78,11 +78,6 @@ const EnumPropertyItem rna_enum_navigation_mode_items[] = {
|
|||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
static const EnumPropertyItem rna_enum_studio_light_icons_id_items[] = {
|
||||
{0, "DEFAULT", 0, "Default", ""},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
#if defined(WITH_INTERNATIONAL) || !defined(RNA_RUNTIME)
|
||||
static const EnumPropertyItem rna_enum_language_default_items[] = {
|
||||
|
@ -704,38 +699,6 @@ static int rna_UserDef_studiolight_index_get(PointerRNA *ptr)
|
|||
return sl->index;
|
||||
}
|
||||
|
||||
/* StudioLight.icon_id */
|
||||
static int rna_UserDef_studiolight_icon_id_get(PointerRNA *ptr)
|
||||
{
|
||||
StudioLight *sl = (StudioLight *)ptr->data;
|
||||
if (sl->flag & (STUDIOLIGHT_ORIENTATION_VIEWNORMAL | STUDIOLIGHT_ORIENTATION_CAMERA)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const EnumPropertyItem *rna_UserDef_studiolight_icon_id_itemf(
|
||||
bContext *UNUSED(C), PointerRNA *ptr,
|
||||
PropertyRNA *UNUSED(prop), bool *r_free)
|
||||
{
|
||||
EnumPropertyItem *item = NULL;
|
||||
int totitem = 0;
|
||||
StudioLight *sl = (StudioLight *)ptr->data;
|
||||
|
||||
if ((sl->flag & (STUDIOLIGHT_ORIENTATION_VIEWNORMAL | STUDIOLIGHT_ORIENTATION_CAMERA)) == 0) {
|
||||
EnumPropertyItem tmp = {0, sl->name, sl->radiance_icon_id, sl->name, ""};
|
||||
RNA_enum_item_add(&item, &totitem, &tmp);
|
||||
}
|
||||
|
||||
{
|
||||
EnumPropertyItem tmp = {1, sl->name, sl->irradiance_icon_id, sl->name, ""};
|
||||
RNA_enum_item_add(&item, &totitem, &tmp);
|
||||
}
|
||||
RNA_enum_item_end(&item, &totitem);
|
||||
*r_free = true;
|
||||
return item;
|
||||
}
|
||||
|
||||
/* StudioLight.is_user_defined */
|
||||
static int rna_UserDef_studiolight_is_user_defined_get(PointerRNA *ptr)
|
||||
{
|
||||
|
@ -3320,12 +3283,6 @@ static void rna_def_userdef_studiolight(BlenderRNA *brna)
|
|||
RNA_def_property_enum_funcs(prop, "rna_UserDef_studiolight_orientation_get", "rna_UserDef_studiolight_orientation_set", NULL);
|
||||
RNA_def_property_ui_text(prop, "Orientation", "");
|
||||
|
||||
prop = RNA_def_property(srna, "icon_id", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_funcs(prop, "rna_UserDef_studiolight_icon_id_get", NULL, "rna_UserDef_studiolight_icon_id_itemf");
|
||||
RNA_def_property_enum_items(prop, rna_enum_studio_light_icons_id_items);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_ui_text(prop, "Preview", "Preview of the studiolight");
|
||||
|
||||
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
|
||||
RNA_def_property_string_funcs(prop, "rna_UserDef_studiolight_name_get", "rna_UserDef_studiolight_name_length", NULL);
|
||||
RNA_def_property_ui_text(prop, "Name", "");
|
||||
|
|
Loading…
Reference in New Issue