Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/render/render_preview.c
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLO_readfile.h" | #include "BLO_readfile.h" | ||||
| #include "DNA_world_types.h" | #include "DNA_world_types.h" | ||||
| #include "DNA_camera_types.h" | #include "DNA_camera_types.h" | ||||
| #include "DNA_group_types.h" | |||||
| #include "DNA_material_types.h" | #include "DNA_material_types.h" | ||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_lamp_types.h" | #include "DNA_lamp_types.h" | ||||
| #include "DNA_space_types.h" | #include "DNA_space_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_brush_types.h" | #include "DNA_brush_types.h" | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| ▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | |||||
| static Scene *preview_get_scene(Main *pr_main) | static Scene *preview_get_scene(Main *pr_main) | ||||
| { | { | ||||
| if (pr_main == NULL) return NULL; | if (pr_main == NULL) return NULL; | ||||
| return pr_main->scene.first; | return pr_main->scene.first; | ||||
| } | } | ||||
| static const char *preview_layer_name(const char pr_type) | static const char *preview_collection_name(const char pr_type) | ||||
| { | { | ||||
| switch (pr_type) { | switch (pr_type) { | ||||
| case MA_FLAT: | case MA_FLAT: | ||||
| return "Flat"; | return "Flat"; | ||||
| case MA_SPHERE: | case MA_SPHERE: | ||||
| return "Sphere"; | return "Sphere"; | ||||
| case MA_CUBE: | case MA_CUBE: | ||||
| return "Cube"; | return "Cube"; | ||||
| Show All 12 Lines | switch (pr_type) { | ||||
| case MA_ATMOS: | case MA_ATMOS: | ||||
| return "Atmosphere"; | return "Atmosphere"; | ||||
| default: | default: | ||||
| BLI_assert(!"Unknown preview type"); | BLI_assert(!"Unknown preview type"); | ||||
| return ""; | return ""; | ||||
| } | } | ||||
| } | } | ||||
| static void set_preview_layer(ViewLayer *view_layer, char pr_type) | static void set_preview_collection(Scene *scene, ViewLayer *view_layer, char pr_type) | ||||
| { | { | ||||
| LayerCollection *lc; | LayerCollection *lc = view_layer->layer_collections.first; | ||||
| const char *collection_name = preview_layer_name(pr_type); | const char *collection_name = preview_collection_name(pr_type); | ||||
| for (lc = view_layer->layer_collections.first; lc; lc = lc->next) { | for (lc = lc->layer_collections.first; lc; lc = lc->next) { | ||||
| if (STREQ(lc->scene_collection->name, collection_name)) { | if (STREQ(lc->collection->id.name + 2, collection_name)) { | ||||
| lc->flag = COLLECTION_VIEWPORT | COLLECTION_RENDER; | lc->collection->flag &= ~COLLECTION_RESTRICT_RENDER; | ||||
| } | } | ||||
| else { | else { | ||||
| lc->flag = COLLECTION_DISABLED; | lc->collection->flag |= COLLECTION_RESTRICT_RENDER; | ||||
| } | } | ||||
| } | } | ||||
| BKE_layer_collection_sync(scene, view_layer); | |||||
| } | } | ||||
| static World *preview_get_localized_world(ShaderPreview *sp, World *world) | static World *preview_get_localized_world(ShaderPreview *sp, World *world) | ||||
| { | { | ||||
| if (world == NULL) { | if (world == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| if (sp->worldcopy != NULL) { | if (sp->worldcopy != NULL) { | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | if (id_type == ID_MA) { | ||||
| * scene world can be slow if it has big textures. */ | * scene world can be slow if it has big textures. */ | ||||
| sce->world->use_nodes = false; | sce->world->use_nodes = false; | ||||
| sce->world->horr = 0.5f; | sce->world->horr = 0.5f; | ||||
| sce->world->horg = 0.5f; | sce->world->horg = 0.5f; | ||||
| sce->world->horb = 0.5f; | sce->world->horb = 0.5f; | ||||
| } | } | ||||
| if (sp->pr_method == PR_ICON_RENDER) { | if (sp->pr_method == PR_ICON_RENDER) { | ||||
| set_preview_layer(view_layer, MA_SPHERE_A); | set_preview_collection(sce, view_layer, MA_SPHERE_A); | ||||
| } | } | ||||
| else { | else { | ||||
| set_preview_layer(view_layer, mat->pr_type); | set_preview_collection(sce, view_layer, mat->pr_type); | ||||
| if (mat->nodetree && sp->pr_method == PR_NODE_RENDER) { | if (mat->nodetree && sp->pr_method == PR_NODE_RENDER) { | ||||
| /* two previews, they get copied by wmJob */ | /* two previews, they get copied by wmJob */ | ||||
| BKE_node_preview_init_tree(mat->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(mat->nodetree, sp->sizex, sp->sizey, true); | ||||
| BKE_node_preview_init_tree(origmat->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(origmat->nodetree, sp->sizex, sp->sizey, true); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 24 Lines | if (sce) { | ||||
| else if (id_type == ID_TE) { | else if (id_type == ID_TE) { | ||||
| Tex *tex = NULL, *origtex = (Tex *)id; | Tex *tex = NULL, *origtex = (Tex *)id; | ||||
| if (origtex) { | if (origtex) { | ||||
| tex = BKE_texture_localize(origtex); | tex = BKE_texture_localize(origtex); | ||||
| sp->texcopy = tex; | sp->texcopy = tex; | ||||
| BLI_addtail(&pr_main->tex, tex); | BLI_addtail(&pr_main->tex, tex); | ||||
| } | } | ||||
| set_preview_layer(view_layer, MA_TEXTURE); | set_preview_collection(sce, view_layer, MA_TEXTURE); | ||||
| if (tex && tex->nodetree && sp->pr_method == PR_NODE_RENDER) { | if (tex && tex->nodetree && sp->pr_method == PR_NODE_RENDER) { | ||||
| /* two previews, they get copied by wmJob */ | /* two previews, they get copied by wmJob */ | ||||
| BKE_node_preview_init_tree(origtex->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(origtex->nodetree, sp->sizex, sp->sizey, true); | ||||
| BKE_node_preview_init_tree(tex->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(tex->nodetree, sp->sizex, sp->sizey, true); | ||||
| } | } | ||||
| } | } | ||||
| else if (id_type == ID_LA) { | else if (id_type == ID_LA) { | ||||
| Lamp *la = NULL, *origla = (Lamp *)id; | Lamp *la = NULL, *origla = (Lamp *)id; | ||||
| /* work on a copy */ | /* work on a copy */ | ||||
| if (origla) { | if (origla) { | ||||
| la = BKE_lamp_localize(origla); | la = BKE_lamp_localize(origla); | ||||
| sp->lampcopy = la; | sp->lampcopy = la; | ||||
| BLI_addtail(&pr_main->lamp, la); | BLI_addtail(&pr_main->lamp, la); | ||||
| } | } | ||||
| set_preview_layer(view_layer, MA_LAMP); | set_preview_collection(sce, view_layer, MA_LAMP); | ||||
| if (sce->world) { | if (sce->world) { | ||||
| /* Only use lighting from the lamp. */ | /* Only use lighting from the lamp. */ | ||||
| sce->world->use_nodes = false; | sce->world->use_nodes = false; | ||||
| sce->world->horr = 0.0f; | sce->world->horr = 0.0f; | ||||
| sce->world->horg = 0.0f; | sce->world->horg = 0.0f; | ||||
| sce->world->horb = 0.0f; | sce->world->horb = 0.0f; | ||||
| } | } | ||||
| Show All 15 Lines | else if (id_type == ID_WO) { | ||||
| World *wrld = NULL, *origwrld = (World *)id; | World *wrld = NULL, *origwrld = (World *)id; | ||||
| if (origwrld) { | if (origwrld) { | ||||
| wrld = BKE_world_localize(origwrld); | wrld = BKE_world_localize(origwrld); | ||||
| sp->worldcopy = wrld; | sp->worldcopy = wrld; | ||||
| BLI_addtail(&pr_main->world, wrld); | BLI_addtail(&pr_main->world, wrld); | ||||
| } | } | ||||
| set_preview_layer(view_layer, MA_SKY); | set_preview_collection(sce, view_layer, MA_SKY); | ||||
| sce->world = wrld; | sce->world = wrld; | ||||
| if (wrld && wrld->nodetree && sp->pr_method == PR_NODE_RENDER) { | if (wrld && wrld->nodetree && sp->pr_method == PR_NODE_RENDER) { | ||||
| /* two previews, they get copied by wmJob */ | /* two previews, they get copied by wmJob */ | ||||
| BKE_node_preview_init_tree(wrld->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(wrld->nodetree, sp->sizex, sp->sizey, true); | ||||
| BKE_node_preview_init_tree(origwrld->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(origwrld->nodetree, sp->sizex, sp->sizey, true); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 766 Lines • Show Last 20 Lines | |||||