feat: move_camera.txt 改为速度段格式驱动相机运动

格式:
  1-60   vx=1.0  rx=10         # 1-60帧:x平移1/帧 + 绕x转10°/帧
  30-90  vy=2.0  ry=20  rz=10  # 30-90帧:y平移2/帧 + 绕y转20°/帧 + 绕z转10°/帧

draw.py 每帧累加平移速度修改center,累加旋转速度修改
elevation/azimuth,实现连续平滑的相机运动。
This commit is contained in:
2026-06-12 07:58:08 +08:00
parent 22b94011ee
commit e40f7a49e4
4 changed files with 89 additions and 63 deletions
+16 -8
View File
@@ -33,7 +33,8 @@ def _fmt_alpha(v):
def _load_camera_kf(config, runtime_base):
"""加载 move_camera.txt → JSON 字符串,供 display.txt header 使用"""
"""加载 move_camera.txt(速度段格式)→ JSON 字符串。"""
import re, json
if not int(config.get("move_camera", 0)):
return ""
cam_file = str(config.get("move_camera_file",
@@ -43,18 +44,25 @@ def _load_camera_kf(config, runtime_base):
cam_path = os.path.join(runtime_base, cam_file)
if not os.path.exists(cam_path):
return ""
import json
kfs = []
segments = []
with open(cam_path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if not line or line.startswith("#"):
continue
parts = line.split()
if len(parts) >= 4:
kfs.append([int(parts[0]), float(parts[1]),
float(parts[2]), float(parts[3])])
return json.dumps(kfs) if kfs else ""
m = re.match(r'(\d+)\s*-\s*(\d+)', line)
if not m:
continue
start, end = int(m.group(1)), int(m.group(2))
v, r = [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]
for i, axis in enumerate(['x', 'y', 'z']):
m2 = re.search(r'v' + axis + r'\s*=\s*([-\d.]+)', line)
if m2: v[i] = float(m2.group(1))
m2 = re.search(r'r' + axis + r'\s*=\s*([-\d.]+)', line)
if m2: r[i] = float(m2.group(1))
if any(v) or any(r):
segments.append({"start": start, "end": end, "v": v, "r": r})
return json.dumps(segments) if segments else ""
def read_optional_index(data, key, default_value):