Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/render/render_preview.cc
| Show First 20 Lines • Show All 368 Lines • ▼ Show 20 Lines | case ID_WO: { | ||||
| BLI_assert(BKE_previewimg_id_supports_jobs(id)); | BLI_assert(BKE_previewimg_id_supports_jobs(id)); | ||||
| ID *id_copy = BKE_id_copy_ex(nullptr, | ID *id_copy = BKE_id_copy_ex(nullptr, | ||||
| id, | id, | ||||
| nullptr, | nullptr, | ||||
| LIB_ID_CREATE_LOCAL | LIB_ID_COPY_LOCALIZE | | LIB_ID_CREATE_LOCAL | LIB_ID_COPY_LOCALIZE | | ||||
| LIB_ID_COPY_NO_ANIMDATA); | LIB_ID_COPY_NO_ANIMDATA); | ||||
| return id_copy; | return id_copy; | ||||
| } | } | ||||
| case ID_GR: { | |||||
| /* Doesn't really duplicate the collection. Just creates a collection instance empty. */ | |||||
| BLI_assert(BKE_previewimg_id_supports_jobs(id)); | |||||
| Object *instance_empty = BKE_object_add_only_object(nullptr, OB_EMPTY, nullptr); | |||||
| instance_empty->instance_collection = (Collection *)id; | |||||
| instance_empty->transflag |= OB_DUPLICOLLECTION; | |||||
| return &instance_empty->id; | |||||
| } | |||||
| /* These support threading, but don't need duplicating. */ | /* These support threading, but don't need duplicating. */ | ||||
| case ID_IM: | case ID_IM: | ||||
| case ID_BR: | case ID_BR: | ||||
| BLI_assert(BKE_previewimg_id_supports_jobs(id)); | BLI_assert(BKE_previewimg_id_supports_jobs(id)); | ||||
| return nullptr; | return nullptr; | ||||
| default: | default: | ||||
| if (!allow_failure) { | if (!allow_failure) { | ||||
| BLI_assert_msg(0, "ID type preview not supported."); | BLI_assert_msg(0, "ID type preview not supported."); | ||||
| ▲ Show 20 Lines • Show All 494 Lines • ▼ Show 20 Lines | static void object_preview_render(IconPreview *preview, IconPreviewSize *preview_sized) | ||||
| DEG_graph_free(depsgraph); | DEG_graph_free(depsgraph); | ||||
| BKE_main_free(preview_main); | BKE_main_free(preview_main); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Collection Preview | |||||
| * | |||||
| * For the most part this reuses the object preview code by creating an instance collection empty | |||||
| * object and rendering that. | |||||
| * | |||||
| * \{ */ | |||||
| /** | |||||
| * Check if the collection contains any geometry that can be rendered. Otherwise there's nothing to | |||||
| * display in the preview, so don't generate one. | |||||
| * Objects and sub-collections hidden in the render will be skipped. | |||||
| */ | |||||
| static bool collection_preview_contains_geometry_recursive(const Collection *collection) | |||||
| { | |||||
| LISTBASE_FOREACH (CollectionObject *, col_ob, &collection->gobject) { | |||||
| if (col_ob->ob->visibility_flag & OB_HIDE_RENDER) { | |||||
| continue; | |||||
| } | |||||
| if (OB_TYPE_IS_GEOMETRY(col_ob->ob->type)) { | |||||
| return true; | |||||
| } | |||||
| } | |||||
| LISTBASE_FOREACH (CollectionChild *, child_col, &collection->children) { | |||||
| if (child_col->collection->flag & COLLECTION_HIDE_RENDER) { | |||||
| continue; | |||||
| } | |||||
| if (collection_preview_contains_geometry_recursive(child_col->collection)) { | |||||
| return true; | |||||
| } | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Action Preview | /** \name Action Preview | ||||
| * \{ */ | * \{ */ | ||||
| static struct PoseBackup *action_preview_render_prepare(IconPreview *preview) | static struct PoseBackup *action_preview_render_prepare(IconPreview *preview) | ||||
| { | { | ||||
| Object *object = preview->active_object; | Object *object = preview->active_object; | ||||
| if (object == nullptr) { | if (object == nullptr) { | ||||
| WM_report(RPT_WARNING, "No active object, unable to apply the Action before rendering"); | WM_report(RPT_WARNING, "No active object, unable to apply the Action before rendering"); | ||||
| ▲ Show 20 Lines • Show All 677 Lines • ▼ Show 20 Lines | if (ip->id != nullptr) { | ||||
| switch (GS(ip->id->name)) { | switch (GS(ip->id->name)) { | ||||
| case ID_OB: | case ID_OB: | ||||
| if (object_preview_is_type_supported((Object *)ip->id)) { | if (object_preview_is_type_supported((Object *)ip->id)) { | ||||
| /* Much simpler than the ShaderPreview mess used for other ID types. */ | /* Much simpler than the ShaderPreview mess used for other ID types. */ | ||||
| object_preview_render(ip, cur_size); | object_preview_render(ip, cur_size); | ||||
| continue; | continue; | ||||
| } | } | ||||
| break; | break; | ||||
| case ID_GR: | |||||
| BLI_assert(collection_preview_contains_geometry_recursive((Collection *)ip->id)); | |||||
| /* A collection instance empty was created, so this can just reuse the object preview | |||||
| * rendering. */ | |||||
| object_preview_render(ip, cur_size); | |||||
| continue; | |||||
| case ID_AC: | case ID_AC: | ||||
| action_preview_render(ip, cur_size); | action_preview_render(ip, cur_size); | ||||
| continue; | continue; | ||||
| default: | default: | ||||
| /* Fall through to the same code as the `ip->id == nullptr` case. */ | /* Fall through to the same code as the `ip->id == nullptr` case. */ | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | bool ED_preview_id_is_supported(const ID *id) | ||||
| } | } | ||||
| if (GS(id->name) == ID_NT) { | if (GS(id->name) == ID_NT) { | ||||
| /* Node groups don't support standard preview generation. */ | /* Node groups don't support standard preview generation. */ | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (GS(id->name) == ID_OB) { | if (GS(id->name) == ID_OB) { | ||||
| return object_preview_is_type_supported((const Object *)id); | return object_preview_is_type_supported((const Object *)id); | ||||
| } | } | ||||
| if (GS(id->name) == ID_GR) { | |||||
| return collection_preview_contains_geometry_recursive((const Collection *)id); | |||||
| } | |||||
| return BKE_previewimg_id_get_p(id) != nullptr; | return BKE_previewimg_id_get_p(id) != nullptr; | ||||
| } | } | ||||
| void ED_preview_icon_render( | void ED_preview_icon_render( | ||||
| const bContext *C, Scene *scene, PreviewImage *prv_img, ID *id, eIconSizes icon_size) | const bContext *C, Scene *scene, PreviewImage *prv_img, ID *id, eIconSizes icon_size) | ||||
| { | { | ||||
| /* Deferred loading of previews from the file system. */ | /* Deferred loading of previews from the file system. */ | ||||
| if (prv_img->tag & PRV_TAG_DEFFERED) { | if (prv_img->tag & PRV_TAG_DEFFERED) { | ||||
| ▲ Show 20 Lines • Show All 232 Lines • Show Last 20 Lines | |||||