using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Android; using Mediapipe.Unity; using Mediapipe.Unity.IrisTracking; using TMPro; using System.Linq; public class CameraController : MonoBehaviour { public IrisTrackingGraph irisTrackingGraph; public Transform camera; public TMP_Text text; public Vector2 leftEyeSize,rightEyeSize; IEnumerator Start() { Debug.Log("Start"); Permission.RequestUserPermission(Permission.Camera); while(!(ImageSourceProvider.ImageSource is var source && source && source.isPlaying)) yield return new WaitForEndOfFrame(); Debug.LogFormat("ImageSourceProvider.ImageSource : {0}",ImageSourceProvider.ImageSource); while(irisTrackingGraph._faceLandmarksWithIrisStream == null) yield return new WaitForEndOfFrame(); Debug.LogFormat("irisTrackingGraph : {0}",irisTrackingGraph._faceLandmarksWithIrisStream); irisTrackingGraph._faceLandmarksWithIrisStream.AddListener((sender,output) => { if(output?.value?.Landmark == null) { Debug.LogError("No landmark detected"); return; } var parts = FaceLandmarkListWithIrisAnnotation.PartitionLandmarkList(output.value.Landmark); if(parts.leftIris == null && parts.rightIris == null) { Debug.LogError("No iris detected"); return; } leftEyeSize = new Vector2(parts.leftIris.Distance(1,3).Value,parts.leftIris.Distance(2,4).Value); rightEyeSize = new Vector2(parts.rightIris.Distance(1,3).Value,parts.rightIris.Distance(2,4).Value); }); } WebCamSource webCamSource; void Update() { if(!webCamSource) webCamSource = GameObject.FindFirstObjectByType(); if(text && RelativeOffcenter.cameraCharacteristics?.Length > 0 && webCamSource?.webCamDevice?.isFrontFacing is bool facing) { var preferFacing = facing ? RelativeOffcenter.PreferFacing.Front : RelativeOffcenter.PreferFacing.Back; var cc = RelativeOffcenter.cameraCharacteristics.OrderBy((characteristics) => characteristics.preferFacing == preferFacing ? 0 : 1).First(); var eyeSize = 11.75f * Vector2.one; var dl = cc.DistanceMM(0,leftEyeSize * cc.SensorSizePx,eyeSize) / 1000; var dr = cc.DistanceMM(0,rightEyeSize * cc.SensorSizePx,eyeSize) / 1000; text.text = string.Join("\n", "L : " + leftEyeSize.ToString("0.0000"),"R : " + rightEyeSize.ToString("0.0000"),"DL : " + dl.ToString("0.0000"),"DR : " + dr.ToString("0.0000")); } } }