private void Update() { if (_detecting) { #if UNITY_EDITOR int markerCount = UnityCompositorInterface.GetLatestArUcoMarkerCount(); if (compositorMarkers == null || compositorMarkers.Length < markerCount) { compositorMarkers = new CompositorMarker[markerCount]; } UnityCompositorInterface.GetLatestArUcoMarkers(markerCount, compositorMarkers); compositorMarkersToProcess.Clear(); for (int i = 0; i < markerCount; i++) { compositorMarkersToProcess.Add(compositorMarkers[i].id, compositorMarkers[i].AsMarker()); } ProcessMarkersFromFrame(compositorMarkersToProcess); #else if (_holoLensCamera.State == CameraState.Ready && !_holoLensCamera.TakeSingle()) { Debug.LogError("Failed to take photo with HoloLensCamera, Camera State: " + _holoLensCamera.State.ToString()); } #endif } if (_nextMarkerUpdate != null) { MarkersUpdated?.Invoke(_nextMarkerUpdate); _nextMarkerUpdate = null; } }
private void ProcessMarkerUpdates() { bool locatedAllMarkers = true; var markerDictionary = new Dictionary <int, Marker>(); lock (_contentLock) { foreach (var markerPair in _markerIds) { if (!_markerCoordinateSystems.ContainsKey(markerPair.Key)) { var coordinateSystem = SpatialGraphInteropPreview.CreateCoordinateSystemForNode(markerPair.Key.SpatialGraphNodeId); if (coordinateSystem != null) { _markerCoordinateSystems[markerPair.Key] = coordinateSystem; } } } foreach (var coordinatePair in _markerCoordinateSystems) { if (!_markerIds.TryGetValue(coordinatePair.Key, out var markerId)) { DebugLog($"Failed to locate marker:{coordinatePair.Key}, {markerId}"); locatedAllMarkers = false; continue; } if (_qrCodesManager.TryGetLocationForQRCode(coordinatePair.Value, out var location)) { var translation = location.GetColumn(3); // The obtained QRCode orientation will reflect a positive y axis down the QRCode. // Spectator view marker detectors should return a positive y axis up the marker, // so, we rotate the marker orientation 180 degrees around its z axis. var rotation = Quaternion.LookRotation(location.GetColumn(2), location.GetColumn(1)) * Quaternion.Euler(0, 0, 180); if (_markerSizes.TryGetValue(markerId, out var size)) { var transform = Matrix4x4.TRS(translation, rotation, Vector3.one); var offset = -1.0f * size / 2.0f; var markerCenter = transform.MultiplyPoint(new Vector3(offset, offset, 0)); var marker = new Marker(markerId, markerCenter, rotation); markerDictionary[markerId] = marker; } } } } if (markerDictionary.Count > 0 || locatedAllMarkers) { MarkersUpdated?.Invoke(markerDictionary); } // Stop processing markers once all markers have been located _processMarkers = !locatedAllMarkers; }
private void Update() { if (_detecting) { if (_holoLensCamera.State == CameraState.Ready && !_holoLensCamera.TakeSingle()) { Debug.LogError("Failed to take photo with HoloLensCamera, Camera State: " + _holoLensCamera.State.ToString()); } } if (_nextMarkerUpdate != null) { MarkersUpdated?.Invoke(_nextMarkerUpdate); _nextMarkerUpdate = null; } }
private void RefreshMarkers() { if (markerSequence == null) { RemoveMarkers(); return; } bool recolorAll = markerSequence != prevMarkerSequence; updatingMarkers = true; Selection.BeginUpdate(); int caret = SelectionStart; int maxDepth = -1; List <MarkerNode> highlightedMarkers = new List <MarkerNode>(); ClearStyle(recolorAll ? StyleIndex.All : highlightStyleIndex); foreach (MarkerNode node in markerSequence) { Marker marker = node.Marker; int depth = node.Depth; if (marker.HasIndex(caret)) { highlightedMarkers.Add(node); maxDepth = Math.Max(depth, maxDepth); } else { maxDepth = Math.Min(depth, maxDepth); } } if (recolorAll) { int colorIndex = 0; foreach (MarkerNode node in markerSequence) { Marker marker = node.Marker; SelectionStart = marker.IndexStart; SelectionLength = marker.Length; Selection.ClearStyle(StyleIndex.All); Selection.SetStyle(mainStyleIndex[colorIndex % mainStyleIndex.Length]); ++colorIndex; } } MarkerNode?newMarkerCaret = markerCaret; if (highlightedMarkers.Count > 0) { MarkerNode deepestNode = highlightedMarkers.Last(); Marker deepestMarker = deepestNode.Marker; SelectionStart = deepestMarker.IndexStart; SelectionLength = deepestMarker.Length; Selection.SetStyle(highlightStyleIndex); newMarkerCaret = deepestNode; } SelectionStart = caret; SelectionLength = 0; Selection.EndUpdate(); updatingMarkers = false; markerCaret = newMarkerCaret; MarkersUpdated?.Invoke(this, new MarkerUpdateEventArgs(MarkerTitle, MarkerRoot !, markerSequence, new HashSet <MarkerNode>(highlightedMarkers), markerCaret)); }