コード例 #1
0
    /// <summary>
    /// Replaces all velocity values in a log file with estimates based on position data
    /// </summary>
    /// <param name="log">The log to hack</param>
    public static void HackVelocity(ref ScenarioLog log)
    {
        Dictionary <string, Vector3> prev_poses = new Dictionary <string, Vector3>();
        float prev_time = 0.0f;

        for (int i = 0; i < log.Count; i++)
        {
            float time_diff = 1.0f / (log.log[i].time - prev_time);
            foreach (var entry in log.log[i].logstep)
            {
                if (prev_poses.ContainsKey(entry.name))
                {
                    // figure new velocity
                    Vector3 pos_diff = new Vector3(entry.position[0], entry.position[1], entry.position[2]) - prev_poses[entry.name];

                    Vector3 velocity = pos_diff * time_diff;
                    entry.velocity[0] = velocity.x;
                    entry.velocity[1] = velocity.y;
                    entry.velocity[2] = velocity.z;
                }

                prev_poses[entry.name] = new Vector3(entry.position[0], entry.position[1], entry.position[2]);
            }

            prev_time = log.log[i].time;
        }
    }
コード例 #2
0
    protected ScenarioLogManager()
    {
        tracked_objs  = new List <GameObject>();
        tracked_hands = new List <NewtonVR.NVRHand>();
        subscribers   = new List <ScenarioLogSubscriber>();
        log           = new ScenarioLog();
        _recording    = false;

        UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneManager_sceneLoaded;
    }
コード例 #3
0
    /// <summary>
    /// Removes all entries for an object from a given log file
    /// </summary>
    /// <param name="objectName">Object to prune from log</param>
    /// <param name="inFile">File to read log from</param>
    /// <param name="outFile">File to write results to</param>
    public static void PruneObject(string objectName, string inFile, string outFile)
    {
        ScenarioLog log = load(inFile);

        // in case of errors reading inFile
        if (log == null)
        {
            return;
        }

        Debug.Log("Hacking '" + objectName + "' out of log...");
        PruneObject(objectName, ref log);

        save(outFile, ref log);
    }
コード例 #4
0
    /// <summary>
    /// Replaces all velocity values in a log file with estimates based on position data
    /// </summary>
    /// <param name="inFile">File to read log data from</param>
    /// <param name="outFile">File to write results to</param>
    public static void HackVelocity(string inFile, string outFile)
    {
        // clear any old log data
        ScenarioLog log = load(inFile);

        // in case of errors reading inFile
        if (log == null)
        {
            return;
        }

        Debug.Log("Hacking log velocities...");
        HackVelocity(ref log);

        save(outFile, ref log);
    }
コード例 #5
0
    /// <summary>
    /// Saves a log to a file
    /// </summary>
    /// <param name="filename">File to write log to</param>
    /// <param name="log">Log to save</param>
    private static void save(string filename, ref ScenarioLog log)
    {
        filename = filename.Replace("\"", "");

        Debug.Log("JSON-ifying log...");
        string total_log = JsonUtility.ToJson(log, true);

        Debug.Log("Writing results to output file: " + filename);
        string dirName = filename.Substring(0, filename.LastIndexOf('\\'));

        if (!System.IO.Directory.Exists(dirName))
        {
            Debug.Log("Creating directory: " + dirName);
            System.IO.Directory.CreateDirectory(dirName);
        }

        System.IO.File.WriteAllText(filename, total_log);

        Debug.Log("Results saved!");
    }
コード例 #6
0
    /// <summary>
    /// Removes all entries for an object from a given log file
    /// </summary>
    /// <param name="objectName">Object to prune from log</param>
    /// <param name="log">Log to remove object from</param>
    public static void PruneObject(string objectName, ref ScenarioLog log)
    {
        foreach (var logEntry in log.log)
        {
            List <int> delIndices = new List <int>();

            for (int i = 0; i < logEntry.logstep.Count; i++)
            {
                if (logEntry.logstep[i].name == objectName)
                {
                    delIndices.Add(i);
                }
            }

            if (delIndices.Count > 0)
            {
                for (int i = delIndices.Count - 1; i >= 0; i--)
                {
                    logEntry.logstep.RemoveAt(delIndices[i]);
                }
            }
        }
    }
