public void StopSolve()
 {
     if (solver != null)
     {
         calibration.StopAllCoroutines(); StopAllCoroutines(); solver = null;
     }
 }
예제 #2
0
        /// <summary>
        /// Outputs the current state of the headset as a calibration file based on the
        /// configured output file name into the configured calibrations folder.
        /// </summary>
        public void SaveCurrentCalibration()
        {
            if (!Application.isPlaying)
            {
                Debug.LogError("For safety, calibrations cannot be saved at edit-time. "
                               + "Enter play mode to save a calibration.", this);
                return;
            }

            int    randomNumber = UnityEngine.Random.Range(0, 10000);
            string temp         = outputCalibrationFile;

            if (string.IsNullOrEmpty(outputCalibrationFile) || (!Application.isEditor))
            {
                outputCalibrationFile = randomNumber + " - Temp Calibration.json";
                Debug.LogWarning("outputCalibrationFile was null or empty; defaulting to "
                                 + "'XXXX - Temp Calibration.json'.", this);
            }

            //If this is a calibrator scene, find the screen calibrator and optimizers and
            //stop the optimization process to allow us to reload the calibration we're saving
            Testing.WebcamScreenCalibration calibratorObject = FindObjectOfType <Testing.WebcamScreenCalibration>();
            if (calibratorObject != null)
            {
                calibratorObject.StopAllCoroutines();
                var optimizers = FindObjectsOfType <Testing.DenseOptimizer>();
                foreach (var optimizer in optimizers)
                {
                    optimizer.StopSolve();
                }
            }


            Pose devicePose;

            if (headTransform != null)
            {
                devicePose = headTransform.ToPose().inverse *
                             provider.deviceOrigin.ToPose();
            }
            else
            {
                devicePose = provider.deviceOrigin.ToLocalPose();
            }
            currentCalibration.leapTracker = new PhysicalComponent(
                devicePose,
                provider.gameObject.name
                );

            currentCalibration.leftEye  = constructLeftEyeOptics(false);
            currentCalibration.rightEye = constructRightEyeOptics(false);

            var outputPath = outputFilePath;

            File.WriteAllText(outputPath,
                              JsonUtility.ToJson(currentCalibration, prettyPrint: true)
                              .Replace("\n", "\r\n")
                              .Replace("    ", "  "));

            Debug.Log("Saved current calibration to: " + outputPath);

            inputCalibrationFile = outputCalibrationFile;
            LoadCalibration(disableEllipsoids: false, ignoreConfig: true);

            if (saveSteamVRStyleCalibration)
            {
                outputCalibrationFile = randomNumber + " - Temp SteamVR Calibration.vrsettings";
                var steamVROutputDirectory = Path.Combine(calibrationsFolder.Path,
                                                          "SteamVR/");
                if (!Directory.Exists(steamVROutputDirectory))
                {
                    Directory.CreateDirectory(steamVROutputDirectory);
                }
                outputPath = Path.Combine(steamVROutputDirectory, randomNumber + " - Temp SteamVR Calibration.vrsettings");

                SteamVRHeadsetCalibration steamVRCalib = new SteamVRHeadsetCalibration();
                steamVRCalib.leftEye  = currentCalibration.leftEye;
                steamVRCalib.rightEye = currentCalibration.rightEye;

                string steamVRJSON =
                    (SteamVROptics.getSteamVRPrefixString() +
                     JsonUtility.ToJson(steamVRCalib, prettyPrint: true)
                     .Substring(1)                 //(remove first bracket)
                     .Replace("\n", "\r\n"))
                    .Replace("    ", "  ");

                File.WriteAllText(outputPath, steamVRJSON);
                Debug.Log("Saved SteamVR calibration to: " + outputPath);
            }
            outputCalibrationFile = temp;
        }