Beispiel #1
0
 private void OnHeadsetCalibrationUpdated(byte[] payload)
 {
     if (networkingService != null)
     {
         if (networkingService.SendData(payload, NetworkPriority.Critical))
         {
             Debug.Log($"Headset calibration data sent:{payload.Length} bytes");
         }
         else
         {
             Debug.LogWarning($"Failed to send payload:{payload.Length} bytes");
         }
     }
 }
        private void Update()
        {
            if (feedImage != null &&
                feedImage.texture == null)
            {
                feedImage.texture = CompositorWrapper.Instance.GetVideoCameraFeed();
            }

            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (networkingService != null &&
                    matchMakingService != null)
                {
                    var request = new HeadsetCalibrationDataRequest();
                    request.timestamp = Time.time;
                    var payload = request.Serialize();

                    if (networkingService.SendData(payload, NetworkPriority.Critical))
                    {
                        Debug.Log($"Sent headset calibration data request to HoloLens at {request.timestamp}");
                    }
                    else
                    {
                        Debug.LogWarning("Failed to send headset calibration data request to HoloLens");
                    }
                }

                if (headsetCalibration != null)
                {
                    Debug.Log("Requesting headset calibration data from VR Headset");
                    headsetCalibration.UpdateHeadsetCalibrationData();
                }
            }

            if (headsetData != null)
            {
                if (headsetData.markers.Count != expectedNumberOfMarkers)
                {
                    Debug.Log("Headset has not yet detected all of the markers on the calibration board, dropping payload from headset.");
                }
                else
                {
                    var dslrTexture = CompositorWrapper.Instance.GetVideoCameraTexture();
                    var fileName    = CalibrationDataHelper.GetUniqueFileName();
                    CalibrationDataHelper.SaveDSLRArUcoImage(dslrTexture, fileName);
                    CalibrationDataHelper.SaveHeadsetData(headsetData, fileName);

                    if (ProcessArUcoData(headsetData, dslrTexture))
                    {
                        CalibrationDataHelper.SaveDSLRArUcoDetectedImage(dslrTexture, fileName);
                        CreateVisual(headsetData, fileName);
                    }
                }

                headsetData = null;
            }

            if (Input.GetKeyDown(KeyCode.Return))
            {
                Debug.Log("Starting Individual Camera Extrinsics calculations.");
                cameraExtrinsics = CalibrationAPI.Instance.CalculateIndividualArUcoExtrinsics(dslrIntrinsics, parentVisuals.Count);
                if (cameraExtrinsics != null)
                {
                    foreach (var extrinsic in cameraExtrinsics)
                    {
                        Debug.Log($"Calculated extrinsics: {extrinsic}");
                    }
                    CreateExtrinsicsVisual(cameraExtrinsics);
                }

                Debug.Log("Starting the Global Camera Extrinsics calculation.");
                globalExtrinsics = CalibrationAPI.Instance.CalculateGlobalArUcoExtrinsics(dslrIntrinsics);
                if (globalExtrinsics != null)
                {
                    var fileName = CalibrationDataHelper.SaveCameraExtrinsics(globalExtrinsics);
                    Debug.Log($"Saved global extrinsics: {fileName}");
                    Debug.Log($"Found global extrinsics: {globalExtrinsics}");
                    var        position = globalExtrinsics.ViewFromWorld.GetColumn(3);
                    var        rotation = Quaternion.LookRotation(globalExtrinsics.ViewFromWorld.GetColumn(2), globalExtrinsics.ViewFromWorld.GetColumn(1));
                    GameObject camera   = null;
                    cameraVisualHelper.CreateOrUpdateVisual(ref camera, position, rotation);
                    camera.name = "Global Extrinsics";
                    GameObject hololens = null;
                    cameraVisualHelper.CreateOrUpdateVisual(ref hololens, Vector3.zero, Quaternion.identity);
                    hololens.name = "Global HoloLens";
                }
            }
        }