Exemplo n.º 1
0
        /// <summary>
        /// Processes a single Cardboard photo file
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="outputFolder">The output folder path.</param>
        /// <param name="multiFileMode">True if we are processing multiple photo files.</param>
        private static void ProcessFile(string filePath, string outputFolder, bool multiFileMode)
        {
            Console.WriteLine($"Processing file {filePath}.");
            var cardboardPhoto      = new CardboardPhoto(filePath);
            var fileNameNoExtension = Path.GetFileNameWithoutExtension(filePath);

            // Save the left, right, and preview photos
            cardboardPhoto.SaveLeftPhoto(Path.Combine(outputFolder, fileNameNoExtension + "_left.jpg"), true);
            cardboardPhoto.SaveRightPhoto(Path.Combine(outputFolder, fileNameNoExtension + "_right.jpg"), true);
            if (multiFileMode)
            {
                cardboardPhoto.SavePreview(Path.Combine(outputFolder, fileNameNoExtension + "_preview.jpg"), PreviewImageSize);
            }

            // Generate image ids
            var imageId = $"#image{CardboardPhotos.Count}";

            cardboardPhoto.LeftImageId    = $"{imageId}-left";
            cardboardPhoto.RightImageId   = $"{imageId}-right";
            cardboardPhoto.PreviewImageId = $"{imageId}-preview";

            // Add to our list of photos for later processing
            CardboardPhotos.Add(cardboardPhoto);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            var multiFileMode = true;

            if (args.Length < 2)
            {
                PrintHelp();
                return;
            }

            // Get the command line arguments
            var inputFolder  = args[0];
            var outputFolder = args[1];

            // Check input
            if (Directory.Exists(inputFolder))
            {
                multiFileMode = true;
            }
            else if (File.Exists(inputFolder))
            {
                multiFileMode = false;
            }
            else
            {
                Console.WriteLine($"Input folder {inputFolder} does not exist.");
                return;
            }

            // Create the output directory structure
            Directory.CreateDirectory(outputFolder);
            Directory.CreateDirectory(Path.Combine(outputFolder, ScriptsFolderName));
            var assetsFolder = Path.Combine(outputFolder, AssetsFolderName);

            Directory.CreateDirectory(assetsFolder);

            // Process the input as a folder or file.
            if (multiFileMode)
            {
                // Add the initial entry in the our cardboard photo list,
                // This is required later when the list is serialized to JSON
                var startPhoto = new CardboardPhoto
                {
                    LeftImageId  = "#start",
                    RightImageId = "#start",
                    Caption      = "Welcome"
                };
                CardboardPhotos.Add(startPhoto);

                ProcessDirectory(inputFolder, assetsFolder);
            }
            else
            {
                ProcessFile(inputFolder, assetsFolder, false);
            }

            // Write the various output files
            WriteIndexFile(outputFolder, multiFileMode);
            WriteWebContentFiles(outputFolder, multiFileMode);
            if (multiFileMode)
            {
                WriteImagesJsonFile(outputFolder);
            }

            Console.WriteLine($"Results are in {outputFolder}");

            if (CardboardPhotos.Count > 20)
            {
                Console.WriteLine();
                Console.WriteLine("Warning: A large number of photos (> 20) may cause instability in some browsers.");
                Console.WriteLine($"  {CardboardPhotos.Count} photos were processed.");
                Console.WriteLine("  Consider running again with a smaller set of photos.");
            }
        }