/// <summary>
        /// Call to attempt uploading the last calculated calibration data to a connected HoloLens device.
        /// </summary>
        public void UploadCalibrationData()
        {
            uploadResultMessage = string.Empty;
            if (lastCalibration == null)
            {
                Debug.LogWarning("Calibration isn't currently loaded, failed to upload calibration data");
                return;
            }

            if (holographicCameraObserver != null &&
                holographicCameraObserver.IsConnected)
            {
                using (MemoryStream memoryStream = new MemoryStream())
                    using (BinaryWriter writer = new BinaryWriter(memoryStream))
                    {
                        writer.Write(HeadsetCalibration.UploadCalibrationCommandHeader);
                        var payload = lastCalibration.Serialize();
                        writer.Write(payload.Length);
                        writer.Write(payload);
                        writer.Flush();
                        holographicCameraObserver.Broadcast(memoryStream.ToArray());
                        Debug.Log("Sent calibration data to the hololens device.");
                    }
            }
            else
            {
                Debug.LogWarning("HolographicCameraObserver isn't setup correctly, failed to request headset data.");
            }
        }
예제 #2
0
        public static string SaveCameraCalibration(CalculatedCameraCalibration calibration)
        {
            string path = Path.Combine(GetDocumentsFolderPath(), RootDirectoryName, $"CalibrationData.json");
            int    i    = 0;

            while (File.Exists(path))
            {
                path = Path.Combine(GetDocumentsFolderPath(), RootDirectoryName, $"CalibrationData_{i}.json");
                i++;
            }

            var payload = calibration.Serialize();

            File.WriteAllBytes(path, payload);
            return(path);
        }
        private void SendCalibrationData()
        {
            if (UnityCompositorInterface.IsCameraCalibrationInformationAvailable())
            {
                UnityCompositorInterface.GetCameraCalibrationInformation(out CompositorCameraIntrinsics compositorIntrinsics);
                CalculatedCameraCalibration calibration = new CalculatedCameraCalibration(compositorIntrinsics.AsCalculatedCameraIntrinsics(), new CalculatedCameraExtrinsics());
                byte[] serializedCalibration            = calibration.Serialize();

                using (MemoryStream memoryStream = new MemoryStream())
                    using (BinaryWriter message = new BinaryWriter(memoryStream))
                    {
                        message.Write("CalibrationData");
                        message.Write(serializedCalibration.Length);
                        message.Write(serializedCalibration);
                        memoryStream.TryGetBuffer(out var buffer);
                        networkManager.Broadcast(buffer.Array, buffer.Offset, buffer.Count);
                    }
            }
            else
            {
                Debug.LogError($"Expected that calibration data should be available when the {nameof(StationaryCameraCalibrationDataProvider)} component is enabled, but calibration data was not available");
            }
        }