ww_index: window list, captions, lags and scripts to rebuild the WildWorld windows from upstream
a54e6a7 verified Download ww_index/scripts/proxykit36/proxykit/cameras.py from yuzhewu207/wizard-precoded: direct link, hf CLI and curl.
- Browser
- Download file 2.6 kB
-
https://huggingface.co/datasets/yuzhewu207/wizard-precoded/resolve/main/ww_index/scripts/proxykit36/proxykit/cameras.py
- Command line
-
hf download hf://datasets/yuzhewu207/wizard-precoded/ww_index/scripts/proxykit36/proxykit/cameras.py
-
curl -L -o cameras.py https://huggingface.co/datasets/yuzhewu207/wizard-precoded/resolve/main/ww_index/scripts/proxykit36/proxykit/cameras.py
2.6 kB
| """Camera tracks for combat shots: third-person follow behind the player facing the monster (the BOSSV2V training | |
| view), and a transition that orbits from any start camera (e.g. the first-frame view) into the follow camera.""" | |
| import numpy as np | |
| from .geometry import Camera, UP | |
| from .motion import ease | |
| flat = lambda v: np.array([v[0], v[1], 0.0]) | |
| def follow_behind_raw(scene, player, subject, t, dist=450.0, height=210.0, shoulder=60.0, look=0.5, look_z=120.0): | |
| p = scene.entities[player]["track"].poses[t, 0]; s = scene.entities[subject]["track"].poses[t, 0] | |
| d = flat(s - p); d = d / np.linalg.norm(d) | |
| right = np.array([-d[1], d[0], 0.0]) # UE: +Y is right of +X | |
| pos = flat(p) - d * dist + right * shoulder + UP * height | |
| target = flat(p) * (1 - look) + flat(s) * look + UP * look_z | |
| return pos, target | |
| def _smooth(xs, alpha): | |
| out = np.array(xs, float) | |
| for i in range(1, len(out)): | |
| out[i] = out[i - 1] + alpha * (out[i] - out[i - 1]) | |
| return out | |
| def orbit_into_follow(scene, start_cam, t0, t1, player, subject, smooth=0.25, fov=None, **follow_kw): | |
| """Frames < t0 keep start_cam; [t0, t1) orbit around the player (angle, radius, height and aim eased) from the | |
| start view to the follow view; frames >= t1 follow behind the player (exponentially smoothed).""" | |
| T = scene.frames | |
| raw = [follow_behind_raw(scene, player, subject, t, **follow_kw) for t in range(T)] | |
| pos = _smooth([r[0] for r in raw], smooth); tgt = _smooth([r[1] for r in raw], smooth) | |
| fov = fov if fov is not None else start_cam.fov | |
| p_track = scene.entities[player]["track"] | |
| s_pos = np.asarray(start_cam.position, float) | |
| s_dist = np.linalg.norm(flat(p_track.poses[t0, 0] - s_pos)) | |
| s_tgt = s_pos + start_cam.R[:, 0] * s_dist | |
| cams = [] | |
| for t in range(T): | |
| if t < t0: | |
| cams.append(start_cam); continue | |
| if t >= t1: | |
| cams.append(Camera.look_at(pos[t], tgt[t], fov)); continue | |
| u = ease((t - t0) / max(1, t1 - t0)) | |
| c = flat(p_track.poses[t, 0]) | |
| a0 = s_pos - c; a1 = pos[t] - c | |
| th0, th1 = np.arctan2(a0[1], a0[0]), np.arctan2(a1[1], a1[0]) | |
| dth = (th1 - th0 + np.pi) % (2 * np.pi) - np.pi | |
| th = th0 + dth * u | |
| r = np.linalg.norm(a0[:2]) * (1 - u) + np.linalg.norm(a1[:2]) * u | |
| z = s_pos[2] * (1 - u) + pos[t][2] * u | |
| p = c + np.array([np.cos(th) * r, np.sin(th) * r, 0.0]); p[2] = z | |
| aim = s_tgt * (1 - u) + tgt[t] * u | |
| cams.append(Camera.look_at(p, aim, fov)) | |
| scene.cameras = cams | |
| return cams | |