/// <summary> /// Starts up MLHandTracking. /// </summary> /// <param name="initializeValues">Bool that determines if MLHandTracking should automatically run with all poses and high filter levels.</param> public static MLResult Start(bool initializeValues = false) { #if PLATFORM_LUMIN MLResult _result = MLHandTracking.Start(); if (!_result.IsOk) { Debug.LogErrorFormat("Error: MLHandTrackingStarterKit failed starting MLHandTracking. Reason: {0}", _result); } if (initializeValues) { bool success = false; success = EnableKeyPoses(); if (!success) { MLHandTracking.Stop(); _result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLHandTrackingStarterKit failed to start correctly because MLHandTrackingStarterKit.EnablePoses failed because MLHandTracking.KeyPoseManager.EnableKeyPoses failed."); } success = SetKeyPointsFilterLevel(MLHandTracking.KeyPointFilterLevel.ExtraSmoothed); if (!success) { MLHandTracking.Stop(); _result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLHandTrackingStarterKit failed to start correctly because MLHandTrackingStarterKit.SetKeyPointsFilterLevel failed because MLHandTracking.KeyPoseManager.SetKeyPointsFilterLevel failed."); } success = SetPoseFilterLevel(MLHandTracking.PoseFilterLevel.ExtraRobust); if (!success) { MLHandTracking.Stop(); _result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLHandTrackingStarterKit failed to start correctly because MLHandTrackingStarterKit.SetPoseFilterLevel failed because MLHandTracking.KeyPoseManager.SetPoseFilterLevel failed."); } } return(_result); #else return(new MLResult()); #endif }
/** * Returns the GPS location from the paired CompanionApp phone/device. */ public async Task <LocationReply> GetLocation() { Logger.D(TAG, "GetLocation()"); if (!MLLocation.IsStarted) { Logger.D(TAG, "Please start MagicLeap's MLLocation object from a GameObject/MonoBehavior before using this call."); // Hm, Debug: return something. Logger.D(TAG, "FIXME: Returning a hard coded value..."); return(new LocationReply { longitude = -121.955238, latitude = 37.354107 }); } MLLocation.Location locData = new MLLocation.Location(); MLResult result = MLLocation.GetLastFineLocation(out locData); Logger.D(TAG, "MLLocation result: " + result); // Ensure location is allowed. if (!result.Equals(MLResult.Create(MLResult.Code.Ok))) { // Try coarse instead: result = MLLocation.GetLastCoarseLocation(out locData); if (!result.Equals(MLResult.Create(MLResult.Code.Ok))) { Logger.D(TAG, "Empty location returning"); return(new LocationReply { longitude = 0f, latitude = 0f }); } } Logger.D(TAG, "New location returning: {" + locData.Longitude + ", " + locData.Latitude + "}"); return(new LocationReply { longitude = locData.Longitude, latitude = locData.Latitude }); }
/// <summary> /// Used to check if your privilege has already been granted. /// </summary> /// <param name="privilege">The privilege to check for.</param> public static MLResult CheckPrivilege(MLPrivileges.Id privilege) { #if PLATFORM_LUMIN if (MLPrivileges.IsStarted) { _result = MLPrivileges.CheckPrivilege(privilege); if (_result.Result != MLResult.Code.PrivilegeGranted && _result.Result != MLResult.Code.PrivilegeNotGranted) { Debug.LogErrorFormat("Error: MLPrivilegesStarterKit.CheckPrivilege failed for the privilege {0}. Reason: {1}", privilege, _result); } } else { Debug.LogError("Error: MLPrivilegesStarterKit.CheckPrivilege failed because MLPrivileges was not started."); _result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPrivileges was not started"); } #endif return(_result); }
/// <summary> /// Function used to query for planes present in the real world. /// </summary> /// <param name="parameters">The parameters to use for this query.</param> /// <param name="callback">The function to call when the query is done.</param> public static MLResult QueryPlanes(MLPlanes.QueryParams parameters, MLPlanes.QueryResultsDelegate callback) { if (MLPlanes.IsStarted) { if (isQuerying) { return(MLResult.Create(MLResult.Code.UnspecifiedFailure, "A previous query is still in progress.")); } // Required flag by the CAPI, has to be set or errors will occur. parameters.Flags |= MLPlanes.QueryFlags.Polygons; // Planes can't have MinHoleLength less than 0.0. parameters.MinHoleLength = Mathf.Clamp(parameters.MinHoleLength, 0.0f, parameters.MinHoleLength); // Planes can't have MinPlaneArea less than 0.04. parameters.MinPlaneArea = Mathf.Clamp(parameters.MinHoleLength, 0.04f, parameters.MinPlaneArea); callback += _queryCallback; _result = MLPlanes.GetPlanes(parameters, callback); isQuerying = _result.IsOk; if (!_result.IsOk) { callback = null; Debug.LogErrorFormat("Error: MLPlanesStarterKit.QueryPlanes failed. Reason: {0}", _result); } } else { Debug.LogError("Error: MLPlanesStarterKit.QueryPlanes failed because MLPlanes was not started."); _result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPlanes was not started"); } return(_result); }
/// <summary> /// Request privileges asynchronously. /// </summary> ////<param name="callback">The method to call back once a result is known. It will be called when all privileges are granted or if requesting all privileges fails.</param> /// <param name="privileges">An array of privileges to request.</param> public static MLResult RequestPrivilegesAsync(Action <MLResult> callback, params MLPrivileges.Id[] privileges) { #if PLATFORM_LUMIN if (MLPrivileges.IsStarted) { int numPrivilegesToRequest = privileges.Length; for (int i = 0; i < privileges.Length; i++) { MLPrivileges.Id privilege = privileges[i]; _result = CheckPrivilege(privilege); if (_result.Result == MLResult.Code.PrivilegeGranted) { numPrivilegesToRequest--; if (numPrivilegesToRequest == 0) { callback?.Invoke(_result); } continue; } _result = MLPrivileges.RequestPrivilegeAsync(privilege, (MLResult result, MLPrivileges.Id priv) => { numPrivilegesToRequest--; if (result.Result == MLResult.Code.PrivilegeGranted) { if (numPrivilegesToRequest == 0) { callback?.Invoke(result); } } // Privilege was not granted else { numPrivilegesToRequest = 0; if (numPrivilegesToRequest == 0) { callback?.Invoke(result); } } }); if (!_result.IsOk) { return(_result); } } } else { Debug.LogError("Error: MLPrivilegesStarterKit.RequestPrivilegesAsync failed because MLPrivileges was not started."); _result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLPrivileges was not started"); } // Override result in case privilege was already granted. if (_result.Result == MLResult.Code.PrivilegeGranted) { _result = MLResult.Create(MLResult.Code.Ok); } #endif return(_result); }
public static MLResult Start() { return(MLResult.Create(MLResult.Code.Ok)); }
public static MLResult Start(MLImageTracker.Settings customSettings) { return(MLResult.Create(MLResult.Code.Ok)); }
/// <summary> /// Called by MLAPISingleton to start the API /// </summary> protected override MLResult StartAPI() { return(MLResult.Create(MLResult.Code.Ok)); }