/// <summary>
 /// Loads the processed focal surface meshes for play.
 /// </summary>
 /// <returns></returns>
 public IEnumerator LoadProcessedFocalSurfacesCoroutine()
 {
     CameraModel[] cameraModels = cameraSetup.cameraModels;
     meshTransforms = new Transform[cameraModels.Length];
     // Check that the application is playing.
     if (!Application.isPlaying)
     {
         yield break;
     }
     // Only continue if there are source images.
     if (cameraModels.Length > 0)
     {
         // Create a gameobject for the geometric data, and set it as a child of this transform.
         Transform geometricDataTransform = new GameObject("Geometric data").transform;
         geometricDataTransform.parent = dataHandler.transform;
         // For each source image, check whether to load the quad or the sphere focal surface.
         Mesh   quadFocalSurface    = null;
         Mesh   sphereFocalSurface  = null;
         string bundledAssetsPrefix = DataHandler.GetBundledAssetPrefixFromType(typeof(PerViewMeshesFS));
         for (int sourceCamIndex = 0; sourceCamIndex < cameraModels.Length; sourceCamIndex++)
         {
             // Create a gameobject for the mesh, and set it as a child of the geometric data transform.
             Transform meshTransform = new GameObject(bundledAssetsPrefix + "FocalSurface" + sourceCamIndex).transform;
             meshTransform.parent = geometricDataTransform;
             // Determine the mesh's transform values from the camera model.
             CameraModel cameraModel  = cameraModels[sourceCamIndex];
             Vector3     meshPosition = cameraModel.transform.position;
             Quaternion  meshRotation = cameraModel.transform.rotation;
             Vector3     meshScale    = Vector3.one;
             // If the camera model is omnidirectional, load the sphere focal surface mesh.
             if (cameraModel.isOmnidirectional)
             {
                 if (sphereFocalSurface == null)
                 {
                     yield return(dataHandler.StartCoroutine(dataHandler.LoadAssetsFromBundleCoroutine <Mesh>((result => sphereFocalSurface = result[0]), bundledAssetsPrefix + sphereFocalSurfaceName)));
                 }
                 meshTransform.gameObject.AddComponent <MeshFilter>().sharedMesh = sphereFocalSurface;
             }
             // If the camera model is perspective, load the quad focal surface mesh.
             else
             {
                 if (quadFocalSurface == null)
                 {
                     yield return(dataHandler.StartCoroutine(dataHandler.LoadAssetsFromBundleCoroutine <Mesh>((result => quadFocalSurface = result[0]), bundledAssetsPrefix + quadFocalSurfaceName)));
                 }
                 meshTransform.gameObject.AddComponent <MeshFilter>().sharedMesh = quadFocalSurface;
                 // Scale the quad based on the camera model's aspect ratio.
                 meshScale = new Vector3(1, cameraModel.pixelResolution.y * 1f / cameraModel.pixelResolution.x, 1);
             }
             // Set the mesh's transform to the computed values.
             GeneralToolkit.SetTransformValues(meshTransform, false, meshPosition, meshRotation, meshScale);
             // Assign to the output array.
             meshTransforms[sourceCamIndex] = meshTransform;
         }
         // Reset the geometric data's local position, rotation, and scale, to fit that of the parent object.
         GeneralToolkit.SetTransformValues(geometricDataTransform.transform, true, Vector3.zero, Quaternion.identity, Vector3.one);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a camera model, eventually set as the child of a parent transform.
        /// </summary>
        /// <param name="parentTransform"></param> The parent transform.
        /// <returns></returns> The created camera model.
        public static CameraModel CreateCameraModel(Transform parentTransform = null)
        {
            CameraModel cameraModel = new GameObject().AddComponent <CameraModel>();

            cameraModel.Reset();
            if (parentTransform != null)
            {
                cameraModel.transform.parent = parentTransform;
                GeneralToolkit.SetTransformValues(cameraModel.transform, true, Vector3.zero, Quaternion.identity, Vector3.one);
            }
            return(cameraModel);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the processed per-view meshes for play.
        /// </summary>
        /// <returns></returns>
        public IEnumerator LoadProcessedPerViewMeshesCoroutine()
        {
            CameraModel[] cameraModels = cameraSetup.cameraModels;
            perViewMeshes         = new Mesh[cameraModels.Length];
            perViewMeshTransforms = new Transform[cameraModels.Length];
            // Check that the application is playing.
            if (!Application.isPlaying)
            {
                yield break;
            }
            // Only continue if there are source images.
            if (cameraModels.Length > 0)
            {
                // Create a gameobject for the geometric data, and set it as a child of this transform.
                Transform geometricDataTransform = new GameObject("Geometric data").transform;
                geometricDataTransform.parent = dataHandler.transform;
                // Reset the geometric data's local position, rotation, and scale, to fit that of the parent object.
                GeneralToolkit.SetTransformValues(geometricDataTransform.transform, true, Vector3.zero, Quaternion.identity, Vector3.one);
                // Check each bundled asset name for the prefix corresponding to this class.
                string bundledAssetsPrefix = DataHandler.GetBundledAssetPrefixFromType(typeof(PerViewMeshesQSTR));
                foreach (string bundledAssetName in dataHandler.bundledAssetsNames)
                {
                    // If the correct asset name is found, load the per-view mesh.
                    if (bundledAssetName.Contains(bundledAssetsPrefix))
                    {
                        Mesh processedPerViewMesh = new Mesh();
                        yield return(dataHandler.StartCoroutine(dataHandler.LoadAssetsFromBundleCoroutine <Mesh>((result => processedPerViewMesh = result[0]), bundledAssetName)));

                        // Create a gameobject for the mesh, and set it as a child of the geometric data.
                        Transform meshTransform = new GameObject(processedPerViewMesh.name).transform;
                        meshTransform.parent = geometricDataTransform;
                        // Link the per-view mesh to the gameobject.
                        meshTransform.gameObject.AddComponent <MeshFilter>().sharedMesh = processedPerViewMesh;
                        // Determine the source camera index.
                        string assetName            = bundledAssetName.Replace(bundledAssetsPrefix, string.Empty);
                        string sourceCamIndexString = assetName.Replace(perViewMeshAssetPrefix, string.Empty);
                        int    sourceCamIndex       = GeneralToolkit.ParseInt(sourceCamIndexString);
                        // Determine the mesh's transform values from the camera model.
                        CameraModel cameraModel  = cameraModels[sourceCamIndex];
                        Vector3     meshPosition = cameraModel.transform.position;
                        Quaternion  meshRotation = cameraModel.transform.rotation;
                        Vector3     meshScale    = Vector3.one;
                        // Set the mesh's transform to the computed values.
                        GeneralToolkit.SetTransformValues(meshTransform, false, meshPosition, meshRotation, meshScale);
                        // Assign to the output arrays.
                        perViewMeshes[sourceCamIndex]         = processedPerViewMesh;
                        perViewMeshTransforms[sourceCamIndex] = meshTransform;
                    }
                }
            }
        }
 /// <summary>
 /// Updates the focal surface positions and scales based on the current focal length.
 /// </summary>
 /// <param name="focalSurfaceTransforms"></param> The focal surface transforms.
 public void UpdateFocalSurfaceTransforms(Transform[] focalSurfaceTransforms)
 {
     for (int i = 0; i < focalSurfaceTransforms.Length; i++)
     {
         float   focalRatio = _focalLength / _initialFocals[i];
         Vector3 position   = _initialPositions[i];
         if (!_areCamerasOmnidirectional[i])
         {
             position += _focalLength * focalSurfaceTransforms[i].forward;
         }
         Quaternion rotation = focalSurfaceTransforms[i].rotation;
         Vector3    scale    = focalRatio * _initialScales[i];
         GeneralToolkit.SetTransformValues(focalSurfaceTransforms[i], false, position, rotation, scale);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads the processed global mesh with per-view depth for play.
        /// </summary>
        /// <returns></returns>
        public IEnumerator LoadProcessedGlobalMeshCoroutine()
        {
            globalMesh          = null;
            globalMeshTransform = null;
            // Check that the application is playing.
            if (!Application.isPlaying)
            {
                yield break;
            }
            // Check each bundled asset name for the prefix corresponding to this class.
            string bundledAssetsPrefix = DataHandler.GetBundledAssetPrefixFromType(typeof(GlobalMeshEF));

            foreach (string bundledAssetName in dataHandler.bundledAssetsNames)
            {
                string assetName = bundledAssetName.Replace(bundledAssetsPrefix, string.Empty);
                // If the correct asset name is found, load the global mesh.
                if (assetName == globalMeshAssetName)
                {
                    yield return(dataHandler.StartCoroutine(dataHandler.LoadAssetsFromBundleCoroutine <Mesh>((result => globalMesh = result[0]), bundledAssetName)));
                }
            }
            // If the mesh data was found, initialize a transform in the scene with a mesh filter to contain it.
            if (globalMesh != null)
            {
                // Create a gameobject for the geometric data, and set it as a child of this transform.
                Transform geometricDataTransform = new GameObject("Geometric data").transform;
                geometricDataTransform.parent = dataHandler.transform;
                // Create a gameobject for the mesh, and set it as a child of the geometric data.
                globalMeshTransform        = new GameObject(globalMesh.name).transform;
                globalMeshTransform.parent = geometricDataTransform;
                // Link the global mesh to the gameobject.
                globalMeshTransform.gameObject.AddComponent <MeshFilter>().sharedMesh = globalMesh;
                // Add a mesh collider.
                if (dataHandler.generateColliders)
                {
                    globalMeshTransform.gameObject.AddComponent <MeshCollider>();
                }
                // Reset the geometric data's local position, rotation, and scale, to fit that of the parent object.
                GeneralToolkit.SetTransformValues(geometricDataTransform.transform, true, Vector3.zero, Quaternion.identity, Vector3.one);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Processes color and/or depth data.
        /// </summary>
        /// <returns></returns>
        private IEnumerator ProcessDataCoroutine()
        {
            // Inform the user that the process has started.
            GeneralToolkit.ResetCancelableProgressBar(true, true);
            Debug.Log(GeneralToolkit.FormatScriptMessage(typeof(Processing), "Started processing data."));
            processingCanceled = false;
            // Save the current position, rotation, and scale for later.
            Vector3    position = transform.position;
            Quaternion rotation = transform.rotation;
            Vector3    scale    = transform.localScale;

            // Reset the transform, and wait for the camera models to be updated accordingly.
            GeneralToolkit.SetTransformValues(transform, false, Vector3.zero, Quaternion.identity, Vector3.one);
            yield return(null);

            // Create the processed data directory and initialize the processing information file.
            dataHandler.CreateProcessingInfoFile();
            // Move the processed data directory to the temporary directory.
            GeneralToolkit.Move(PathType.Directory, dataHandler.processedDataDirectory, GeneralToolkit.tempDirectoryAbsolutePath, false);
            AssetDatabase.Refresh();
            if (!Directory.Exists(GeneralToolkit.tempDirectoryAbsolutePath))
            {
                processingCanceled = true;
            }
            // Execute the processing methods.
            for (int iter = 0; iter < processingMethods.Length; iter++)
            {
                ProcessingMethod processingMethod = processingMethods[iter];
                if (!processingMethod.IsGUINested() && processingMethod.shouldExecute)
                {
                    yield return(StartCoroutine(processingMethod.ExecuteAndDisplayLog()));
                }
                if (processingCanceled)
                {
                    break;
                }
            }
            // Unload loaded assets.
            Resources.UnloadUnusedAssets();
            EditorUtility.UnloadUnusedAssetsImmediate();
            yield return(null);

            // Move the processed data directory back to its original position.
            GeneralToolkit.Move(PathType.Directory, GeneralToolkit.tempDirectoryAbsolutePath, dataHandler.processedDataDirectory, false);
            AssetDatabase.Refresh();
            // Update the processed asset information.
            dataHandler.UpdateProcessedAssets();
            // Inform the user of the end of the process.
            if (!processingCanceled)
            {
                Debug.Log(GeneralToolkit.FormatScriptMessage(typeof(Processing), "Finished processing data."));
            }
            else
            {
                Debug.Log(GeneralToolkit.FormatScriptMessage(typeof(Processing), "Processing was canceled."));
            }
            // Perform a check to verify whether data was processed.
            dataHandler.CheckStatusOfDataProcessingAndBundling(out isDataReadyForBundling, out isDataBundled, out processedDataInfo);
            // Return the transform's values to their previous ones.
            GeneralToolkit.SetTransformValues(transform, false, position, rotation, scale);
            // Reset the progress bar.
            GeneralToolkit.ResetCancelableProgressBar(false, false);
        }