My Main Scene File

For every animation project I have just one .POV file, and this file will reference all of the other files needed for the animation. I generally name the file main.pov; each animation project has its own folder, so there's little potential for confusion. The file basically does four things.
Read and interpret the render settings
POV-Ray exposes several of the rendering parameters to the scene description language (SDL). I used them to set up the camera and other scene-level aspects of the render:
  • Shot: POV-Ray allows the user to pass variables from the command line to the SDL. I use this to specify which shot is being rendered. There's no fall-back code so that things will fail noisily if I forget to set them in the .INI file.
  • Test: I also pass a simple 0 or 1 to indicate whether I an running a test render or a final render. If for some reason I've left this out of the .INI file then I supply a default:
  • #ifndef(Test)
      #declare Test = 1;
    #end
  • Time: If the variables that control animation are all defined, I use them to calculate the current time and the frames per second of the animation; otherwise I set them to default values.
  • #if(clock_on)
      #declare FPS = (final_frame - initial_frame) / (final_clock - initial_clock);
      #declare Time = frame_number / FPS;
    #else
      #declare FPS = 1;
      #declare Time = 0;
    #end
    
    In my .INI file I usually set the Initial_Clock and Initial_Frame values to zero, the Final_Clock value to the length of the animation (rounding up to the next whole number if the length is a fraction), and then set Final_Frame to the product of the animation length and the desired frame rate. Most of my scenes are rendered at 24 frames per second, but when I use motion blur I will render at a higher frame rate. I'm aware that the POV-Ray documentation recommends a Final_Clock value of 1 for all animations, with code in the scene files to re-calculate the desired value; that's needless complexity from where I see it.
    Invoke the file for the shot
    This consists of building the file path, testing to see if the file exists, and then either invoking the file or generating a warning if the file is missing. I make this fault-tolerant because sometimes I only have a titling file (which is invoked later) and I don't need a noisy failure.
    #local SceneFileName = concat("s_", str(Shot,-4,0), ".inc")
    
    #if (file_exists(SceneFileName))
      #debug concat("Including scene file '", SceneFileName, "'.\n")
      #include SceneFileName
    #else
      #debug concat("Could not find file '", SceneFileName, "'.\n")
    #end
    
    Note that the concat function call pads out the shot number to four digits, with leading zeroes. This allows for up to 10,000 shots in a single project, which should be more than enough; but you can kick it out to five or six digits if you're really ambitious.
    Instantiate the Camera
    My scene files include everything except the camera and everything that is positioned relative to the camera (sub-titles, simulated filters, etc.), but they will specify the placement and direction of the camera. I take the values set (with defaults, if needed) and use them to calculate the values used for the camera definition. Note that I prefer left-handed geometry (positive x is right, positive y is up, positive z is forward):
    #ifndef(pCamL) // where the camera is
      #declare pCamL = <0,0,0>;
    #end
    
    #ifndef(pCamE) // the spot at which the camera is pointed
      #declare pCamE = z;
    #end
    
    #ifndef(vCamS) // up, as seen within the scene
      #declare vCamS = y;
    #end
    
    #ifndef(sCamZ) // the camera zoom
      #declare sCamZ = 2.5;
    #end
    
    #declare vCamD = vnormalize(pCamE - pCamL);
    #declare vCamR = vnormalize(vcross(vCamS, vCamD));
    #declare vCamU = vnormalize(vcross(vCamD, vCamR));
    
    camera {
      location pCamL
      right vCamR * image_width
      up vCamU * image_height
      direction vCamD * sCamZ * min(image_width, image_height)
    }
    
    Usually only pCamL and pCamE are needed; My scenes are designed with the same sense of "up" in mind, and the same value for zoom generally works everywhere.
    Invoke the titling file
    As with the scene file, I build the path, test to see if the file exists, and then either invoke the file or generate a warning if the file is missing. Most scenes don't have any titling, so being fault-tolerant is important here.
    #local TitleFileName = concat("s_", str(Shot,-4,0), ".inc")
    
    #if (file_exists(SceneFileName))
      #debug concat("Including scene file '", TitleFileName, "'.\n")
      #include TitleFileName
    #else
      #debug concat("Could not find file '", TitleFileName, "'.\n")
    #end
    
    As I mentioned above, the scene elements that are positioned to appear in a specific place in the camera view, regardless of its position or orientation, are all described in the titling file. I use the values vCamR, vCamU, vCamD, and pCamL to position them, so it's better to create the titling elements after the positioning values have been calculated.

    Comments

    Popular posts from this blog

    Transition Macros

    Titling Made Simple

    Star Field Generator