Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-03-29 16:36:02 +0300
committerJulian Eisel <julian@blender.org>2022-03-29 16:37:22 +0300
commit810e225c260dfc2eac9c6b8bfd3271066dc0224b (patch)
tree78a3fdf108c080787b4ad34e1522d4f07f686afc /source/blender/editors/render/render_preview.cc
parent9ec77d709c3cd8cc6b210fd4c5fbf762bd18188e (diff)
Assets: Support automatic collection previews
Adds supports for collection previews that are rendered automatically when collections are marked as assets. (Or when preview rendering is triggered differently, e.g. through the //Refresh Data-Block Previews// operator). Idea in this patch is to create a collection instance empty outside of main for the collection, and then reuse the object rendering code to render the preview. This keeps things very simple and works just fine. Differential Revision: https://developer.blender.org/D14460 Reviewed by: Bastien Montagne
Diffstat (limited to 'source/blender/editors/render/render_preview.cc')
-rw-r--r--source/blender/editors/render/render_preview.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc
index ef0f0b6225c..7e01754bb3a 100644
--- a/source/blender/editors/render/render_preview.cc
+++ b/source/blender/editors/render/render_preview.cc
@@ -374,6 +374,14 @@ static ID *duplicate_ids(ID *id, const bool allow_failure)
LIB_ID_COPY_NO_ANIMDATA);
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. */
case ID_IM:
case ID_BR:
@@ -884,6 +892,42 @@ static void object_preview_render(IconPreview *preview, IconPreviewSize *preview
/** \} */
/* -------------------------------------------------------------------- */
+/** \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
* \{ */
@@ -1577,6 +1621,12 @@ static void icon_preview_startjob_all_sizes(void *customdata,
continue;
}
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:
action_preview_render(ip, cur_size);
continue;
@@ -1868,6 +1918,9 @@ bool ED_preview_id_is_supported(const ID *id)
if (GS(id->name) == ID_OB) {
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;
}