Ejemplo n.º 1
0
        /// <inheritdoc/>
        protected override IEnumerator ExecuteMethodCoroutine()
        {
            // Get the processed asset's name and path in the bundle.
            string bundledAssetName      = GetBundledAssetName(colorDataAssetName);
            string colorDataPathRelative = GetAssetPathRelative(bundledAssetName);

            // Check if the asset has already been processed.
            if (!dataHandler.IsAssetAlreadyProcessed(colorDataPathRelative))
            {
                // Reset the progress bar.
                GeneralToolkit.ResetCancelableProgressBar(true, false);
                // Determine the resolution and depth that should be given to the texture array.
                Vector2Int arrayResolution; int arrayDepth;
                GetCorrectedPowerOfTwoForImages(cameraSetup.cameraModels, out arrayResolution, out arrayDepth);
                // Create an empty texture array.
                colorData = new Texture2DArray(1, 1, 1, TextureFormat.RGBA32, useMipMaps);
                GeneralToolkit.CreateTexture2DArray(ref colorData, arrayResolution, arrayDepth, TextureFormat.RGB24, false, FilterMode.Point, TextureWrapMode.Clamp, useMipMaps);
                // Create an empty texture, with the array's resolution.
                Texture2D arraySlice = new Texture2D(1, 1);
                GeneralToolkit.CreateTexture2D(ref arraySlice, arrayResolution, TextureFormat.RGB24, false, FilterMode.Point, TextureWrapMode.Clamp, useMipMaps);
                // Create an empty texture, in which we will load the set of source images one-by-one.
                Texture2D loadTex = new Texture2D(1, 1);
                // Process as many images as possible from the set of source images.
                for (int i = 0; i < arrayDepth; i++)
                {
                    // Update the progress bar, and enable the user to cancel the process.
                    DisplayAndUpdateCancelableProgressBar();
                    if (GeneralToolkit.progressBarCanceled)
                    {
                        processingCaller.processingCanceled = true;
                        break;
                    }
                    // Load the camera model.
                    CameraModel cameraModel = cameraSetup.cameraModels[i];
                    // Load the image into a texture object.
                    string imagePath = Path.Combine(dataHandler.colorDirectory, cameraModel.imageName);
                    GeneralToolkit.CreateTexture2D(ref loadTex, cameraModel.pixelResolution, TextureFormat.RGB24, false, FilterMode.Point, TextureWrapMode.Clamp, useMipMaps);
                    GeneralToolkit.LoadTexture(imagePath, ref loadTex);
                    // Resize the texture so that it fits the array's resolution.
                    GeneralToolkit.ResizeTexture2D(loadTex, ref arraySlice);
                    // Add the texture to the texture array.
                    colorData.SetPixels(arraySlice.GetPixels(), i);
                    colorData.Apply();
                    yield return(null);
                }
                // If the user has not canceled the process, continue.
                if (!GeneralToolkit.progressBarCanceled)
                {
                    // Create an asset from this texture array.
                    AssetDatabase.CreateAsset(colorData, colorDataPathRelative);
                    AssetDatabase.Refresh();
                }
                // Destroy created objects.
                DestroyImmediate(loadTex);
                DestroyImmediate(arraySlice);
                // Reset the progress bar.
                GeneralToolkit.ResetCancelableProgressBar(true, false);
            }
            Texture2DArray colorDataAsset = AssetDatabase.LoadAssetAtPath <Texture2DArray>(colorDataPathRelative);

            colorData = (Texture2DArray)Instantiate(colorDataAsset);
        }