public override IEnumerator StartDetection(GestureOption option) { #if VIVEHANDTRACKING_WITH_WAVEVR && !UNITY_EDITOR // retry at most 5 times if camera is not ready int count = 5; #else int count = 1; #endif while (count > 0) { State.Error = GestureInterface.StartGestureDetection(option); if (State.Error == GestureFailure.Camera && count > 1) { Debug.LogError("Start camera failed, retrying..."); yield return(new WaitForSeconds(0.5f)); count--; continue; } else if (State.Error != GestureFailure.None) { Debug.LogError("Start gesture detection failed: " + State.Error); State.Status = GestureStatus.Error; } else { State.Mode = option.mode; State.Status = GestureStatus.Starting; } break; } }
void Update() { if (Status == GestureStatus.NotStarted || Status == GestureStatus.Error) { return; } UpdatedInThisFrame = false; IntPtr ptr; int index; var size = GestureInterface.GetGestureResult(out ptr, out index); if (index < 0) { #if VIVEHANDTRACKING_WITH_WAVEVR WaveVR_Log.Log.e("Aristo", "Gesture detection stopped"); #else Debug.LogError("Gesture detection stopped"); #endif Status = GestureStatus.Error; Error = GestureFailure.Internal; return; } else if (Status == GestureStatus.Starting && index > 0) { Status = GestureStatus.Running; } if (index <= lastIndex) { return; } lastIndex = index; UpdatedInThisFrame = true; LeftHand = RightHand = null; if (size <= 0) { return; } var structSize = Marshal.SizeOf(typeof(GestureResultRaw)); for (var i = 0; i < size; i++) { var gesture = (GestureResultRaw)Marshal.PtrToStructure(ptr, typeof(GestureResultRaw)); ptr = new IntPtr(ptr.ToInt64() + structSize); for (int j = 0; j < 21; j++) { gesture.points[j] = transform.TransformPoint(gesture.points[j]); } if (gesture.isLeft) { LeftHand = new GestureResult(gesture); } else { RightHand = new GestureResult(gesture); } } }
public override void UpdateResult() { var transform = GestureProvider.Current.transform; GestureInterface.SetCameraTransform(transform.position, transform.rotation); IntPtr ptr; int index; var size = GestureInterface.GetGestureResult(out ptr, out index); if (index < 0) { Debug.LogError("Gesture detection stopped"); State.Status = GestureStatus.Error; State.Error = GestureFailure.Internal; return; } if (index <= lastIndex) { return; } lastIndex = index; State.UpdatedInThisFrame = true; State.LeftHand = State.RightHand = null; if (size <= 0) { return; } var structSize = Marshal.SizeOf(typeof(GestureResultRaw)); for (var i = 0; i < size; i++) { var gesture = (GestureResultRaw)Marshal.PtrToStructure(ptr, typeof(GestureResultRaw)); ptr = new IntPtr(ptr.ToInt64() + structSize); if (gesture.isLeft) { State.LeftHand = new GestureResult(gesture); } else { State.RightHand = new GestureResult(gesture); } } }
void StartGestureDetection() { if (Status == GestureStatus.Starting || Status == GestureStatus.Running) { return; } Error = GestureInterface.StartGestureDetection(option); if (Error != GestureFailure.None) { #if VIVEHANDTRACKING_WITH_WAVEVR WaveVR_Log.Log.e("Aristo", "Start gesture detection failed: " + Error); #else Debug.LogError("Start gesture detection failed: " + Error); #endif Status = GestureStatus.Error; } else { Mode = option.mode; HaveSkeleton = Mode == GestureMode.Skeleton; Status = GestureStatus.Starting; } }
IEnumerator Start() { Screen.sleepTimeout = SleepTimeout.NeverSleep; #if UNITY_ANDROID #if VIVEHANDTRACKING_WITH_WAVEVR // setup wavevr rendering if (transform.GetComponent <WaveVR_Render>() == null) { Destroy(transform.GetComponent <AudioListener>()); Destroy(transform.GetComponent <FlareLayer>()); gameObject.AddComponent <WaveVR_Render>(); var tracker = gameObject.AddComponent <WaveVR_DevicePoseTracker>(); #if VIVEHANDTRACKING_WITH_WAVEVR3 tracker.type = WaveVR_Controller.EDeviceType.Head; #else tracker.type = wvr.WVR_DeviceType.WVR_DeviceType_HMD; #endif } yield return(WaitForReady()); // get camera permission var pmInstance = WaveVR_PermissionManager.instance; while (!pmInstance.isInitialized()) { yield return(null); } bool granting = true; bool hasPermission = pmInstance.isPermissionGranted(permissionNames[0]); WaveVR_PermissionManager.requestCompleteCallback callback = (results) => { granting = false; if (results.Count > 0 && results[0].Granted) { hasPermission = true; } }; while (!hasPermission) { granting = true; pmInstance.requestPermissions(permissionNames, callback); while (granting) { yield return(null); } } #elif VIVEHANDTRACKING_WITH_GOOGLEVR // get camera permission using daydream API if (UnityEngine.VR.VRSettings.loadedDeviceName == "daydream") { var permissionRequester = GvrPermissionsRequester.Instance; bool granting = true; Action <GvrPermissionsRequester.PermissionStatus[]> callback = (results) => granting = false; while (!permissionRequester.IsPermissionGranted(permissionNames[0])) { granting = true; permissionRequester.RequestPermissions(permissionNames, callback); while (granting) { yield return(null); } } } #elif UNITY_2018_3_OR_NEWER // Unity 2018.3 or newer adds support for android runtime permission while (!Permission.HasUserAuthorizedPermission(Permission.Camera)) { Permission.RequestUserPermission(Permission.Camera); yield return(null); } #else while (!Application.HasUserAuthorization(UserAuthorization.WebCam)) { yield return(Application.RequestUserAuthorization(UserAuthorization.WebCam)); } #endif #endif GestureInterface.UseExternalTransform(true); // start detection StartGestureDetection(); initialized = true; yield break; }
void StopGestureDetection() { GestureInterface.StopGestureDetection(); ClearState(); }
public override IEnumerator Setup() { lastIndex = -1; var transform = GestureProvider.Current.transform; var gameObject = GestureProvider.Current.gameObject; #if UNITY_ANDROID && !UNITY_EDITOR #if VIVEHANDTRACKING_WITH_WAVEVR // get camera permission var pmInstance = WaveVR_PermissionManager.instance; while (!pmInstance.isInitialized()) { yield return(null); } bool granting = true; bool hasPermission = pmInstance.isPermissionGranted(permissionNames[0]); WaveVR_PermissionManager.requestCompleteCallback callback = (results) => { granting = false; if (results.Count > 0 && results[0].Granted) { hasPermission = true; } }; while (!hasPermission) { granting = true; pmInstance.requestPermissions(permissionNames, callback); while (granting) { yield return(null); } } #elif VIVEHANDTRACKING_WITH_GOOGLEVR // get camera permission using daydream API if (UnityEngine.VR.VRSettings.loadedDeviceName == "daydream") { var permissionRequester = GvrPermissionsRequester.Instance; bool granting = true; Action <GvrPermissionsRequester.PermissionStatus[]> callback = (results) => granting = false; while (!permissionRequester.IsPermissionGranted(permissionNames[0])) { granting = true; permissionRequester.RequestPermissions(permissionNames, callback); while (granting) { yield return(null); } } } #elif UNITY_2018_3_OR_NEWER // Unity 2018.3 or newer adds support for android runtime permission while (!Permission.HasUserAuthorizedPermission(Permission.Camera)) { Permission.RequestUserPermission(Permission.Camera); yield return(null); } #else while (!Application.HasUserAuthorization(UserAuthorization.WebCam)) { yield return(Application.RequestUserAuthorization(UserAuthorization.WebCam)); } #endif #endif GestureInterface.UseExternalTransform(true); yield break; }
public override void StopDetection() { GestureInterface.StopGestureDetection(); lastIndex = -1; }