Beispiel #1
0
        /// <summary>Starts povray using the given options.</summary>
        /// <param name="options">Povray options.</param>
        public bool Render(PovrayOptions options)
        {
            if (options.SceneParsing.InputFileName == null)
            {
                throw new ArgumentException("No input file", nameof(options.SceneParsing.InputFileName));
            }

            if (options.FileOutput.OutputFileName == null)
            {
                options.FileOutput.OutputFileName = Path.ChangeExtension(options.SceneParsing.InputFileName, "png");
            }

            string iniFile = options.WriteFile();

            List <string> args = new List <string>
            {
                iniFile
            };

            if (OS.IsWindows)
            {
                args.Add("/NORESTORE");
                if (!options.DisplayOutput.PauseWhenDone)
                {
                    args.Add("/EXIT");
                }
            }


            bool result = this.Render(args.ToArray());

            File.Delete(iniFile);
            return(result);
        }
Beispiel #2
0
        /// <summary>Renders a scene file.</summary>
        /// <param name="options">Povray options.</param>
        /// <param name="povFile">Povray scene file.</param>
        /// <param name="output">Output filename</param>
        public bool Render(PovrayOptions options, string povFile, string output = null)
        {
            options.FileOutput.OutputFileName  = output;
            options.SceneParsing.InputFileName = povFile;

            return(this.Render(options));
        }
Beispiel #3
0
 /// <summary>
 /// Creates an instance.
 /// </summary>
 /// <param name="scene">The scene to render.</param>
 /// <param name="length">The number of frames.</param>
 /// <param name="povray">The renderer.</param>
 /// <param name="options">Povray options.</param>
 public Animation(Scene scene, int length, Povray povray = null, PovrayOptions options = null)
 {
     this.Length  = length;
     this.Scene   = scene;
     this.povray  = povray ?? new Povray();
     this.Options = new PovrayOptions(scene.PovrayOptions).Copy();
     this.Options.SetOptions(options);
 }
Beispiel #4
0
        /// <summary>Renders a scene.</summary>
        /// <param name="scene">The scene to render.</param>
        /// <param name="width">Image width.</param>
        /// <param name="height">Image height. 0 to use the width at a ratio of 4:3</param>
        /// <param name="options">Povray options, overriding the values that are set in the scene (if any).</param>
        /// <returns></returns>
        public bool Render(Scene scene, int width, int height = 0, PovrayOptions options = null)
        {
            PovrayOptions modifiedOptions = new PovrayOptions(options);

            modifiedOptions.GeneralOutput.Width  = width;
            modifiedOptions.GeneralOutput.Height = height == 0 ? (int)(width * 0.75) : height;
            return(this.Render(scene, modifiedOptions));
        }
Beispiel #5
0
 /// <summary>
 /// Copy the options from another instance onto this.
 /// </summary>
 /// <param name="otherOptions"></param>
 public void SetOptions(PovrayOptions otherOptions)
 {
     if (otherOptions != null)
     {
         foreach (KeyValuePair <string, object> item in otherOptions.storage)
         {
             this.storage[item.Key] = item.Value;
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// Get the rendering options for the scenes that a scene depends upon.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        internal IEnumerable <PovrayOptions> GetDependentScenes(Scene scene, PovrayOptions options)
        {
            foreach (Scene dependentScene in scene.DependentScenes)
            {
                PovrayOptions opt = new PovrayOptions(scene.PovrayOptions);
                opt.SetOptions(options);
                opt.SetOptions(dependentScene.PovrayOptions);
                opt.SceneParsing.InputFileName = dependentScene.OutputFile;
                opt.FileOutput.OutputFileName  = dependentScene.OutputImageFile;

                foreach (PovrayOptions child in this.GetDependentScenes(dependentScene, opt))
                {
                    yield return(child);
                }

                yield return(opt);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Generate the scene files for each frame.
        /// </summary>
        /// <param name="baseFilename">Path of the generated scene files, without the .pov extension.</param>
        /// <param name="options">Base options to use.</param>
        /// <returns>Frame-specific options for each frame.</returns>
        public PovrayOptions[] GenerateSceneFiles(string baseFilename, PovrayOptions options)
        {
            string filenameFormat = this.GetFrameFormat(baseFilename, "pov");

            this.CurrentFrame = -1;

            if (this.StartFrame < 0)
            {
                this.StartFrame = 0;
            }

            if (this.StartFrame >= this.Length)
            {
                this.StartFrame = this.Length - 1;
            }

            if (this.EndFrame < 0 || this.EndFrame >= this.Length)
            {
                this.EndFrame = this.Length - 1;
            }

            this.Clock = this.InitialClock;

            this.Scene.StartAnimation(this);

            List <PovrayOptions> frames = new List <PovrayOptions>(this.Length);

            while (this.NextFrame())
            {
                string povFile = string.Format(filenameFormat, this.CurrentFrame);

                PovrayOptions frameOptions = new PovrayOptions(options);
                frameOptions.Animation.Clock            = this.Clock;
                frameOptions.FileOutput.OutputFileName  = Path.ChangeExtension(povFile, "png");
                frameOptions.SceneParsing.InputFileName = povFile;
                frames.Add(frameOptions);

                this.Scene.PovVersion = this.povray.Version;
                this.Scene.WriteFile(frameOptions.SceneParsing.InputFileName, frameOptions.FileOutput.OutputFileName);
            }

            this.CurrentFrame = -1;
            return(frames.ToArray());
        }
Beispiel #8
0
        /// <summary>Renders a scene.</summary>
        /// <param name="options">Povray options, overriding the values that are set in the scene (if any).</param>
        /// <param name="scene">The scene to render.</param>
        /// <returns></returns>
        public bool Render(Scene scene, PovrayOptions options = null)
        {
            // Duplicate the scene's options, and copy the provided values.
            PovrayOptions mergedOptions = new PovrayOptions(scene.PovrayOptions);

            mergedOptions.SetOptions(options);

            // Write the scene file.
            if (string.IsNullOrEmpty(mergedOptions.SceneParsing.InputFileName))
            {
                mergedOptions.SceneParsing.InputFileName = "pov.pov";
            }

            scene.PovVersion = this.Version;

            scene.WriteFile(mergedOptions.SceneParsing.InputFileName, mergedOptions.FileOutput.OutputFileName);

            if (scene.DependentScenes.Count > 0)
            {
                foreach (PovrayOptions dependent in this.GetDependentScenes(scene, options))
                {
                    dependent.DisplayOutput.PauseWhenDone = false;
                    this.Render(dependent);
                }
            }

            bool result = this.Render(mergedOptions);

            if (options != null)
            {
                // Copy the output file onto the provided options.
                options.FileOutput.OutputFileName = mergedOptions.FileOutput.OutputFileName;
            }

            return(result);
        }
Beispiel #9
0
 /// <summary>
 /// Creates an instance, using the values of another instance.
 /// </summary>
 /// <param name="original">The instance to copy values from.</param>
 public PovrayOptions(PovrayOptions original)
     : this()
 {
     this.SetOptions(original);
 }