void OnApplicationFocus(bool focus) { var service = ObjectAnchorsService.GetService(); if (focus) { service.Resume(); if (GetComponent <ObjectSearch>().IsDiagnosticsCaptureEnabled) { TextLogger.Log("Start capture diagnostics."); service.StartDiagnosticsSession(); } } else { // Pause could block the UI for a very short time, application can put it // into a coroutine or background task. service.Pause(); // This method can run asynchronously if the Unity app supports background running. // Here we wait until the diagnostics data has been fully committed to the storage since this app // doesn't support background running. service.StopDiagnosticsSessionAsync().Wait(); } }
private void StopSearch() { ObjectAnchorsService.GetService().Pause(); StopSearchButton.gameObject.SetActive(false); StartSearchButton.gameObject.SetActive(true); _textToSpeech.Speak("Object tracking stopped."); }
private void Awake() { _objectAnchorsService = ObjectAnchorsService.GetService(); if (_objectAnchorsService == null) { Debug.LogError("Could not get AOA service"); Destroy(this); } }
private void StartSearch() { ObjectAnchorsService.GetService().Resume(); StopSearchButton.gameObject.SetActive(true); StartSearchButton.gameObject.SetActive(false); ToggleActiveObservationButton.IsEnabled = false; _textToSpeech.Speak("Object tracking started."); }
private void Awake() { _objectAnchorsService = ObjectAnchorsService.GetService(); _surfaceObserver = TryToGetObserver(); if (_surfaceObserver != null) { _surfaceObserver.Disable(); _surfaceObserver.DisplayOption = SpatialAwarenessMeshDisplayOptions.None; } _objectTracker = FindObjectOfType <ObjectTracker>(); }
public async Task <bool> LoadObjectModelsAsync(string modelPath) { IObjectAnchorsService objectAnchorsService = ObjectAnchorsService.GetService(); Debug.Log($"{Application.persistentDataPath} {objectAnchorsService != null}"); string[] ouFiles = Directory.GetFiles(modelPath, "*.ou", SearchOption.AllDirectories); foreach (var file in ouFiles) { // Represent a model by TrackableObject, and load its model into OU service. var trackableObject = new TrackableObjectData(); trackableObject.ModelFilePath = file.Replace('/', '\\'); string appPath = Application.persistentDataPath.Replace('/', '\\'); if (trackableObject.ModelFilePath.Contains(appPath)) { trackableObject.ModelId = await objectAnchorsService.AddObjectModelAsync(trackableObject.ModelFilePath); } else { #if WINDOWS_UWP byte[] buffer = await ReadFileBytesAsync(trackableObject.ModelFilePath); trackableObject.ModelId = await objectAnchorsService.AddObjectModelAsync(buffer); #endif // WINDOWS_UWP } if (trackableObject.ModelId != Guid.Empty) { trackableObject.ModelMesh = new Mesh(); await trackableObject.ModelMesh.SetFromObjectModel(trackableObject.ModelId); Debug.Log($"mesh has {trackableObject.ModelMesh.triangles.Length} indices"); trackableObject.logicalBoundingBox = objectAnchorsService.GetModelBoundingBox(trackableObject.ModelId); _trackableObjects.Add(trackableObject); _modelIdToTrackableObject.Add(trackableObject.ModelId, trackableObject); Debug.Log($"Loaded Model\n{trackableObject}"); } else { Debug.LogError($"failed to load model {trackableObject.ModelFilePath}"); } } if (_trackableObjects.Count > 0) { ModelsLoaded?.Invoke(this, EventArgs.Empty); } return(_trackableObjects.Count > 0); }
public static SystemMeshData FromObjectModel(Guid modelId) { #if UNITY_WSA var objectAnchorsService = ObjectAnchorsService.GetService(); return(new SystemMeshData() { Vertices = objectAnchorsService.GetModelVertexPositions(modelId), Normals = objectAnchorsService.GetModelVertexNormals(modelId), Indices = objectAnchorsService.GetModelTriangleIndices(modelId) }); #else return(new SystemMeshData()); #endif }
private void Start() { _mainCamera = Camera.main; // // Find bounding box components. // _searchAreaBboxManipulationHandler = GetComponent <ObjectManipulator>(); _searchAreaBboxManipulationHandler.OnManipulationEnded.AddListener(BoundingBoxMoved); _searchAreaBounds = GetComponent <BoundsControl>(); _objectAnchorsService = ObjectAnchorsService.GetService(); _trackableObjectDataLoader = TrackableObjectDataLoader.Instance; _trackableObjectDataLoader.ModelsLoaded += _trackableObjectDataLoader_ModelsLoaded; _automaticSearchAreaMovementController = GetComponent <AutonomousSearchArea>(); _searchAreaModelVisualization = GetComponentInChildren <SearchAreaModelVisualization>(); }
/// <summary> /// Generates a mesh from an Azure Object Anchors SDK model /// </summary> /// <param name="modelId">The id of the model to get the mesh for</param> /// <returns>A mesh with the requested model's geometry</returns> private Mesh GenerateMesh(Guid modelId) { IObjectAnchorsService objectAnchorsService = ObjectAnchorsService.GetService(); var vertices = objectAnchorsService.GetModelVertexPositions(modelId); int[] indices = (int[])(object)objectAnchorsService.GetModelTriangleIndices(modelId); Debug.Log($"mesh has {indices.Length} indices"); Mesh mesh = new Mesh(); Vector3[] unityVertices = new Vector3[vertices.Length]; for (int k = 0; k < vertices.Length; k++) { unityVertices[k] = vertices[k].ToUnity(); } mesh.vertices = unityVertices; if (unityVertices.Length > 65535) { mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; } if (indices != null && indices.Length > 2) { mesh.SetIndices(indices, MeshTopology.Triangles, 0); } else { int[] vertexIndices = new int[vertices.Length]; for (int k = 0; k < vertices.Length; k++) { vertexIndices[k] = k; } mesh.SetIndices(vertexIndices, MeshTopology.Points, 0); } mesh.RecalculateBounds(); mesh.RecalculateNormals(); return(mesh); }
public async Task <bool> LoadObjectModelsAsync(string modelPath) { IObjectAnchorsService objectAnchorsService = ObjectAnchorsService.GetService(); Debug.Log($"{Application.persistentDataPath} {objectAnchorsService != null}"); string[] ouFiles = Directory.GetFiles(modelPath, "*.ou", SearchOption.AllDirectories); foreach (var file in ouFiles) { // Represent a model by TrackableObject, and load its model into OU service. var trackableObject = new TrackableObjectData(); trackableObject.ModelFilePath = file.Replace('/', '\\'); trackableObject.ModelId = await objectAnchorsService.AddObjectModelAsync(trackableObject.ModelFilePath); if (trackableObject.ModelId != Guid.Empty) { // Query the default coverage threshold from this object model. ObjectQuery query = objectAnchorsService.CreateObjectQuery(trackableObject.ModelId); trackableObject.MinSurfaceCoverageFromObjectModel = query.MinSurfaceCoverage; trackableObject.ModelMesh = GenerateMesh(trackableObject.ModelId); trackableObject.logicalBoundingBox = objectAnchorsService.GetModelBoundingBox(trackableObject.ModelId); _trackableObjects.Add(trackableObject); _modelIdToTrackableObject.Add(trackableObject.ModelId, trackableObject); Debug.Log($"Loaded Model\n{trackableObject}"); } else { Debug.LogError($"failed to load model {trackableObject.ModelFilePath}"); } } if (_trackableObjects.Count > 0) { ModelsLoaded?.Invoke(this, EventArgs.Empty); } return(_trackableObjects.Count > 0); }
private void Start() { _objectAnchorsService = ObjectAnchorsService.GetService(); _objectTracker = FindObjectOfType <ObjectTracker>(); }
private void Awake() { _initialized = new ManualResetEvent(false); _objectAnchorsService = ObjectAnchorsService.GetService(); Debug.Assert(_objectAnchorsService != null); }
void Start() { _objectAnchorsService = ObjectAnchorsService.GetService(); _objectTracker = ObjectTracker.Instance; }
private void Awake() { _objectAnchorsService = ObjectAnchorsService.GetService(); AddObjectAnchorsListeners(); }