Workbench: Add option to have world space lighting in studio light mode
authorClément Foucault <foucault.clem@gmail.com>
Thu, 29 Nov 2018 19:57:09 +0000 (20:57 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Thu, 29 Nov 2018 20:52:36 +0000 (21:52 +0100)
This option is per viewport.

Having view space shading make sense when working on isolated objects like
if you were holding them in your hands. But for entire scene work, it is
better to have the lighting fixed to have a better spatial representation.

release/scripts/startup/bl_ui/space_view3d.py
source/blender/draw/engines/workbench/workbench_private.h
source/blender/draw/engines/workbench/workbench_studiolight.c
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_space.c

index bc38214f10180518d911217517b29d49a65e7104..cc0881e1a9aeb4b194d8d7936e978864e3263c04 100644 (file)
@@ -4189,14 +4189,22 @@ class VIEW3D_PT_shading_lighting(Panel):
             sub.scale_y = 0.6  # smaller matcap/hdri preview
 
             if shading.light == 'STUDIO':
-                # Not implemented right now
+                userpref = context.user_preferences
+                system = userpref.system
+
                 sub.template_icon_view(shading, "studio_light", scale=3)
 
-                # if shading.selected_studio_light.type == 'WORLD':
-                #     col.prop(shading, "studiolight_rotate_z", text="Rotation")
+                col = split.column()
+                col.operator('wm.studiolight_userpref_show', emboss=False, text="", icon='PREFERENCES')
 
+                split = layout.split(factor=0.9)
                 col = split.column()
-                # col.operator('wm.studiolight_userpref_show', emboss=False, text="", icon='PREFERENCES')
+                row = col.row()
+                row.prop(shading, "use_world_space_lighting", text="", icon="WORLD", toggle=True)
+                row = row.row()
+                row.active = shading.use_world_space_lighting
+                row.prop(shading, "studiolight_rotate_z", text="Rotation")
+                col = split.column()  # to align properly with above
 
             elif shading.light == 'MATCAP':
                 sub.template_icon_view(shading, "studio_light", scale=3)
index b1f3a589d056bacce7e8d0a29daba6159856cbed..9853737518cf96856bf6733a3600b1ce3674b646 100644 (file)
@@ -46,6 +46,7 @@
 #define FLAT_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_FLAT)
 #define STUDIOLIGHT_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_STUDIO)
 #define MATCAP_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_MATCAP)
+#define USE_WORLD_ORIENTATION(wpd) ((wpd->shading.flag & V3D_SHADING_WORLD_ORIENTATION) != 0)
 #define STUDIOLIGHT_TYPE_WORLD_ENABLED(wpd) (STUDIOLIGHT_ENABLED(wpd) && (wpd->studio_light->flag & STUDIOLIGHT_TYPE_WORLD))
 #define STUDIOLIGHT_TYPE_STUDIO_ENABLED(wpd) (STUDIOLIGHT_ENABLED(wpd) && (wpd->studio_light->flag & STUDIOLIGHT_TYPE_STUDIO))
 #define STUDIOLIGHT_TYPE_MATCAP_ENABLED(wpd) (MATCAP_ENABLED(wpd) && (wpd->studio_light->flag & STUDIOLIGHT_TYPE_MATCAP))
index 183b285c69c35b314810e7a33c989883718b048a..f0a166105ab6e6be2e841df4fbcec9ecece14f35 100644 (file)
@@ -37,8 +37,7 @@ void studiolight_update_world(WORKBENCH_PrivateData *wpd, StudioLight *studiolig
        float view_matrix[4][4], rot_matrix[4][4];
        DRW_viewport_matrix_get(view_matrix, DRW_MAT_VIEW);
 
-       /* TODO enable when we support studiolight presets. */
-       if (STUDIOLIGHT_TYPE_WORLD_ENABLED(wpd) && false) {
+       if (USE_WORLD_ORIENTATION(wpd)) {
                axis_angle_to_mat4_single(rot_matrix, 'Y', -wpd->shading.studiolight_rot_z);
                mul_m4_m4m4(rot_matrix, rot_matrix, view_matrix);
                swap_v3_v3(rot_matrix[2], rot_matrix[1]);
index 5c31f37744713380f514470fcd1b4d35324b0a28..79d2c230fdcbbc10442a4581c66e29f7feac9d99 100644 (file)
@@ -395,6 +395,7 @@ enum {
        V3D_SHADING_MATCAP_FLIP_X       = (1 << 6),
        V3D_SHADING_SCENE_WORLD         = (1 << 7),
        V3D_SHADING_XRAY_BONE           = (1 << 8),
+       V3D_SHADING_WORLD_ORIENTATION   = (1 << 9),
 };
 
 /* View3DShading->color_type */
index 74fb09f808821e70f22115479ccf20aea71cf383..e8cda30a5111cd49cd95341fa56340cae868f1c6 100644 (file)
@@ -2441,6 +2441,12 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Studiolight", "Studio lighting setup");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
+       prop = RNA_def_property(srna, "use_world_space_lighting", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_WORLD_ORIENTATION);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_ui_text(prop, "World Space Lighting", "Make the lighting fixed and not follow the camera");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
        prop = RNA_def_property(srna, "show_cavity", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_CAVITY);
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);