[Bf-blender-cvs] [fe285548980] blender2.8: StudioLight Editor: Add copy settings and overwrite prompt

Clément Foucault noreply at git.blender.org
Fri Nov 30 15:41:13 CET 2018


Commit: fe2855489801d8e87038b8b5884fc9d26efb1bf2
Author: Clément Foucault
Date:   Fri Nov 30 15:40:46 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBfe2855489801d8e87038b8b5884fc9d26efb1bf2

StudioLight Editor: Add copy settings and overwrite prompt

Copy settings let users create variations more easily.

Ovewrite prompt is there to be able to edit already existing studiolight.

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

M	release/scripts/startup/bl_operators/wm.py
M	release/scripts/startup/bl_ui/space_userpref.py
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 f78b7491bdd..03f83097cb0 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -2480,18 +2480,21 @@ class WM_OT_studiolight_install(Operator):
 
 
 class WM_OT_studiolight_new(Operator):
-    """Create custom studio light from the studio light editor settings"""
+    """Save custom studio light from the studio light editor settings"""
     bl_idname = 'wm.studiolight_new'
-    bl_label = "Create custom Studio light"
+    bl_label = "Save custom Studio light"
 
     filename: StringProperty(
         name="Name",
         default="StudioLight",
     )
 
+    ask_overide = False
+
     def execute(self, context):
         import pathlib
         userpref = context.user_preferences
+        wm = context.window_manager
 
         path_studiolights = bpy.utils.user_resource('DATAFILES')
 
@@ -2508,8 +2511,13 @@ class WM_OT_studiolight_new(Operator):
 
         finalpath = str(path_studiolights.joinpath(self.filename));
         if pathlib.Path(finalpath + ".sl").is_file():
-            self.report({'ERROR'}, "File already exists")
-            return {'CANCELLED'}
+            if not self.ask_overide:
+                self.ask_overide = True
+                return wm.invoke_props_dialog(self, width=600)
+            else:
+                for studio_light in userpref.studio_lights:
+                    if studio_light.name == self.filename + ".sl":
+                        bpy.ops.wm.studiolight_uninstall(index=studio_light.index)
 
         userpref.studio_lights.new(path=finalpath)
 
@@ -2524,7 +2532,10 @@ class WM_OT_studiolight_new(Operator):
 
     def draw(self, context):
         layout = self.layout
-        layout.prop(self, "filename")
+        if self.ask_overide:
+            layout.label(text="Warning, file already exists. Overwrite existing file?")
+        else:
+            layout.prop(self, "filename")
 
     def invoke(self, context, event):
         wm = context.window_manager
@@ -2532,6 +2543,7 @@ class WM_OT_studiolight_new(Operator):
 
 
 class WM_OT_studiolight_uninstall(Operator):
+    """Delete Studio Light"""
     bl_idname = 'wm.studiolight_uninstall'
     bl_label = "Uninstall Studio Light"
     index: bpy.props.IntProperty()
@@ -2556,6 +2568,28 @@ class WM_OT_studiolight_uninstall(Operator):
         return {'CANCELLED'}
 
 
+class WM_OT_studiolight_copy_settings(Operator):
+    """Copy Studio Light settings to the Studio light editor"""
+    bl_idname = 'wm.studiolight_copy_settings'
+    bl_label = "Copy Studio Light settings"
+    index: bpy.props.IntProperty()
+
+    def execute(self, context):
+        userpref = context.user_preferences
+        system = userpref.system
+        for studio_light in userpref.studio_lights:
+            if studio_light.index == self.index:
+                system.light_ambient = studio_light.light_ambient
+                for sys_light, light in zip(system.solid_lights, studio_light.solid_lights):
+                    sys_light.use = light.use
+                    sys_light.diffuse_color = light.diffuse_color
+                    sys_light.specular_color = light.specular_color
+                    sys_light.smooth = light.smooth
+                    sys_light.direction = light.direction
+                return {'FINISHED'}
+        return {'CANCELLED'}
+
+
 class WM_OT_studiolight_userpref_show(Operator):
     """Show light user preferences"""
     bl_idname = "wm.studiolight_userpref_show"
