[Bf-blender-cvs] [844788a36cb] blender2.8: Workbench: Add back studio lighting presets

Clément Foucault noreply at git.blender.org
Thu Nov 29 21:52:46 CET 2018


Commit: 844788a36cb0e1efdf3a2010ee67abcb7c46474c
Author: Clément Foucault
Date:   Thu Nov 29 19:54:23 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB844788a36cb0e1efdf3a2010ee67abcb7c46474c

Workbench: Add back studio lighting presets

This changes a bit how the userprefs solid lights works. They are not
visible until enabling the "Edit Solid Light" checkbox. Once enabled the
current studiolight used for solid mode will be overwritten.

Once the lighting settings are tweaked, the user can click the
"Save as Studio light" button to save the current settings.
This makes it easy to create new lighting without messing the other
presets.

The studio lights are stored as ASCII files on the disk using a dead
simple custom format.

The UI/UX is not perfect and will be improved in other commits.

Also includes:
* Separate LookDev HDRI selection from Solid Lights
* Hide LookDev HDRIs from the Solid Lights selection list

===================================================================

M	release/scripts/startup/bl_operators/wm.py
M	release/scripts/startup/bl_ui/space_userpref.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/BKE_studiolight.h
M	source/blender/blenkernel/intern/studiolight.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/engines/eevee/eevee_lookdev.c
M	source/blender/draw/engines/workbench/workbench_data.c
M	source/blender/draw/engines/workbench/workbench_private.h
M	source/blender/draw/engines/workbench/workbench_studiolight.c
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_userdef.c

===================================================================

diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index 4206adcfb91..65ac0cb745b 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -2462,7 +2462,7 @@ class WM_OT_studiolight_install(Operator):
 
         for filepath in filepaths:
             shutil.copy(str(filepath), str(path_studiolights))
