private void UpdateGraphInfoOnCreation(string idCreated) { if (graphInfo == null) { graphInfo = new GraphInfo(); } RemoveOutdatedAnchorsFromGraph(); List <AnchorHandler> locatedAnchors = GetLocatedAnchors(); // The newly created anchor will always show isLocated = false, so we need to manually add it to the locatedAnchors list. AnchorHandler anchorHandler = existingAnchors[idCreated]; locatedAnchors.Add(anchorHandler); ResetLocatedNodes(locatedAnchors); UpdateOffsetList(locatedAnchors); updateNeighbourTask = UpdateNeighbourOnCreationAsync(anchorHandler); foreach (GraphNode node in graphInfo.Nodes.Values) { Debug.Log("Graph info updated:"); Debug.Log($"{node.AnchorId}: {node.OffsetList.Count}"); } SaveGraphInfo(); }
private AnchorHandler LoadAnchor(string id) { if (anchorStore == null) { Debug.Log("Anchor store hasn't been loaded."); return(null); } GameObject anchorGameObject = Instantiate <GameObject>(anchorGameObjectPrefab); AnchorHandler anchorHandler = anchorGameObject.GetComponent <AnchorHandler>(); GraphNode node; string anchorName = ""; if (graphInfo.Nodes.TryGetValue(id, out node)) { anchorName = node.AnchorName; } else { Debug.LogWarning($"Unable to find id: {id} in local database."); } anchorHandler.Initialize(id, anchorName); anchorStore.Load(id, anchorHandler.AnchorGameObject); return(anchorHandler); }
private void UpdateOffsetList(List <AnchorHandler> locatedAnchors) { int count = locatedAnchors.Count; for (int firstIndex = 0; firstIndex < count - 1; firstIndex++) { for (int secondIndex = firstIndex + 1; secondIndex < count; secondIndex++) { AnchorHandler first = locatedAnchors[firstIndex]; AnchorHandler second = locatedAnchors[secondIndex]; graphInfo.Nodes[first.AnchorId].OffsetList.Add( new Tuple <string, SerializableVector3>( second.AnchorId, new SerializableVector3(first.Anchor.transform.position - second.Anchor.transform.position))); graphInfo.Nodes[second.AnchorId].OffsetList.Add( new Tuple <string, SerializableVector3>( first.AnchorId, new SerializableVector3(second.Anchor.transform.position - first.Anchor.transform.position))); } } foreach (GraphNode node in graphInfo.Nodes.Values) { node.OffsetList.Sort((e1, e2) => e1.Item2.ToVector3().magnitude.CompareTo(e2.Item2.ToVector3().magnitude)); } }
public void UpdateNeighbours() { if (selectionManager.SingleSelectedObject == null) { return; } AnchorHandler master = selectionManager.SingleSelectedObject as AnchorHandler; List <string> previousNeighbourIds = GameMaster.Instance.GetNeighbourIds(master.AnchorId); foreach (string id in previousNeighbourIds) { GameMaster.Instance.GetNeighbourIds(id).Remove(master.AnchorId); } List <string> currentNeighbourIds = new List <string>(); foreach (ISelectableObject selectedObject in selectionManager.MultiSelectedObjects) { string neighbourId = ((AnchorHandler)selectedObject).AnchorId; currentNeighbourIds.Add(neighbourId); GameMaster.Instance.GetNeighbourIds(neighbourId).Add(master.AnchorId); } GameMaster.Instance.OverrideNeighbourIds(master.AnchorId, currentNeighbourIds); }
private WorldAnchor CreateAnchor() { if (anchorStore == null) { Debug.Log("Anchor store hasn't been loaded."); return(null); } if (updateNeighbourTask != null && !updateNeighbourTask.IsCompleted) { Debug.Log("Anchor creation task is not finished."); return(null); } string id = Guid.NewGuid().ToString(); Vector3 position = cameraTransform.TransformPoint(1.1f * Vector3.forward); GameObject anchorGameObject = Instantiate(anchorGameObjectPrefab, position, cameraTransform.rotation); anchorGameObject.transform.up = Vector3.up; AnchorHandler anchorHandler = anchorGameObject.GetComponent <AnchorHandler>(); anchorHandler.Initialize(id, ""); WorldAnchor anchor = anchorHandler.Anchor; anchorStore.Save(id, anchor); existingAnchors.Add(id, anchorHandler); Debug.Log($"Anchor {id} is created. Anchor count: {anchorStore.anchorCount}."); UpdateGraphInfoOnCreation(id); return(anchor); }
private void OnAnchorStoreLoaded(WorldAnchorStore store) { anchorStore = store; if (clearAnchorOnStart) { anchorStore.Clear(); if (graphInfo == null) { graphInfo = new GraphInfo(); } else { graphInfo.Reset(); } Debug.Log("All anchors are cleared."); return; } string[] anchorIds = anchorStore.GetAllIds(); foreach (string id in anchorIds) { AnchorHandler anchorHandler = LoadAnchor(id); existingAnchors.Add(id, anchorHandler); anchorHandler.Anchor.OnTrackingChanged += OnAnchorTrackingChanged; Debug.Log($"Anchor {id} isLocated: {anchorHandler.Anchor.isLocated}"); } Debug.Log($"Anchor Store loaded. Current Ids: {string.Join(", ", anchorIds)}."); }
public PathNode(AnchorHandler handler) { IsVisited = false; AnchorHandler = handler; ActualWeight = float.MaxValue; HeuristicWeight = float.MaxValue; Parent = null; }
public void ShowNeighbour(AnchorHandler selectedAnchor) { if (selectionManager.SingleSelectedObject == selectedAnchor) { return; } Reset(); selectionManager.SingleSelect(selectedAnchor); List <string> neighbourIds = GameMaster.Instance.GetNeighbourIds(selectedAnchor.AnchorId); foreach (string neighbourId in neighbourIds) { AnchorHandler neighbour = GameMaster.Instance.ExistingAnchors[neighbourId]; selectionManager.MultiSelect(neighbour); } }
public void OnPointerClicked() { if (CurrentGameMode == GameMode.Editing) { GameObject target = gazeProvider.GazeTarget; if (CurrentEditingAction == EditingAction.PlaceAnchor) { if (target != null && target.GetComponent <IMixedRealityFocusHandler>() != null) { return; } if (target == null || Vector3.Distance(target.transform.position, cameraTransform.position) > 1) { CreateAnchor(); } } else { if (target == null) { return; } AnchorHandler selectedAnchor = target.GetComponentInParent <AnchorHandler>(); if (selectedAnchor == null) { return; } if (CurrentEditingAction == EditingAction.ShowNeighbours) { neighbourManager.ShowNeighbour(selectedAnchor); } else if (CurrentEditingAction == EditingAction.OverrideNeighbours) { neighbourManager.OverrideNeighbourSelect(selectedAnchor); } } } }
public void OverrideNeighbourSelect(AnchorHandler selectedAnchor) { if (!overridenNeighbourMasterSelected) { // Select the main anchor to modify Reset(); selectionManager.SingleSelect(selectedAnchor); overridenNeighbourMasterSelected = true; } else { // Select the overriden neighbours if (selectedAnchor == selectionManager.SingleSelectedObject) { return; } selectionManager.MultiSelect(selectedAnchor); } }
private void DeducePosition() { List <Tuple <string, SerializableVector3> > offsetList = GameMaster.Instance.GetOffsetList(AnchorId); if (offsetList == null) { TrackingState = AnchorTrackingState.Lost; return; } int count = Math.Min(offsetList.Count, offsetDeductionLimit); Vector3 average = Vector3.zero; int otherAnchorNumber = 0; for (int index = 0; index < count; index++) { string otherId = offsetList[index].Item1; AnchorHandler otherAnchorHandler = GameMaster.Instance.GetAnchorHandler(otherId); if (otherAnchorHandler.TrackingState != AnchorTrackingState.Lost) { Vector3 offset = offsetList[index].Item2.ToVector3(); average += otherAnchorHandler.AnchorVisualTransform.position + offset; otherAnchorNumber++; } } if (otherAnchorNumber > 0) { average /= otherAnchorNumber; anchorVisual.transform.position = average; TrackingState = AnchorTrackingState.LocationDeduced; } else { TrackingState = AnchorTrackingState.Lost; } }
private async Task UpdateNeighbourOnCreationAsync(AnchorHandler anchorHandler) { await Task.Delay(TimeSpan.FromSeconds(spatialMeshObserver.UpdateInterval)); List <string> neighbourIds = new List <string>(); Vector3 anchorPosition = anchorHandler.AnchorVisualTransform.position; float observerBoundDistance = spatialMeshObserver.ObservationExtents.x; List <AnchorHandler> surroundingAnchors = new List <AnchorHandler>(); foreach (AnchorHandler otherAnchorHandler in existingAnchors.Values) { if (otherAnchorHandler.AnchorId == anchorHandler.AnchorId || otherAnchorHandler.TrackingState == AnchorTrackingState.Lost || Vector3.Distance(otherAnchorHandler.AnchorVisualTransform.position, anchorPosition) > observerBoundDistance) { continue; } surroundingAnchors.Add(otherAnchorHandler); } const float verticalMaxDistance = 100f; const float raycastOriginOffset = 0.5f; int layerMask = spatialMeshObserver.MeshPhysicsLayerMask; bool raycastBottom = true; bool raycastTop = true; RaycastHit hitFloor; if (Physics.Raycast(anchorPosition, Vector3.down, out hitFloor, verticalMaxDistance, layerMask, QueryTriggerInteraction.Ignore)) { raycastBottom = hitFloor.distance > raycastOriginOffset; } RaycastHit hitCeiling; if (Physics.Raycast(anchorPosition, Vector3.up, out hitCeiling, verticalMaxDistance, layerMask, QueryTriggerInteraction.Ignore)) { raycastTop = hitFloor.distance > raycastOriginOffset; } foreach (AnchorHandler otherAnchorHandler in surroundingAnchors) { Vector3 direction = otherAnchorHandler.AnchorVisualTransform.position - anchorPosition; if (raycastBottom) { Vector3 bottomPosition = anchorPosition + Vector3.down * raycastOriginOffset; if (CheckNodesBlocked(bottomPosition, direction, layerMask)) { continue; } } if (raycastTop) { Vector3 topPosition = anchorPosition + Vector3.up * raycastOriginOffset; if (CheckNodesBlocked(topPosition, direction, layerMask)) { continue; } } if (CheckNodesBlocked(anchorPosition, direction, layerMask)) { continue; } neighbourIds.Add(otherAnchorHandler.AnchorId); GraphNode otherNode = graphInfo.Nodes[otherAnchorHandler.AnchorId]; if (otherNode.NeighbourIds == null) { otherNode.NeighbourIds = new List <string>(); } otherNode.NeighbourIds.Add(anchorHandler.AnchorId); } graphInfo.Nodes[anchorHandler.AnchorId].NeighbourIds = neighbourIds; SaveGraphInfo(); }
private void OnAnchorTrackingChanged(WorldAnchor worldAnchor, bool located) { AnchorHandler handler = worldAnchor.GetComponentInParent <AnchorHandler>(); Debug.Log($"Anchor {handler.AnchorId} located: {located}."); }