Descriptions and Examples for the POV-Ray Raytracer by Friedrich A. Lohmüller
    Include files with POV-Ray
How they work and How to make your own include files
Deutsch Deutsch

Home
- POV-Ray Tutorial

  - POV-Ray Details

  - About Variables

  - A Short
    Include File Tutorial
      Why Include Files?
    >Self-made Include Files
          and how to call them.
      Special Notations, ".inc"
          "#local / #declare"
      Where to store
      Design of Include Files
      Adding a new item
        to the 'Insert Menu'


                                                       

Self-made include files

First Example - An include file for an object:
Here the relevant part of a small table 'Table_01' in a simple POV-Ray scene file (red):

// POV-Ray 3.6/3.7 scene file sample
//
//
// camera, light, background here !
// ...
//////////// object definition ///////
// table dimensions
#local H = 0.50; // height,
#local W = 0.45; // width in x and z
#local R = 0.02; // thickness
//------------------------
#declare Table_01 =
union{
   // feet
  cylinder{<0,0,0>,<0,H,0>, R
           translate< W/2-R,0,-W/2+R>}
  cylinder{<0,0,0>,<0,H,0>, R
           translate< W/2-R,0, W/2-R>}
  cylinder{<0,0,0>,<0,H,0>, R
           translate<-W/2+R,0, W/2-R>}
  cylinder{<0,0,0>,<0,H,0>, R
           translate<-W/2+R,0,-W/2+R>}
  // seat
  box{ <-W/2,-0.025,-W/2>,<W/2,0,W/2>
       translate<0,H,0> }

  pigment{ color rgb<0.75,0.5,0.3>*0.3}
}// end of union 'Table_01'
//////////////////////////////////////
// using the object:
object{ Table_01
        rotate<0,0,0>
        translate<0,0,0>
      }
//------------------------------------
Table_00
The object 'Table_01'.


Making an Include File and How we refer to it:
Now we put the declaration of the object 'Table_01' in a new separate file called 'Table_01.inc'
and we save it in the same directory as the scene (.pov) file:
(other possibilties are descriped later!)
The POV-Ray Scene File
using the object 'Table_01':
'Table_01_test.pov'

//POV-Ray scene 'Scene_with_Table_01.pov'
// needs: "Table_01.inc"
// ...
// camera, light, background here !
// ...
//////////////////////////////////////
#include "Table_01.inc"
//////////////////////////////////////
// using the object:
object{ Table_01
        rotate<0,0,0>
        translate<0,0,0>
      }
// ... and again once more:
object{ Table_01
        rotate<0,0,0>
        translate<1,0,0>
      }
// ...

//------------------------------------
Notes:
1) An include file must be included in the scene file
before anything of it's content can be used!
The best place is up in the scene file header or before the main objects in the scene!
2) Subsequent uses of the content of an include file
(here: object{ Table_01 ...})
need including the relative include file only once!
The POV-Ray include file
'Table_01.inc'
 
// POV-Ray Include File: 'Table_01.inc'
//////////////////////////////////////
// table dimensions
#local H = 0.50; // height,
#local W = 0.45; // width in x and z
#local R = 0.02; // thickness
//------------------------
#declare  Table_01 =
union{
   // feet
  cylinder{<0,0,0>,<0,H,0>, R
           translate< W/2-R,0,-W/2+R>}
  cylinder{<0,0,0>,<0,H,0>, R
           translate< W/2-R,0, W/2-R>}
  cylinder{<0,0,0>,<0,H,0>, R
           translate<-W/2+R,0, W/2-R>}
  cylinder{<0,0,0>,<0,H,0>, R
           translate<-W/2+R,0,-W/2+R>}
  // seat
  box{ <-W/2,-0.025,-W/2>,<W/2,0,W/2>
       translate<0,H,0> }

  pigment{ color rgb<0.75,0.5,0.3>*0.3}
}// end of union 'Table_01'
//////////////////////////////////////
// ............... end of include file
Notes:
3) The include file does not contain any camera, light or background items.
The include file contain only the table declarations - nothing else!
4) Declaring objects in include files: It makes sense to use the objects here centered at the origine <0,0,0> without any rotate or translate!
Otherwise re-using them in other scenes may become very difficult!


top

© Friedrich A. Lohmüller, 2015
http://www.f-lohmueller.de
 
Visitors:
(since May-1999)
Thanks for your visit!