-            userpref.studio_lights.new(str(path_studiolights.joinpath(filepath.name)), self.type)
+            userpref.studio_lights.load(str(path_studiolights.joinpath(filepath.name)), self.type)
 
         # print message
         msg = (
@@ -2479,6 +2479,57 @@ class WM_OT_studiolight_install(Operator):
         return {'RUNNING_MODAL'}
 
 
+class WM_OT_studiolight_new(Operator):
+    bl_idname = 'wm.studiolight_new'
+    bl_label = "Create Studio Light from default light setup"
+
+    filename: StringProperty(
+        name="Filename",
+        default="StudioLight",
+    )
+
+    def execute(self, context):
+        import pathlib
+        userpref = context.user_preferences
+
+        path_studiolights = bpy.utils.user_resource('DATAFILES')
+
+        if not path_studiolights:
+            self.report({'ERROR'}, "Failed to get Studio Light path")
+            return {'CANCELLED'}
+
+        path_studiolights = pathlib.Path(path_studiolights, "studiolights", "studio")
+        if not path_studiolights.exists():
+            try:
+                path_studiolights.mkdir(parents=True, exist_ok=True)
+            except:
+                traceback.print_exc()
+
+        finalpath = str(path_studiolights.joinpath(self.filename));
+        if pathlib.Path(finalpath + ".sl").is_file():
+            self.report({'ERROR'}, "File already exists")
+            return {'CANCELLED'}
+
+        userpref.studio_lights.new(path=finalpath)
+
+        # print message
+        msg = (
+            tip_("StudioLight Installed %r into %r") %
+            (self.filename, str(path_studiolights))
+        )
+        print(msg)
+        self.report({'INFO'}, msg)
+        return {'FINISHED'}
+
+    def draw(self, context):
+        layout = self.layout
+        layout.prop(self, "filename")
+
+    def invoke(self, context, event):
+        wm = context.window_manager
+        return wm.invoke_props_dialog(self, width=600)
+
+
 class WM_OT_studiolight_uninstall(Operator):
     bl_idname = 'wm.studiolight_uninstall'
     bl_label = "Uninstall Studio Light"
@@ -2765,6 +2816,7 @@ classes = (
     WM_OT_owner_enable,
     WM_OT_url_open,
     WM_OT_studiolight_install,
+    WM_OT_studiolight_new,
     WM_OT_studiolight_uninstall,
     WM_OT_studiolight_userpref_show,
     WM_OT_tool_set_by_name,
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 72b07d55f70..261eccc7c55 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -47,7 +47,9 @@ class USERPREF_HT_header(Header):
         elif userpref.active_section == 'LIGHTS':
             layout.operator('wm.studiolight_install', text="Add MatCap").type = 'MATCAP'
             layout.operator('wm.studiolight_install', text="Add LookDev HDRI").type = 'WORLD'
-            layout.operator('wm.studiolight_install', text="Add Studio Light").type = 'STUDIO'
+            op = layout.operator('wm.studiolight_install', text="Add Studio Light")
+            op.type = 'STUDIO'
+            op.filter_glob = ".sl"
         elif userpref.active_section == 'THEMES':
             layout.operator("wm.theme_install", icon='FILEBROWSER')
             layout.operator("ui.reset_default_theme", icon='LOOP_BACK')
@@ -1498,6 +1500,10 @@ class StudioLightPanelMixin():
         layout = self.layout
         userpref = context.user_preferences
         lights = self._get_lights(userpref)
+
+        self.draw_light_list(layout, lights)
+
+    def draw_light_list(self, layout, lights):
         if lights:
             flow = layout.column_flow(columns=4)
             for studio_light in lights:
@@ -1569,8 +1575,16 @@ class USERPREF_PT_studiolight_lights(Panel, StudioLightPanelMixin):
 
         layout.separator()
 
+        layout.prop(system, "edit_solid_light")
         layout.prop(system, "light_ambient")
 
+        layout.operator('wm.studiolight_new', text="Save as Studio light")
+
+        lights = self._get_lights(userpref)
+
+        self.draw_light_list(layout, lights)
+
+
 classes = (
     USERPREF_HT_header,
     USERPREF_PT_navigation,
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 0ba3b2217f2..bc38214f101 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4190,9 +4190,9 @@ class VIEW3D_PT_shading_lighting(Panel):
 
             if shading.light == 'STUDIO':
                 # Not implemented right now
-                # sub.template_icon_view(shading, "studio_light", scale=3)
+                sub.template_icon_view(shading, "studio_light", scale=3)
 
-                # if shading.selected_studio_light.orientation == 'WORLD':
+                # if shading.selected_studio_light.type == 'WORLD':
                 #     col.prop(shading, "studiolight_rotate_z", text="Rotation")
 
                 col = split.column()
@@ -4221,7 +4221,7 @@ class VIEW3D_PT_shading_lighting(Panel):
                 col = split.column()
                 col.operator('wm.studiolight_userpref_show', emboss=False, text="", icon='PREFERENCES')
 
-                if shading.selected_studio_light.orientation == 'WORLD':
+                if shading.selected_studio_light.type == 'WORLD':
                     split = layout.split(factor=0.9)
                     col = split.column()
                     col.prop(shading, "studiolight_rotate_z", text="Rotation")
diff --git a/source/blender/blenkernel/BKE_studiolight.h b/source/blender/blenkernel/BKE_studiolight.h
index 6616af355ac..25931e2bbf5 100644
--- a/source/blender/blenkernel/BKE_studiolight.h
+++ b/source/blender/blenkernel/BKE_studiolight.h
@@ -39,6 +39,7 @@
 #include "BLI_sys_types.h"
 
 #include "DNA_space_types.h"
+#include "DNA_userdef_types.h"
 
 #include "IMB_imbuf_types.h"
 
@@ -59,6 +60,8 @@
 #define STUDIOLIGHT_ICON_ID_TYPE_MATCAP         (1 << 2)
 #define STUDIOLIGHT_ICON_ID_TYPE_MATCAP_FLIPPED (1 << 3)
 
+#define STUDIOLIGHT_MAX_LIGHT 4
+
 #define STUDIOLIGHT_ICON_SIZE 96
 
 /* Only 1 - 5 is supported */
@@ -97,7 +100,7 @@ enum StudioLightFlag {
 #define STUDIOLIGHT_FLAG_ALL (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_EXTERNAL_FILE)
 #define STUDIOLIGHT_FLAG_ORIENTATIONS (STUDIOLIGHT_TYPE_STUDIO | STUDIOLIGHT_TYPE_WORLD | STUDIOLIGHT_TYPE_MATCAP)
 #define STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE (STUDIOLIGHT_TYPE_WORLD)
-#define STUDIOLIGHT_ORIENTATIONS_SOLID (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_TYPE_STUDIO | STUDIOLIGHT_TYPE_WORLD)
+#define STUDIOLIGHT_ORIENTATIONS_SOLID (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_TYPE_STUDIO)
 
 typedef void StudioLightFreeFunction(struct StudioLight *, void *data);
 
@@ -121,6 +124,8 @@ typedef struct StudioLight {
 	ImBuf *radiance_cubemap_buffers[6];
 	struct GPUTexture *equirect_radiance_gputexture;
 	struct GPUTexture *equirect_irradiance_gputexture;
+	SolidLight light[STUDIOLIGHT_MAX_LIGHT];
+	float light_ambient[3];
 
 	/*
 	 * Free function to clean up the running icons previews (wmJob) the usage is in
@@ -140,7 +145,9 @@ void BKE_studiolight_preview(uint *icon_buffer, StudioLight *sl, int icon_id_typ
 struct ListBase *BKE_studiolight_listbase(void);
 void BKE_studiolight_ensure_flag(StudioLight *sl, int flag);
 void BKE_studiolight_refresh(void);
-StudioLight *BKE_studiolight_new(const char *path, int orientation);
+StudioLight *BKE_studiolight_load(const char *path, int orientation);
+StudioLight *BKE_studiolight_create(const char *path, const SolidLight light[4], const float light_ambient[3]);
+StudioLight *BKE_studiolight_studio_edit_get(void);
 void BKE_studiolight_remove(StudioLight *sl);
 void BKE_studiolight_set_free_function(StudioLight *sl, StudioLightFreeFunction *free_function, void *data);
 void BKE_studiolight_unset_icon_id(StudioLight *sl, int icon_id);
diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c
index 937c24c47e6..10d9dcfbfec 100644
--- a/source/blender/blenkernel/intern/studiolight.c
+++ b/source/blender/blenkernel/intern/studiolight.c
@@ -35,9 +35,11 @@
 #include "BKE_appdir.h"
 #include "BKE_icons.h"
 
+#include "BLI_dynstr.h"
 #include "BLI_fileops.h"
 #include "BLI_fileops_types.h"
 #include "BLI_listbase.h"
+#include "BLI_linklist.h"
 #include "BLI_math.h"
 #include "BLI_math_color.h"
 #include "BLI_path_util.h"
@@ -82,7 +84,7 @@ static int last_studiolight_id = 0;
  */
 #define STUDIOLIGHT_LOAD_CACHED_FILES
 
-static const char *STUDIOLIGHT_LIGHTS_FOLDER = "studiolights/light/";
+static const char *STUDIOLIGHT_LIGHTS_FOLDER = "studiolights/studio/";
 static const char *STUDIOLIGHT_WORLD_FOLDER = "studiolights/world/";
 static const char *STUDIOLIGHT_MATCAP_FOLDER = "studiolights/matcap/";
 
@@ -168,13 +170,15 @@ static struct StudioLight *studiolight_create(int flag)
 	sl->free_function = NULL;
 	sl->flag = flag;
 	sl->index = ++last_studiolight_id;
-	if (flag & STUDIOLIGHT_TYPE_MATCAP) {
+	if (flag & STUDIOLIGHT_TYPE_STUDIO) {
+		sl->icon_id_irradiance = BKE_icon_ensure_studio_light(sl, STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE);
+	}
+	else if (flag & STUDIOLIGHT_TYPE_MATCAP) {
 		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++) {
@@ -184,6 +188,99 @@ static struct StudioLight *studiolight_create(int flag)
 	return sl;
 }
 
+#define STUDIOLIGHT_FILE_VERSION 1
+
+#define READ_VAL(type, parser, id, val, lines) do { \
+	for (LinkNode *line = lines; line; li

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list