mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Allow for setting a default frame orientation
This commit is contained in:
parent
a1449def95
commit
5deef1c249
2 changed files with 23 additions and 2 deletions
|
@ -29,6 +29,7 @@ class CameraFrame(Mobject):
|
||||||
self.center_point = center_point
|
self.center_point = center_point
|
||||||
self.focal_dist_to_height = focal_dist_to_height
|
self.focal_dist_to_height = focal_dist_to_height
|
||||||
self.view_matrix = np.identity(4)
|
self.view_matrix = np.identity(4)
|
||||||
|
self.default_orientation = Rotation.identity()
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
def init_uniforms(self) -> None:
|
def init_uniforms(self) -> None:
|
||||||
|
@ -50,11 +51,15 @@ class CameraFrame(Mobject):
|
||||||
def get_orientation(self):
|
def get_orientation(self):
|
||||||
return Rotation.from_quat(self.uniforms["orientation"])
|
return Rotation.from_quat(self.uniforms["orientation"])
|
||||||
|
|
||||||
|
def make_orientation_default(self):
|
||||||
|
self.default_orientation = self.get_orientation()
|
||||||
|
return self
|
||||||
|
|
||||||
def to_default_state(self):
|
def to_default_state(self):
|
||||||
self.center()
|
self.center()
|
||||||
self.set_height(FRAME_HEIGHT)
|
self.set_height(FRAME_HEIGHT)
|
||||||
self.set_width(FRAME_WIDTH)
|
self.set_width(FRAME_WIDTH)
|
||||||
self.set_orientation(Rotation.identity())
|
self.set_orientation(self.default_orientation)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_euler_angles(self):
|
def get_euler_angles(self):
|
||||||
|
@ -101,7 +106,11 @@ class CameraFrame(Mobject):
|
||||||
for i, var in enumerate([theta, phi, gamma]):
|
for i, var in enumerate([theta, phi, gamma]):
|
||||||
if var is not None:
|
if var is not None:
|
||||||
eulers[i] = var * units
|
eulers[i] = var * units
|
||||||
self.set_orientation(Rotation.from_euler("zxz", eulers[::-1]))
|
if all(eulers == 0):
|
||||||
|
rot = Rotation.identity()
|
||||||
|
else:
|
||||||
|
rot = Rotation.from_euler("zxz", eulers[::-1])
|
||||||
|
self.set_orientation(rot)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def reorient(
|
def reorient(
|
||||||
|
|
|
@ -18,6 +18,7 @@ from tqdm.auto import tqdm as ProgressDisplay
|
||||||
from manimlib.animation.animation import prepare_animation
|
from manimlib.animation.animation import prepare_animation
|
||||||
from manimlib.animation.fading import VFadeInThenOut
|
from manimlib.animation.fading import VFadeInThenOut
|
||||||
from manimlib.camera.camera import Camera
|
from manimlib.camera.camera import Camera
|
||||||
|
from manimlib.camera.camera_frame import CameraFrame
|
||||||
from manimlib.config import get_module
|
from manimlib.config import get_module
|
||||||
from manimlib.constants import ARROW_SYMBOLS
|
from manimlib.constants import ARROW_SYMBOLS
|
||||||
from manimlib.constants import DEFAULT_WAIT_TIME
|
from manimlib.constants import DEFAULT_WAIT_TIME
|
||||||
|
@ -63,6 +64,8 @@ class Scene(object):
|
||||||
default_window_config: dict = dict()
|
default_window_config: dict = dict()
|
||||||
default_file_writer_config: dict = dict()
|
default_file_writer_config: dict = dict()
|
||||||
samples = 0
|
samples = 0
|
||||||
|
# Euler angles, in degrees
|
||||||
|
default_frame_orientation = (0, 0)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -108,6 +111,10 @@ class Scene(object):
|
||||||
|
|
||||||
# Core state of the scene
|
# Core state of the scene
|
||||||
self.camera: Camera = Camera(**self.camera_config)
|
self.camera: Camera = Camera(**self.camera_config)
|
||||||
|
self.frame: CameraFrame = self.camera.frame
|
||||||
|
self.frame.reorient(*self.default_frame_orientation)
|
||||||
|
self.frame.make_orientation_default()
|
||||||
|
|
||||||
self.file_writer = SceneFileWriter(self, **self.file_writer_config)
|
self.file_writer = SceneFileWriter(self, **self.file_writer_config)
|
||||||
self.mobjects: list[Mobject] = [self.camera.frame]
|
self.mobjects: list[Mobject] = [self.camera.frame]
|
||||||
self.id_to_mobject_map: dict[int, Mobject] = dict()
|
self.id_to_mobject_map: dict[int, Mobject] = dict()
|
||||||
|
@ -971,3 +978,8 @@ class SceneState():
|
||||||
|
|
||||||
class EndScene(Exception):
|
class EndScene(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ThreeDScene(Scene):
|
||||||
|
samples = 4
|
||||||
|
default_frame_orientation = (-30, 70)
|
||||||
|
|
Loading…
Add table
Reference in a new issue