@@ -2819,6 +2853,7 @@ classes = (
     WM_OT_studiolight_install,
     WM_OT_studiolight_new,
     WM_OT_studiolight_uninstall,
+    WM_OT_studiolight_copy_settings,
     WM_OT_studiolight_userpref_show,
     WM_OT_tool_set_by_name,
     WM_OT_toolbar,
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 56accc902f4..ae1fe42b3d7 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -1516,9 +1516,14 @@ class StudioLightPanelMixin():
         row = box.row()
 
         row.template_icon(layout.icon(studio_light), scale=6.0)
-        op = row.operator('wm.studiolight_uninstall', text="", icon='REMOVE')
+        col = row.column()
+        op = col.operator('wm.studiolight_uninstall', text="", icon='REMOVE')
         op.index = studio_light.index
 
+        if studio_light.type == 'STUDIO':
+            op = col.operator('wm.studiolight_copy_settings', text="", icon='IMPORT')
+            op.index = studio_light.index
+
         box.label(text=studio_light.name)
 
 
@@ -1536,29 +1541,6 @@ class USERPREF_PT_studiolight_lights(Panel, StudioLightPanelMixin):
     bl_label = "Studio Lights"
     sl_type = 'STUDIO'
 
-    @classmethod
-    def poll(cls, context):
-        userpref = context.user_preferences
-        return (userpref.active_section == 'LIGHTS')
-
-    def opengl_light_buttons(self, layout, light):
-
-        col = layout.column()
-        col.active = light.use
-
-        col.prop(light, "use", text="Use Light")
-        col.prop(light, "diffuse_color", text="Diffuse")
-        col.prop(light, "specular_color", text="Specular")
-        col.prop(light, "smooth")
-        col.prop(light, "direction")
-
-    def draw(self, context):
-        userpref = context.user_preferences
-        lights = self._get_lights(userpref)
-        layout = self.layout
-
-        self.draw_light_list(layout, lights)
-
 
 class USERPREF_PT_studiolight_light_editor(Panel):
     bl_label = "Studio Light Editor"
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 80b937c9367..3bdec89ce5b 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -743,6 +743,28 @@ static void rna_UserDef_studiolight_spherical_harmonics_coefficients_get(Pointer
 	}
 }
 
+/* StudioLight.solid_lights */
+
+static void rna_UserDef_studiolight_solid_lights_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+	StudioLight *sl = (StudioLight *)ptr->data;
+	rna_iterator_array_begin(iter, sl->light, sizeof(*sl->light), ARRAY_SIZE(sl->light), 0, NULL);
+}
+
+static int rna_UserDef_studiolight_solid_lights_length(PointerRNA *ptr)
+{
+	StudioLight *sl = (StudioLight *)ptr->data;
+	return ARRAY_SIZE(sl->light);
+}
+
+/* StudioLight.light_ambient */
+
+static void rna_UserDef_studiolight_light_ambient_get(PointerRNA *ptr, float *values)
+{
+	StudioLight *sl = (StudioLight *)ptr->data;
+	copy_v3_v3(values, sl->light_ambient);
+}
+
 #else
 
 /* TODO(sergey): This technically belongs to blenlib, but we don't link
@@ -3387,6 +3409,21 @@ static void rna_def_userdef_studiolight(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Path", "");
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 
+	prop = RNA_def_property(srna, "solid_lights", PROP_COLLECTION, PROP_NONE);
+	RNA_def_property_collection_sdna(prop, NULL, "light_param", "");
+	RNA_def_property_struct_type(prop, "UserSolidLight");
+	RNA_def_property_collection_funcs(prop, "rna_UserDef_studiolight_solid_lights_begin", "rna_iterator_array_next",
+	                                        "rna_iterator_array_end", "rna_iterator_array_get",
+	                                        "rna_UserDef_studiolight_solid_lights_length", NULL, NULL, NULL);
+	RNA_def_property_ui_text(prop, "Solid Lights", "Lights user to display objects in solid draw mode");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+	prop = RNA_def_property(srna, "light_ambient", PROP_FLOAT, PROP_COLOR);
+	RNA_def_property_array(prop, 3);
+	RNA_def_property_float_funcs(prop, "rna_UserDef_studiolight_light_ambient_get", NULL, NULL);
+	RNA_def_property_ui_text(prop, "Ambient Color", "Color of the ambient light that uniformly lit the scene");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
 	prop = RNA_def_property(srna, "path_irr_cache", PROP_STRING, PROP_DIRPATH);
 	RNA_def_property_string_funcs(prop, "rna_UserDef_studiolight_path_irr_cache_get", "rna_UserDef_studiolight_path_irr_cache_length", NULL);
 	RNA_def_property_ui_text(prop, "Irradiance Cache Path", "Path where the irradiance cache is stored");



More information about the Bf-blender-cvs mailing list