Ejemplo n.º 1
0
        void Start()
        {
            if (eyePerspective == null)
            {
                eyePerspective = GetComponent <Camera>();                    /*eyePerspective.aspect = aspectRatio;*/
            }
            if (deformer == null)
            {
                deformer = eyePerspective.transform.parent.GetComponent <CalibrationDeformer>();
            }

            //Set up job-elements
            meshVertices.Clear();
            meshUVs.Clear();
            //Full range = 0f - 1f
            for (float i = 0; i <= meshResolution.x; i++)
            {
                for (float j = 0; j <= meshResolution.y; j++)
                {
                    Vector2 RenderUV = new Vector2(i / meshResolution.x, j / meshResolution.y);
                    meshUVs.Add(RenderUV);
                }
            }
            rayUVs   = new NativeArray <Vector2>(meshUVs.ToArray(), Allocator.Persistent);
            vertices = new NativeArray <Vector3>(meshUVs.Count, Allocator.Persistent);

            ScheduleCreateDistortionMesh();
            Application.targetFrameRate = -1000;
        }
Ejemplo n.º 2
0
        void Start()
        {
            if (eyePerspective == null)
            {
                eyePerspective = GetComponent <Camera>(); eyePerspective.aspect = aspectRatio;
            }
            if (deformer == null)
            {
                deformer = eyePerspective.transform.parent.GetComponent <CalibrationDeformer>();
            }
            eyePerspective.aspect = aspectRatio;

            CreateDistortionMesh();
            Application.targetFrameRate = -1000;

            /*
             * StringBuilder builder = new StringBuilder();
             * builder.AppendLine("CameraU, CameraV, DisplayU, DisplayV");
             * for(int i = 0; i< meshUVs.Count; i++) {
             * //builder.AppendLine(meshUVs[i].x + ", " + meshUVs[i].y + ", " + meshVertices[i].x + ", " + meshVertices[i].y);
             * builder.AppendLine("[ [" + (meshVertices[i].y + 0.5f) + ", " + (meshVertices[i].x + 0.5f) + "], [" + meshUVs[i].x + "," + meshUVs[i].y + "] ],");
             * }
             *
             * File.WriteAllText(Directory.GetParent(Application.dataPath).FullName + "/ARReflectorHomography.csv", builder.ToString());*/
        }
        /// <summary>
        /// Loads the calibration file specified by the inputCalibrationFile field, which
        /// </summary>
        public void LoadCalibration()
        {
            if (!Application.isPlaying)
            {
                Debug.LogError("For safety, calibrations cannot be loaded at edit-time. "
                               + "Enter play mode to load a calibration.", this);
                return;
            }

            if (string.IsNullOrEmpty(inputCalibrationFile))
            {
                Debug.LogError("inputCalibrationFile field is null or empty; cannot load "
                               + "a calibration file.", this);
            }

            var inputFile = inputFilePath;

            if (File.Exists(inputFile))
            {
                string calibrationData = File.ReadAllText(inputFile);
                ListWrapper <CalibrationComponent> serializableList
                    = JsonUtility.FromJson <ListWrapper <CalibrationComponent> >(calibrationData);

                foreach (CalibrationComponent calib in serializableList.list)
                {
                    Transform componentTransform = calibratedComponents[calib.name];
                    componentTransform.localPosition = calib.localPose.position;
                    componentTransform.localRotation = calib.localPose.rotation;
                    componentTransform.localScale    = calib.localScale;

                    CalibrationDeformer deformer = componentTransform.GetComponent <CalibrationDeformer>();
                    if (deformer != null)
                    {
                        deformer.vertexIndices = calib.vertexIndices;
                        deformer.controlPoints = calib.controlPoints;
                    }
                }
                ARRaytracer[] raytracers = GetComponentsInChildren <ARRaytracer>();
                foreach (ARRaytracer raytracer in raytracers)
                {
                    raytracer.ScheduleCreateDistortionMesh();
                }

                Debug.Log("Headset calibration successfully loaded from " + inputCalibrationFile);
            }
            else
            {
                Debug.LogWarning("No calibration exists for: " + inputFile + "; no calibration "
                                 + "was loaded.");
            }
        }
        /// <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;
            }

            if (string.IsNullOrEmpty(outputCalibrationFile) || (!Application.isEditor))
            {
                outputCalibrationFile = "ARCalibration - " + Random.Range(0, 10000) + ".json";
                Debug.LogWarning("outputCalibrationFile was null or empty; defaulting to "
                                 + "'ARCalibration - XXXX.json'.", this);
            }

            List <CalibrationComponent> calibrationList = new List <CalibrationComponent>();

            foreach (var nameTransformPair in calibratedComponents)
            {
                var name      = nameTransformPair.Key;
                var transform = nameTransformPair.Value;

                CalibrationDeformer deformer = nameTransformPair.Value.GetComponent <CalibrationDeformer>();
                if (deformer == null)
                {
                    calibrationList.Add(new CalibrationComponent(name,
                                                                 transform.ToLocalPose(),
                                                                 transform.localScale));
                }
                else
                {
                    calibrationList.Add(new CalibrationComponent(name,
                                                                 transform.ToLocalPose(),
                                                                 transform.localScale,
                                                                 deformer.vertexIndices,
                                                                 deformer.controlPoints));
                }
            }

            var outputPath = outputFilePath;

            File.WriteAllText(outputPath,
                              JsonUtility.ToJson(new ListWrapper <CalibrationComponent>(calibrationList),
                                                 prettyPrint: true));
            Debug.Log("Saved current calibration to: " + outputPath);
        }