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>2020-12-14 14:48:16 +0300
committerJulian Eisel <julian@blender.org>2020-12-14 15:17:57 +0300
commit4b0396695c622d1ac8669600fa820e80b1f0979f (patch)
tree0d7938ad051d727be476b416e40869a90e87731b /source/blender/editors/space_view3d/view3d_utils.c
parent732d0b458b6f9024b285747a643cacb128888b8c (diff)
UI/Assets: Support generating object preview images
Object previews are really helpful for visual data-block selection, like asset browsing. Having them be generative should also be quite handy and should work well enough in many, if not most cases. What this does is simple: * Place the object (actually a deep copy of it, for thread safety) in a virtual .blend into an empty scene/view-layer. * Add a camera, point it towards the front of the object, assuming that means pointing towards its +Y axis. * Use "Camera Fit Frame to Selected" logic to put the object into frame. * Create a threaded off-screen render. Of course, such an automatic preview will not work in all situations. E.g. it currently does a bad job capturing a single plane. We could add options for more advanced automatic previews, but probably custom previews is more important, which I committed already (812ea9184221). Part of the first Asset Browser milestone. Check the #asset_browser_milestone_1 project milestone on developer.blender.org. Reviewed as part of https://developer.blender.org/D9719. Reviewed by: Bastien Montagne, Brecht Van Lommel
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_utils.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_utils.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index 1be9bd27c7a..2b7b8255068 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -1620,6 +1620,41 @@ void ED_view3d_to_object(const Depsgraph *depsgraph,
BKE_object_apply_mat4_ex(ob, mat, ob_eval->parent, ob_eval->parentinv, true);
}
+bool ED_view3d_camera_to_view_selected(struct Main *bmain,
+ Depsgraph *depsgraph,
+ const Scene *scene,
+ Object *camera_ob)
+{
+ Object *camera_ob_eval = DEG_get_evaluated_object(depsgraph, camera_ob);
+ float co[3]; /* the new location to apply */
+ float scale; /* only for ortho cameras */
+
+ if (BKE_camera_view_frame_fit_to_scene(depsgraph, scene, camera_ob_eval, co, &scale)) {
+ ObjectTfmProtectedChannels obtfm;
+ float obmat_new[4][4];
+
+ if ((camera_ob_eval->type == OB_CAMERA) &&
+ (((Camera *)camera_ob_eval->data)->type == CAM_ORTHO)) {
+ ((Camera *)camera_ob->data)->ortho_scale = scale;
+ }
+
+ copy_m4_m4(obmat_new, camera_ob_eval->obmat);
+ copy_v3_v3(obmat_new[3], co);
+
+ /* only touch location */
+ BKE_object_tfm_protected_backup(camera_ob, &obtfm);
+ BKE_object_apply_mat4(camera_ob, obmat_new, true, true);
+ BKE_object_tfm_protected_restore(camera_ob, &obtfm, OB_LOCK_SCALE | OB_LOCK_ROT4D);
+
+ /* notifiers */
+ DEG_id_tag_update_ex(bmain, &camera_ob->id, ID_RECALC_TRANSFORM);
+
+ return true;
+ }
+
+ return false;
+}
+
/** \} */
/* -------------------------------------------------------------------- */