[Bf-blender-cvs] [52c32147765] blender-v3.4-release: Fix distortion regression test after recent commit

Sergey Sharybin noreply at git.blender.org
Thu Nov 17 17:51:15 CET 2022


Commit: 52c321477658d21fa9dc122df5d61c17a1ae6c17
Author: Sergey Sharybin
Date:   Thu Nov 17 17:34:20 2022 +0100
Branches: blender-v3.4-release
https://developer.blender.org/rB52c321477658d21fa9dc122df5d61c17a1ae6c17

Fix distortion regression test after recent commit

The 1a1341c38779 made it so that when ID's path changes the ID is
tagged for the source re-evaluation. Another factor here is that
there is a code in the read file which replaces alternative path
slash with the native one.

Typically it is not a problem since IDs are re-evaluated on load,
but the movie clip has the special handling on load to calculate
the image sequence length and initialize principal point.

This change makes it so that the principal point is only reset
when the clip resolution changes. This is something which is
also useful for cases when a non-centered primncipal point is
used and someone accidentally clicks on the clip reload button.
It is not really ideal but covers most of the common cases.
Ideally the principal point will be stored in relative or
normalized space.

The remaining part is that there is now extra image sequence
length calculation after file load. This needs more careful
look.

===================================================================

M	source/blender/blenkernel/intern/movieclip.c

===================================================================

diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index 58c3ef3bba0..1cc7a17ea01 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -937,15 +937,22 @@ static void movieclip_load_get_size(MovieClip *clip)
   user.framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, 1);
   BKE_movieclip_get_size(clip, &user, &width, &height);
 
-  if (width && height) {
-    clip->tracking.camera.principal[0] = ((float)width) / 2.0f;
-    clip->tracking.camera.principal[1] = ((float)height) / 2.0f;
-  }
-  else {
+  if (!width || !height) {
     clip->lastsize[0] = clip->lastsize[1] = IMG_SIZE_FALLBACK;
   }
 }
 
+static void movieclip_principal_to_center(MovieClip *clip)
+{
+  MovieClipUser user = *DNA_struct_default_get(MovieClipUser);
+
+  int width, height;
+  BKE_movieclip_get_size(clip, &user, &width, &height);
+
+  clip->tracking.camera.principal[0] = ((float)width) / 2.0f;
+  clip->tracking.camera.principal[1] = ((float)height) / 2.0f;
+}
+
 static void detect_clip_source(Main *bmain, MovieClip *clip)
 {
   ImBuf *ibuf;
@@ -995,6 +1002,7 @@ MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name)
     clip->tracking.camera.focal = 24.0f * width / clip->tracking.camera.sensor_width;
   }
 
+  movieclip_principal_to_center(clip);
   movieclip_calc_length(clip);
 
   return clip;
@@ -1672,11 +1680,26 @@ void BKE_movieclip_reload(Main *bmain, MovieClip *clip)
   /* update clip source */
   detect_clip_source(bmain, clip);
 
+  const int old_width = clip->lastsize[0];
+  const int old_height = clip->lastsize[1];
+
+  /* Tag for re-calculation of the actual size. */
   clip->lastsize[0] = clip->lastsize[1] = 0;
-  movieclip_load_get_size(clip);
 
+  movieclip_load_get_size(clip);
   movieclip_calc_length(clip);
 
+  int width, height;
+  MovieClipUser user = *DNA_struct_default_get(MovieClipUser);
+  BKE_movieclip_get_size(clip, &user, &width, &height);
+
+  /* If the resolution changes then re-initialize the principal point.
+   * Ideally the principal point will be in some sort of relative space, but this is not how it is
+   * designed currently. The code should cover the most of the common cases. */
+  if (width != old_width || height != old_height) {
+    movieclip_principal_to_center(clip);
+  }
+
   BKE_ntree_update_tag_id_changed(bmain, &clip->id);
 }



More information about the Bf-blender-cvs mailing list