MultimodalData / player /world_trails.py
alinarus's picture
Upload folder using huggingface_hub (part 19)
9e18664 verified
Raw History Blame Contribute Delete
986 Bytes
"""portable_preview AC/RC trail rules: adjacent valid samples in the last five seconds."""
import numpy as np
COLORS = {'left': [255, 145, 45, 230], 'right': [70, 190, 255, 230],
'head': [133, 155, 170, 230]}
class RollingTrail:
def __init__(self, positions, times):
positions = np.asarray(positions)
self.times = np.asarray(times)
valid = np.isfinite(positions).all(axis=1)
# The original AC starts at end index 2 (frame 0 is not connected).
ends = np.arange(2, len(positions))
self.ends = ends[valid[ends - 1] & valid[ends]]
self.starts = self.ends - 1
self.start_times = self.times[self.starts]
self.segments = np.stack([positions[self.starts], positions[self.ends]], axis=1)
def window(self, frame):
begin = np.searchsorted(self.start_times, self.times[frame] - 5, side='left')
end = np.searchsorted(self.ends, frame, side='right')
return self.segments[begin:end]