コード例 #7
0
    /// <summary>
    /// Reads log data from file
    /// </summary>
    /// <param name="filename">File to read from</param>
    /// <returns></returns>
    private static ScenarioLog load(string filename)
    {
        filename = filename.Replace("\"", "");
        ScenarioLog log = new ScenarioLog();

        try
        {
            Debug.Log("Reading input log: " + filename);
            string log_data = System.IO.File.ReadAllText(filename);
            log = JsonUtility.FromJson <ScenarioLog>(log_data);
        }
        catch (System.IO.FileNotFoundException ex)
        {
            Debug.LogWarning("Could not find log file: '" + filename + "'\n" + ex.Message);
            return(null);
        }
        catch (System.Exception ex)
        {
            Debug.LogWarning("An exception was thrown while trying to read log file '" + filename + "':\n" + ex.Message);
            return(null);
        }

        return(log);
    }
コード例 #8
0
    public bool LoadLog(string filename)
    {
        // do not allow loading new logs during playback
        if (playing)
        {
            return(false);
        }

        log_filename = filename.Replace("\"", "");

        // clear any old log data
        log = new ScenarioLog();
        tracked_objs.Clear();
        events_to_clear.Clear();

        try
        {
            string log_data = System.IO.File.ReadAllText(log_filename);
            log = JsonUtility.FromJson <ScenarioLog>(log_data);
        }
        catch (System.IO.FileNotFoundException ex)
        {
            Debug.LogWarning("Could not find log file: '" + log_filename + "'\n" + ex.Message);
            return(false);
        }
        catch (System.Exception ex)
        {
            Debug.LogWarning("An exception was thrown while trying to read log file '" + log_filename + "':\n" + ex.Message);
            return(false);
        }

        Debug.Log("Playback found " + log.Count + " log entries~!");
        playbackState = LogPlaybackState.Stopped;

        // make playback player copy
        var              players = GameObject.FindObjectsOfType <NewtonVR.NVRPlayer>();
        GameObject       dupe;
        NullAvatarDriver nullDriver = FindObjectOfType <NullAvatarDriver>();


        dupe = nullDriver.gameObject;

        foreach (var player in players)
        {
            if (player != dupe)
            {
                ScenarioLogManager.Instance.UnTrack(player.LeftHand);
                ScenarioLogManager.Instance.UnTrack(player.LeftHand.gameObject);
                ScenarioLogManager.Instance.UnTrack(player.RightHand);
                ScenarioLogManager.Instance.UnTrack(player.RightHand.gameObject);

                player.gameObject.SetActive(false); // disable for now
            }
        }
        dupe.SetActive(true);
        ScenarioLogManager.Instance.Track(nullDriver.LeftHand);
        ScenarioLogManager.Instance.Track(nullDriver.RightHand);
        ScenarioLogManager.Instance.Track(nullDriver.LeftHand.gameObject);
        ScenarioLogManager.Instance.Track(nullDriver.RightHand.gameObject);

        if (OntologyManager.Instance != null)
        {
            OntologyManager.Instance.LeftHand  = nullDriver.LeftHand;
            OntologyManager.Instance.RightHand = nullDriver.RightHand;
        }

        // scan log entries & get references to all relevant transforms where possible
        // save 'null' for objects that don't exist in case they can be found later
        foreach (var entry in log.log)
        {
            foreach (var obj in entry.logstep)
            {
                if (!tracked_objs.ContainsKey(obj.name))
                {
                    Transform transform = FindTransform(obj.name);
                    if (transform == null)
                    {
                        Debug.Log("Could not find transform for: " + obj.name);
                    }

                    tracked_objs.Add(obj.name, transform);
                }
            }
        }

        // must do this AFTER gathering transforms to ensure we don't pick a real player obj up by mistake
        foreach (var player in players)
        {
            player.gameObject.SetActive(true); // re-enable objs we disabled
            foreach (var hand in player.Hands)
            {
                hand.gameObject.SetActive(true); // for some reason Steam disables hands when we disable the parent object above...
            }
        }

        return(true);
    }
コード例 #9
0
 void Start()
 {
     log             = new ScenarioLog();
     tracked_objs    = new Dictionary <string, Transform>();
     events_to_clear = new Dictionary <string, string>();
 }