Allow camera distance to be fixed during Animation
See original GitHub issueThe code below produces a nice video file moving from a sagittal view to a front view. However, the interpolation from the starting point to the ending point causes the camera to seemingly zoom in and zoom out. This is different from the zoom feature, but I’m lacking the vocabulary to describe the effect as anything else. My goal is to interpolate from camera_1 to camera_2 while maintaining a fixed camera distance from the focal point.
from brainrender import Scene, Animation
from rich import print
from myterial import orange
from pathlib import Path
print(f"[{orange}]Running example: {Path(__file__).name}")
"""
This example shows how to create an animated video by specifying
the camera parameters at a number of key frames
"""
# Set custom camera positions
camera_1 = {
'pos': (7830, 4296, 36854),
'viewup': (0, -1, 0),
'clippingRange': (29305, 60266),
'focalPoint': (7830, 4296, -5694),
#'distance':
}
camera_2 = {
'pos': (-50378, 4296, -5694),
'viewup': (0, -1, 0),
'clippingRange': (29305, 60266),
'focalPoint': (7830, 4296, -5694),
#'distance':
}
# Create a brainrender scene
scene = Scene(title="brain regions", inset=False)
# Add brain regions
scene.add_brain_region("TH")
anim = Animation(scene, "./examples", "vid4")
# Specify camera position and zoom at some key frames
anim.add_keyframe(0, camera=camera_1 , zoom=1)
anim.add_keyframe(2, camera=camera_2 , zoom=1)
# Make videos
anim.make_video(duration=3, fps=15)
In the above code the focal point, camera_1, and camera_2 all have the same value for the second axis (4296), so for this example axis 2 is constrained and I will ignore it from hereon out. Camera_1 and the focal point are aligned on axis 1, and camera_2 and the focal point are aligned on axis 3. Thus, the distance between the focal point and camera_1 should be exactly the same as the distance between the focal point and camera_2 (see figure below).
In the example code above the distance between the camera and the focal point is continuously changing during the interpolation between camera_1 and camera_2 and appears to be following the path in red. My guess is that this red path is being controlled by the ‘interpol’ parameter in the add_keyframe function https://github.com/brainglobe/brainrender/blob/a6e92db7135a67944f1e961ce52a8bcaa7d33f10/brainrender/video.py#L203-L212 which by default calls the sigma function https://github.com/brainglobe/brainrender/blob/a6e92db7135a67944f1e961ce52a8bcaa7d33f10/brainrender/video.py#L158-L167 and could be altered by defining a different interpolation function, such as one that locks the distance between the camera and focal point. Am I on the right track?
Is there a way to fix the distance between the camera and focal point during interpolation?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Vedo
is the best! It’s such a rich library, great job!@blogeman perhaps one can use
Spline
andArc
to define fancy camera movements?Thanks, this is really useful info! I’m going to spend some time playing around and will let you know if I come up with anything that generally useful for other users.