Cleanup: specify default studiolight name, instead using first alphabetically.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 31 Dec 2018 14:36:09 +0000 (15:36 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 31 Dec 2018 14:40:42 +0000 (15:40 +0100)
source/blender/blenkernel/BKE_studiolight.h
source/blender/blenkernel/intern/studiolight.c
source/blender/blenloader/intern/versioning_280.c

index 25931e2..cbaa25d 100644 (file)
@@ -140,7 +140,7 @@ void BKE_studiolight_init(void);
 void BKE_studiolight_free(void);
 struct StudioLight *BKE_studiolight_find(const char *name, int flag);
 struct StudioLight *BKE_studiolight_findindex(int index, int flag);
-struct StudioLight *BKE_studiolight_find_first(int flag);
+struct StudioLight *BKE_studiolight_find_default(int flag);
 void BKE_studiolight_preview(uint *icon_buffer, StudioLight *sl, int icon_id_type);
 struct ListBase *BKE_studiolight_listbase(void);
 void BKE_studiolight_ensure_flag(StudioLight *sl, int flag);
index 070b94e..a52ade0 100644 (file)
@@ -88,6 +88,9 @@ static const char *STUDIOLIGHT_LIGHTS_FOLDER = "studiolights/studio/";
 static const char *STUDIOLIGHT_WORLD_FOLDER = "studiolights/world/";
 static const char *STUDIOLIGHT_MATCAP_FOLDER = "studiolights/matcap/";
 
+static const char *STUDIOLIGHT_WORLD_DEFAULT = "forest.exr";
+static const char *STUDIOLIGHT_MATCAP_DEFAULT = "basic_1.exr";
+
 /* ITER MACRO */
 
 /** Iter on all pixel giving texel center position and pixel pointer.
@@ -1249,8 +1252,23 @@ void BKE_studiolight_free(void)
        }
 }
 
-struct StudioLight *BKE_studiolight_find_first(int flag)
+struct StudioLight *BKE_studiolight_find_default(int flag)
 {
+       const char *default_name = "";
+
+       if (flag & STUDIOLIGHT_TYPE_WORLD) {
+               default_name = STUDIOLIGHT_WORLD_DEFAULT;
+       }
+       else if (flag & STUDIOLIGHT_TYPE_MATCAP) {
+               default_name = STUDIOLIGHT_MATCAP_DEFAULT;
+       }
+
+       LISTBASE_FOREACH(StudioLight *, sl, &studiolights) {
+               if ((sl->flag & flag) && STREQ(sl->name, default_name)) {
+                       return sl;
+               }
+       }
+
        LISTBASE_FOREACH(StudioLight *, sl, &studiolights) {
                if ((sl->flag & flag)) {
                        return sl;
@@ -1268,12 +1286,12 @@ struct StudioLight *BKE_studiolight_find(const char *name, int flag)
                        }
                        else {
                                /* flags do not match, so use default */
-                               return BKE_studiolight_find_first(flag);
+                               return BKE_studiolight_find_default(flag);
                        }
                }
        }
        /* When not found, use the default studio light */
-       return BKE_studiolight_find_first(flag);
+       return BKE_studiolight_find_default(flag);
 }
 
 struct StudioLight *BKE_studiolight_findindex(int index, int flag)
@@ -1284,7 +1302,7 @@ struct StudioLight *BKE_studiolight_findindex(int index, int flag)
                }
        }
        /* When not found, use the default studio light */
-       return BKE_studiolight_find_first(flag);
+       return BKE_studiolight_find_default(flag);
 }
 
 struct ListBase *BKE_studiolight_listbase(void)
index ab5f1a3..f81705a 100644 (file)
@@ -1656,7 +1656,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
                        }
                }
                if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "char", "matcap[256]")) {
-                       StudioLight *default_matcap = BKE_studiolight_find_first(STUDIOLIGHT_TYPE_MATCAP);
+                       StudioLight *default_matcap = BKE_studiolight_find_default(STUDIOLIGHT_TYPE_MATCAP);
                        /* when loading the internal file is loaded before the matcaps */
                        if (default_matcap) {
                                for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {