public void StartVisualizingGaze() { Instance.OnUpdate += VisualizeGaze; PupilSettings.Instance.currentCamera = Camera.main; if (!PupilMarker.TryToReset(_markerLeftEye)) { _markerLeftEye = new PupilMarker("LeftEye_2D", Color.green); } if (!PupilMarker.TryToReset(_markerRightEye)) { _markerRightEye = new PupilMarker("RightEye_2D", Color.blue); } if (!PupilMarker.TryToReset(_markerGazeCenter)) { _markerGazeCenter = new PupilMarker("Gaze_2D", Color.red); } if (!PupilMarker.TryToReset(_gaze3D)) { _gaze3D = new PupilMarker("Gaze_3D", Color.yellow); } PupilTools.DataProcessState = EStatus.ProcessingGaze; PupilTools.SubscribeTo("gaze"); }
public void StartVisualizingGaze() { Instance.OnUpdate += VisualizeGaze; PupilSettings.Instance.currentCamera = Camera.main; if (!PupilMarker.TryToReset(_markerLeftEye)) { _markerLeftEye = new PupilMarker("LeftEye_2D", PupilSettings.leftEyeColor); } if (!PupilMarker.TryToReset(_markerRightEye)) { _markerRightEye = new PupilMarker("RightEye_2D", PupilSettings.rightEyeColor); } if (!PupilMarker.TryToReset(_markerGazeCenter)) { _markerGazeCenter = new PupilMarker("Gaze_2D", Color.red); } if (!PupilMarker.TryToReset(_gaze3D)) { _gaze3D = new PupilMarker("Gaze_3D", Color.yellow); } PupilTools.IsGazing = true; PupilTools.SubscribeTo("gaze"); }
// Use this for initialization void Start() { //PupilSettings.Instance.currentCamera = Camera.main; settings = PupilSettings.Instance; if (GazePointLocation._Instance == null) { GazePointLocation._Instance = this; } var relativeRightEyePosition = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.RightEye) - UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye); PupilTools.Calibration.rightEyeTranslation = new float[] { relativeRightEyePosition.z *PupilSettings.PupilUnitScalingFactor, 0, 0 }; var relativeLeftEyePosition = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.LeftEye) - UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye); PupilTools.Calibration.leftEyeTranslation = new float[] { relativeLeftEyePosition.z *PupilSettings.PupilUnitScalingFactor, 0, 0 }; lEye = new PupilMarker("LeftEye", PupilSettings.leftEyeColor); rEye = new PupilMarker("RightEye", PupilSettings.rightEyeColor); gaze = new PupilMarker("Gaze", Color.yellow); marker = new PupilMarker("Marker", Color.red); print(rEye.name + " pos : " + rEye.position); print(lEye.name + " pos : " + lEye.position); print(gaze.name + " pos : " + gaze.position); print(marker.name + " pos : " + marker.position); RunConnect(); /*PupilTools.IsGazing = true; * PupilTools.SubscribeTo("gaze");*/ }
public static bool TryToReset(PupilMarker marker) { if (marker != null) { marker.camera = PupilTools.Settings.currentCamera; marker.gameObject.SetActive(true); return(true); } return(false); }
public void StopVisualizingGaze() { Instance.OnUpdate -= VisualizeGaze; PupilMarker.TryToSetActive(_markerLeftEye, false); PupilMarker.TryToSetActive(_markerRightEye, false); PupilMarker.TryToSetActive(_markerGazeCenter, false); PupilMarker.TryToSetActive(_gaze3D, false); PupilTools.IsIdle = true; // PupilTools.UnSubscribeFrom("gaze"); }
// public void Initialize(bool isActive) // { // gameObject = GameObject.Instantiate (Resources.Load<GameObject> ("MarkerObject")); // gameObject.name = this.name; // gameObject.GetComponent<MeshRenderer> ().material = new Material (Resources.Load<Material> ("MarkerMaterial")); // gameObject.GetComponent<MeshRenderer> ().material.SetColor ("_EmissionColor", this.color); // gameObject.SetActive (isActive); // gameObject.transform.parent = this.camera.transform; // // gameObject.hideFlags = HideFlags.HideInHierarchy; // } public static bool TryToSetActive(PupilMarker marker, bool toggle) { if (marker != null) { if (marker.gameObject != null) { marker.gameObject.SetActive(toggle); } return(true); } return(false); }
public void InitializeCalibration() { Debug.Log("Initializing Calibration"); currentCalibrationPoint = 0; currentCalibrationSamples = 0; currentCalibrationDepth = 0; if (!PupilMarker.TryToReset(Marker)) { Marker = new PupilMarker("Calibraton Marker", Color.white); } UpdateCalibrationPoint(); // yield return new WaitForSeconds (2f); Debug.Log("Starting Calibration"); }
public void showGaze() { PupilMarker.TryToSetActive(_markerGazeCenter, true); }
public void hideGaze() { PupilMarker.TryToSetActive(_markerGazeCenter, false); }
void Update() { if (PupilTools.IsConnected && PupilTools.IsGazing && (isTraining || isStudy)) { //timeManager time = new timeManager(); if (isStudy && !Lock) { //set target to next index //if no target set to false and save data if (currentOrder < 24) { Debug.Log("set random target for study"); targetclicker.setTargetActive(order[currentOrder]); currentOrder++; Lock = true; } else { isStudy = false; streamWriter.Close(); currentOrder = 0; return; } //save data } else if (isTraining && !Lock) { Debug.Log("set random target for training"); //random generate data int trainingIndex = UnityEngine.Random.Range(0, order.Length); targetclicker.setTargetActive(trainingIndex); Lock = true; } if (isRefining) { Vector2 deltaHead = this.transform.forward - lockHeadForward; gazePointCenter = lockCursor.camera.WorldToViewportPoint(lockEyeWorldPoint); lockCursor.UpdatePosition(gazePointCenter); headCursor.UpdatePosition(gazePointCenter + Vector2.Scale(scaler, deltaHead)); } else { gazePointCenter = PupilData._2D.GazePosition; } //missing head point streamWriter.WriteLine(gazePointCenter);//save in json if (Input.GetKeyDown(KeyCode.R)) { if (!isRefining) { Debug.Log("Enter refinement mode."); isRefining = true; lockHeadForward = this.transform.forward; PupilGazeTracker.Instance.hideGaze(); headCursor = new PupilMarker("Head", Color.blue); headCursor.UpdatePosition(gazePointCenter); lockCursor = new PupilMarker("Lock", Color.red); lockCursor.UpdatePosition(gazePointCenter); lockEyeWorldPoint = lockCursor.WorldPoint(); storedCameraRotation = Camera.main.transform.rotation; timeManager.myInstance.pressRefine(); streamWriter.WriteLine("enter refine:" + gazePointCenter); Debug.Log(gazePointCenter); } } else if (Input.GetKeyUp(KeyCode.R) && isRefining) { //Debug.Log(time.selectTime); Debug.Log("Exit refinement mode."); //write to Txt file streamWriter.WriteLine("exit refine:" + gazePointCenter); Debug.Log(gazePointCenter); // AssetDatabase.ImportAsset(path); // TextAsset asset = Resources.Load("test"); isRefining = false; PupilGazeTracker.Instance.showGaze(); PupilMarker.TryToSetActive(headCursor, false); PupilMarker.TryToSetActive(lockCursor, false); timeManager.myInstance.releaseRefine(); Lock = false; //send request to upload movement data } } //change condition if (Input.GetKey(KeyCode.Z) && !isStudy) { Debug.Log("switch to condition1"); conditionID = 0; path = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file fileStream = new FileStream(path, FileMode.Create); streamWriter = new StreamWriter(fileStream); isTraining = true; setCenter(); } else if (Input.GetKey(KeyCode.X) && !isStudy) { Debug.Log("switch to condition2"); conditionID = 1; path = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file fileStream = new FileStream(path, FileMode.Create); streamWriter = new StreamWriter(fileStream); isTraining = true; setCenter(); } else if (Input.GetKey(KeyCode.C) && !isStudy) { Debug.Log("switch to condition3"); conditionID = 2; path = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file fileStream = new FileStream(path, FileMode.Create); streamWriter = new StreamWriter(fileStream); isTraining = true; setCenter(); } else if (Input.GetKey(KeyCode.V) && !isStudy) { Debug.Log("switch to condition4"); conditionID = 3; path = "Assets/test" + idNum.ToString() + "_" + conditionID.ToString() + ".txt"; //txt save file fileStream = new FileStream(path, FileMode.Create); streamWriter = new StreamWriter(fileStream); isTraining = true; setCenter(); } else if (Input.GetKey(KeyCode.Space)) { if (isTraining) { isTraining = false; generateOrder(); isStudy = true; } } }