fix aspect_ratio other than 16:9 issue

This commit is contained in:
german2020 2023-08-27 13:51:54 +08:00
parent d8428585f8
commit 65e7943ff7
3 changed files with 25 additions and 6 deletions

View file

@ -13,7 +13,6 @@ import yaml
from manimlib.logger import log
from manimlib.utils.dict_ops import merge_dicts_recursively
from manimlib.utils.init_config import init_customization
from manimlib.constants import FRAME_HEIGHT
from typing import TYPE_CHECKING
if TYPE_CHECKING:
@ -473,7 +472,7 @@ def get_camera_config(args: Namespace, custom_config: dict) -> dict:
"pixel_width": width,
"pixel_height": height,
"frame_config": {
"frame_shape": ((width / height) * FRAME_HEIGHT, FRAME_HEIGHT),
"frame_shape": ((width / height) * get_frame_height(), get_frame_height()),
},
"fps": fps,
})
@ -520,3 +519,18 @@ def get_configuration(args: Namespace) -> dict:
"embed_exception_mode": custom_config["embed_exception_mode"],
"embed_error_sound": custom_config["embed_error_sound"],
}
def get_frame_height():
return 8.0
def get_aspect_ratio():
cam_config = get_camera_config(parse_cli(), get_custom_config())
return cam_config['pixel_width'] / cam_config['pixel_height']
def get_default_pixel_width():
cam_config = get_camera_config(parse_cli(), get_custom_config())
return cam_config['pixel_width']
def get_default_pixel_height():
cam_config = get_camera_config(parse_cli(), get_custom_config())
return cam_config['pixel_height']

View file

@ -1,6 +1,8 @@
from __future__ import annotations
import numpy as np
from manimlib.config import get_aspect_ratio,get_default_pixel_width,get_default_pixel_height,get_frame_height
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import List
@ -8,15 +10,15 @@ if TYPE_CHECKING:
# Sizes relevant to default camera frame
ASPECT_RATIO: float = 16.0 / 9.0
FRAME_HEIGHT: float = 8.0
ASPECT_RATIO: float = get_aspect_ratio()
FRAME_HEIGHT: float = get_frame_height()
FRAME_WIDTH: float = FRAME_HEIGHT * ASPECT_RATIO
FRAME_SHAPE: tuple[float, float] = (FRAME_WIDTH, FRAME_HEIGHT)
FRAME_Y_RADIUS: float = FRAME_HEIGHT / 2
FRAME_X_RADIUS: float = FRAME_WIDTH / 2
DEFAULT_PIXEL_HEIGHT: int = 1080
DEFAULT_PIXEL_WIDTH: int = 1920
DEFAULT_PIXEL_HEIGHT: int = get_default_pixel_height()
DEFAULT_PIXEL_WIDTH: int = get_default_pixel_width()
DEFAULT_FPS: int = 30
SMALL_BUFF: float = 0.1

View file

@ -9,6 +9,7 @@ import numpy as np
from manimlib.config import parse_cli
from manimlib.config import get_configuration
from manimlib.constants import ASPECT_RATIO
from manimlib.utils.directories import get_shader_dir
from manimlib.utils.file_ops import find_file
@ -112,6 +113,8 @@ def get_shader_code_from_file(filename: str) -> str | None:
with open(filepath, "r") as f:
result = f.read()
result = re.sub(r"\s+ASPECT_RATIO\s+=\s+[\s0-9/.]+", f" ASPECT_RATIO = {ASPECT_RATIO}", result)
# To share functionality between shaders, some functions are read in
# from other files an inserted into the relevant strings before