/// <summary> /// Adds a log entry for the given GameObject mentioning that the given event has happened. /// Useful for recording object-specific events, like button presses or collisions. /// Intended to be called asynchronously during recording by other classes. Events are not /// automatically tracked by the LogManager. /// /// Should only be called after recording has already started. /// </summary> /// <param name="obj">The object which received or triggered the event</param> /// <param name="eventName">The event name</param> /// <param name="property">Any related event parameters</param> public void LogEvent(GameObject obj, string eventName, string property) { if (!recording) { return; } LogEntry newEntry = new LogEntry(GetLogTime()); NewtonVR.NVRHand hand = obj.GetComponent <NewtonVR.NVRHand>(); Rigidbody rb = obj.GetComponentInChildren <Rigidbody>(); if (hand != null) { newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, hand.GetVelocityEstimation(), eventName, property); } else if (rb != null) { newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, rb.velocity, eventName, property); } else { newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, eventName, property); } AddLogEntry(newEntry); }
void FixedUpdate() { if (!Ready() || nohands) //ros == null || !ros.connected) { return; } ROSBridgeLib.ontology_msgs.HandUpdate left = new ROSBridgeLib.ontology_msgs.HandUpdate(); left.grasp = LeftHand.HoldButtonAxis; left.use = LeftHand.UseButtonAxis; if (LeftHand.CurrentlyInteracting != null) { left.obj_inHand = LeftHand.CurrentlyInteracting.gameObject.name; } else { left.obj_inHand = "NONE"; } left.handState = new ROSBridgeLib.ontology_msgs.ObjUpdate(); left.handState.timestamp = new ROSBridgeLib.msg_helpers.Time(ScenarioLogManager.Instance.GetLogTime()); left.handState.position = LeftHand.transform.position; left.handState.orientation = LeftHand.transform.rotation; left.handState.velocity = LeftHand.GetVelocityEstimation(); left.handState.name = LeftHand.gameObject.name; l_hand_pub.Publish(left); ROSBridgeLib.ontology_msgs.HandUpdate right = new ROSBridgeLib.ontology_msgs.HandUpdate(); right.grasp = RightHand.HoldButtonAxis; right.use = RightHand.UseButtonAxis; if (RightHand.CurrentlyInteracting != null) { right.obj_inHand = RightHand.CurrentlyInteracting.gameObject.name; } else { right.obj_inHand = "NONE"; } right.handState = new ROSBridgeLib.ontology_msgs.ObjUpdate(); right.handState.timestamp = new ROSBridgeLib.msg_helpers.Time(ScenarioLogManager.Instance.GetLogTime()); right.handState.position = RightHand.transform.position; right.handState.orientation = RightHand.transform.rotation; right.handState.velocity = RightHand.GetVelocityEstimation(); right.handState.name = RightHand.gameObject.name; r_hand_pub.Publish(right); }
/// <summary> /// Creates and saves a LogEntry for all currently tracked objects /// </summary> /// <param name="time">Current time to save with log entry</param> void LogObjects(float time) { LogEntry newEntry = new LogEntry(time); foreach (var obj in tracked_objs) { // hands do not report velocity through their RigidBody NewtonVR.NVRHand hand = obj.GetComponent <NewtonVR.NVRHand>(); if (hand != null) { newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, hand.GetVelocityEstimation()); continue; } // all other objects should have a normal velocity Rigidbody rb = obj.GetComponentInChildren <Rigidbody>(); if (rb != null) { newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, rb.velocity); } else { newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation); } } foreach (var hand in tracked_hands) { LogEvent(hand.gameObject, "HoldAxis", hand.HoldButtonAxis.ToString()); } AddLogEntry(newEntry); }