using System.Collections.Generic;
using UnityEngine;
namespace InteractiveVideo
{
///
/// Identity of a tracked thing in a video: who or what it is.
/// This never changes across frames. Per-frame state lives in .
///
public sealed class TrackedObject
{
/// Stable track id used by the frames, e.g. "person_01".
public string Id;
/// Category, e.g. "person" or "object".
public string Type;
/// Display name, e.g. "Father".
public string Name;
/// True when this definition was created because a frame referenced an id the file never declared.
public bool IsImplicit;
public override string ToString() => string.IsNullOrEmpty(Name) ? Id : $"{Name} ({Id})";
}
///
/// The state of one tracked object at one point in time: where it is and what it is doing.
/// Coordinates are TRACKING coordinates (normalised 0..1, Y down). Convert with .
/// Instances belonging to loaded frames are immutable in practice; the tracking manager also owns a pool of
/// instances it rewrites every frame when interpolating, so never cache a reference across frames.
///
public sealed class TrackedObjectInstance
{
public string TrackId;
/// Resolved identity. Never null after loading (an implicit definition is created for unknown ids).
public TrackedObject Definition;
/// Bounding box in tracking coordinates (xMin, yMin = top-left; Y grows downwards).
public Rect Bounds;
/// Polygon in tracking coordinates. Reused buffer; may have fewer than 3 points (then it is not hit-testable).
public readonly List Polygon = new List(64);
public bool Visible = true;
public bool Occluded;
public float Confidence = 1f;
/// Semantic per-frame information, e.g. "drinking water". May be null.
public string Action;
/// The video frame this state describes (the tracked frame, or the interpolated video frame).
public long Frame;
public bool HasPolygon => Polygon.Count >= 3;
public string Name => Definition != null && !string.IsNullOrEmpty(Definition.Name) ? Definition.Name : TrackId;
public void CopyFrom(TrackedObjectInstance other)
{
TrackId = other.TrackId;
Definition = other.Definition;
Bounds = other.Bounds;
Polygon.Clear();
Polygon.AddRange(other.Polygon);
Visible = other.Visible;
Occluded = other.Occluded;
Confidence = other.Confidence;
Action = other.Action;
Frame = other.Frame;
}
}
}