POV-Ray : Newsgroups : povray.newusers : Writing a .inc file Server Time
31 Oct 2024 10:24:31 EDT (-0400)
  Writing a .inc file (Message 1 to 7 of 7)  
From: Jug
Subject: Writing a .inc file
Date: 8 Aug 2008 03:20:00
Message: <web.489bf2df611ced9672762ce30@news.povray.org>
Hi,
  I am new to POV-Ray and have no previous programming experience, so please
forgive me if this is a simple question.  I a trying to write an .inc file of
an etched tile.  I want the tile and the lettering to be two different colors
and to be able to easily edit the colors of the tile from the scene file I add
it into.  I know that if I do not include a color/texture in the .inc file I
can define the it in the scene, but it makes the tile and writing the same
color/texture.  Is there a way I can determine or change the color/texture of
the individual components of the tile from the scene file?  I would also like
to be able to easily change  the pigment, texture, and finish of the tile in
the .inc file from the scene file.  Do I need to include the standard .inc
files, such as colors, textures, or stones1 into my .inc file, or will it work
if I include them in the scene?  I have included my tile below and added in the
color and texture as an example of what I am trying to do.  Thanks a lot for any
help you can give me.

Jug


declare Silver =               // Element Tile
union{
difference{                       // Front Plate and Lettering
box{<0, 0, 0>,                       // Box, Near lower left corner
    < 1.6, 2.2,  0.2>                   // Far upper right corner
    texture {T_Stone1}                  // color
    translate <0, 0, 0>}                // location
text {ttf "Arial.ttf" "Ag" 5, 0      // text and symbol
    pigment {Green}                     // color
    scale 1                             // scale
    translate <.2, .5, -1>}             // location
text {ttf "Arial.ttf" "47" 5, 0      // text and number
    pigment {Green}                     // color
    scale 0.6                           // scale
    translate <.1, 1.6, -1>}            // location
translate <0.25, 0.25,  >}           // location

difference{                       // Boarder and Back Plate
box{<0, 0,   0>,                     // Boarder, Near lower left corner
    < 2.1, 2.7,  0.3>                   // Far upper right corner
    texture {T_Stone1}}                 // color
box{<0.15, 0.15, -0.1>,              // Negative Space, Near lower left corner
    < 1.95, 2.55,  0.2>                 // Far upper right corner
    pigment {Green}}}}                  // color


Post a reply to this message

From: Jim Holsenback
Subject: Re: Writing a .inc file
Date: 8 Aug 2008 05:55:22
Message: <489c180a@news.povray.org>
"Jug" <nomail@nomail> wrote in message 
news:web.489bf2df611ced9672762ce30@news.povray.org...
> Hi,
>  I am new to POV-Ray and have no previous programming experience, so 
> please
> forgive me if this is a simple question.  I a trying to write an .inc file 
> of
> an etched tile.  I want the tile and the lettering to be two different 
> colors
> and to be able to easily edit the colors of the tile from the scene file I 
> add
> it into.  I know that if I do not include a color/texture in the .inc file 
> I
> can define the it in the scene, but it makes the tile and writing the same
> color/texture.  Is there a way I can determine or change the color/texture 
> of
> the individual components of the tile from the scene file?  I would also 
> like
> to be able to easily change  the pigment, texture, and finish of the tile 
> in
> the .inc file from the scene file.  Do I need to include the standard .inc
> files, such as colors, textures, or stones1 into my .inc file, or will it 
> work
> if I include them in the scene?  I have included my tile below and added 
> in the
> color and texture as an example of what I am trying to do.  Thanks a lot 
> for any
> help you can give me.
>
> Jug

it's all about order ..... in your scene file if you have #include 
"colors.inc" before you have #include "myobject.inc" it will know about the 
colors without having those entries in the .inc file also. if your object 
had just one texture or pigment, you could build you object in the .inc file 
without any mention of color. Back in your scene file (.pov) you could call 
your object like this:  object {MyObject {pigment Green}} since your object 
has more that one pigment/texture i'd make the .inc file a macro that way 
you could call your object like this: MyObject (T_Stone1, Green) or MyObject 
(T_Stone2, Blue)

hope this helps
Jim


Post a reply to this message

From: Chris B
Subject: Re: Writing a .inc file
Date: 8 Aug 2008 06:44:25
Message: <489c2389$1@news.povray.org>
"Jug" <nomail@nomail> wrote in message 
news:web.489bf2df611ced9672762ce30@news.povray.org...
> Hi,
>  I am new to POV-Ray and have no previous programming experience, so 
> please
> forgive me if this is a simple question.  I a trying to write an .inc file 
> of
> an etched tile.  I want the tile and the lettering to be two different 
> colors
> and to be able to easily edit the colors of the tile from the scene file I 
> add
> it into.  I know that if I do not include a color/texture in the .inc file 
> I
> can define the it in the scene, but it makes the tile and writing the same
> color/texture.  Is there a way I can determine or change the color/texture 
> of
> the individual components of the tile from the scene file?  I would also 
> like
> to be able to easily change  the pigment, texture, and finish of the tile 
> in
> the .inc file from the scene file.  Do I need to include the standard .inc
> files, such as colors, textures, or stones1 into my .inc file, or will it 
> work
> if I include them in the scene?  I have included my tile below and added 
> in the
> color and texture as an example of what I am trying to do.  Thanks a lot 
> for any
> help you can give me.
>
> Jug

Hi and Welcome.

There are actually lots of approaches you could take.

I very much prefer the approach that I've illustrated below using #ifdef and 
#ifndef to define default texture values. As you can see from the 
'WritingTexture' declaration, you can nest these to provide the sort of 
flexibility you mentioned in your question: If 'WritingTexture' is already 
defined by the time your include file is parsed, it'll use that. Otherwise 
if 'WritingPigment' or 'WritingNormal' are defined it'll use them to 
construct 'WritingTexture'. If none are defined it'll just define defaults 
and plough on regardless.

You can use a similar technique to define any #include files that you're 
dependent upon if they weren't already included.

By testing for everything you need you can make a very robust little 
#include file. By providing defaults for everything, anyone can start using 
the file without having to initially worry about setting variables, 
parameters etc.

If you're planning to generate multiple element blocks (e.g. a whole 
periodic table), you're probably better off wrapping the contents of your 
#include file in a macro statement e.g. #macro Element() .... #end. Then you 
can #include it once and call it many times.

p.s. To revert to default settings between macro calls you can use #undef on 
textures, pigments or normals that were previously declared.

Regards,
Chris B.

#ifndef (Green)    #include "colors.inc" #end
#ifndef (T_Stone1) #include "stones.inc" #end

#ifndef(BlockTexture)
  #declare BlockTexture = texture {T_Stone1}
#end
#ifndef(WritingTexture)
  #declare WritingTexture = texture {
    #ifdef (WritingPigment) pigment {WritingPigment}
    #else pigment {Green}
    #end
    #ifdef (WritingNormal) pigment {WritingNormal}
    #else normal {agate scale 0.5}
    #end
  }
#end


#declare Silver = union{            // Element Tile
  difference{                       // Front Plate and Lettering
    box{<0, 0, 0>,                    // Box, Near lower left corner
      < 1.6, 2.2,  0.2>                   // Far upper right corner
      texture {BlockTexture}              // color
      translate <0, 0, 0>                 // location
    }
    text {ttf "Arial.ttf" "Ag" 5, 0   // text and symbol
      texture {WritingTexture}            // color
      scale 1                             // scale
      translate <.2, .5, -1>              // location
    }
    text {ttf "Arial.ttf" "47" 5, 0   // text and number
      texture {WritingTexture}            // color
      scale 0.6                           // scale
      translate <.1, 1.6, -1>             // location
    }
    translate <0.25, 0.25,  >           // location
  }

  difference{                   // Border and Back Plate
    box{<0, 0,   0>,              // Border, Near lower left corner
      < 2.1, 2.7,  0.3>             // Far upper right corner
      texture {T_Stone1}            // color
    }
    box{<0.15, 0.15, -0.1>,       // Negative Space, Near lower left corner
      < 1.95, 2.55,  0.2>           // Far upper right corner
      texture {WritingTexture}      // color
    }
  }
}


Post a reply to this message

From: OT
Subject: Re: Writing a .inc file
Date: 28 Jul 2009 12:50:01
Message: <web.4a6f2b6e2e2465d8411521dd0@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:
> "Jug" <nomail@nomail> wrote in message
> news:web.489bf2df611ced9672762ce30@news.povray.org...
> > Hi,
> >  I am new to POV-Ray and have no previous programming experience, so
> > please
> > forgive me if this is a simple question.  I a trying to write an .inc file
> > of
> > an etched tile.  I want the tile and the lettering to be two different
> > colors
> > and to be able to easily edit the colors of the tile from the scene file I
> > add
> > it into.  I know that if I do not include a color/texture in the .inc file
> > I
> > can define the it in the scene, but it makes the tile and writing the same
> > color/texture.  Is there a way I can determine or change the color/texture
> > of
> > the individual components of the tile from the scene file?  I would also
> > like
> > to be able to easily change  the pigment, texture, and finish of the tile
> > in
> > the .inc file from the scene file.  Do I need to include the standard .inc
> > files, such as colors, textures, or stones1 into my .inc file, or will it
> > work
> > if I include them in the scene?  I have included my tile below and added
> > in the
> > color and texture as an example of what I am trying to do.  Thanks a lot
> > for any
> > help you can give me.
> >
> > Jug
>
> Hi and Welcome.
>
> There are actually lots of approaches you could take.
>
> I very much prefer the approach that I've illustrated below using #ifdef and
> #ifndef to define default texture values. As you can see from the
> 'WritingTexture' declaration, you can nest these to provide the sort of
> flexibility you mentioned in your question: If 'WritingTexture' is already
> defined by the time your include file is parsed, it'll use that. Otherwise
> if 'WritingPigment' or 'WritingNormal' are defined it'll use them to
> construct 'WritingTexture'. If none are defined it'll just define defaults
> and plough on regardless.
>
> You can use a similar technique to define any #include files that you're
> dependent upon if they weren't already included.
>
> By testing for everything you need you can make a very robust little
> #include file. By providing defaults for everything, anyone can start using
> the file without having to initially worry about setting variables,
> parameters etc.
>
> If you're planning to generate multiple element blocks (e.g. a whole
> periodic table), you're probably better off wrapping the contents of your
> #include file in a macro statement e.g. #macro Element() .... #end. Then you
> can #include it once and call it many times.
>
> p.s. To revert to default settings between macro calls you can use #undef on
> textures, pigments or normals that were previously declared.
>
> Regards,
> Chris B.
>
> #ifndef (Green)    #include "colors.inc" #end
> #ifndef (T_Stone1) #include "stones.inc" #end
>
> #ifndef(BlockTexture)
>   #declare BlockTexture = texture {T_Stone1}
> #end
> #ifndef(WritingTexture)
>   #declare WritingTexture = texture {
>     #ifdef (WritingPigment) pigment {WritingPigment}
>     #else pigment {Green}
>     #end
>     #ifdef (WritingNormal) pigment {WritingNormal}
>     #else normal {agate scale 0.5}
>     #end
>   }
> #end
>
>
> #declare Silver = union{            // Element Tile
>   difference{                       // Front Plate and Lettering
>     box{<0, 0, 0>,                    // Box, Near lower left corner
>       < 1.6, 2.2,  0.2>                   // Far upper right corner
>       texture {BlockTexture}              // color
>       translate <0, 0, 0>                 // location
>     }
>     text {ttf "Arial.ttf" "Ag" 5, 0   // text and symbol
>       texture {WritingTexture}            // color
>       scale 1                             // scale
>       translate <.2, .5, -1>              // location
>     }
>     text {ttf "Arial.ttf" "47" 5, 0   // text and number
>       texture {WritingTexture}            // color
>       scale 0.6                           // scale
>       translate <.1, 1.6, -1>             // location
>     }
>     translate <0.25, 0.25,  >           // location
>   }
>
>   difference{                   // Border and Back Plate
>     box{<0, 0,   0>,              // Border, Near lower left corner
>       < 2.1, 2.7,  0.3>             // Far upper right corner
>       texture {T_Stone1}            // color
>     }
>     box{<0.15, 0.15, -0.1>,       // Negative Space, Near lower left corner
>       < 1.95, 2.55,  0.2>           // Far upper right corner
>       texture {WritingTexture}      // color
>     }
>   }
> }

Hi,
Any ideas on how to actually write a macro to arrange all the elements in a
table?
-OT


Post a reply to this message

From: Warp
Subject: Re: Writing a .inc file
Date: 28 Jul 2009 12:53:11
Message: <4a6f2cf7@news.povray.org>
OT <nomail@nomail> wrote:
> Any ideas on how to actually write a macro to arrange all the elements in a
> table?

http://povray.org/documentation/view/3.6.1/430/

-- 
                                                          - Warp


Post a reply to this message

From: Chris B
Subject: Re: Writing a .inc file
Date: 28 Jul 2009 14:02:53
Message: <4a6f3d4d@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message 
news:4a6f2cf7@news.povray.org...
> OT <nomail@nomail> wrote:
>> Any ideas on how to actually write a macro to arrange all the elements in 
>> a
>> table?
>
> http://povray.org/documentation/view/3.6.1/430/
>


I assume you mean the periodic table. My first instinct was, like Warp, to 
suggest arrays, but I don't think you actually need them. The macro below 
should do the job.  The reason for first assigning the text to variables 
rather than writing it directly into the scene is simply to allow it to be 
centre aligned within the box.

Regards,
Chris B.

camera {orthographic location <9, 15,-5> look_at <9,0,-5>}
global_settings { ambient_light 10}

#macro AddElement(Number, Symbol, Group, Period)
  union {
    box {<-0.4,-1,-0.4>,<0.4,-0.1,0.4> pigment {rgb BoxColor}}
    #local NumberText = text {ttf "timrom.ttf" Number 1,0 pigment {rgb 
TextColor} scale 0.4 rotate x*90}
    #local SymbolText = text {ttf "timrom.ttf" Symbol 1,0 pigment {rgb 
TextColor} scale 0.4 rotate x*90}
    object {NumberText translate 
z*0.2-(min_extent(NumberText)+max_extent(NumberText))/2}
    object {SymbolText 
translate -z*0.2-(min_extent(SymbolText)+max_extent(SymbolText))/2}
    translate <Group,0,-Period>
  }
#end

#declare TextColor = <2,0,0>;
#declare BoxColor = <0.5,1,0.5>;
AddElement(  "1","H" ,  1,1)
#declare BoxColor = <0.5,1,1  >;
AddElement(  "2","He", 18,1)
// ...
#declare BoxColor = <1,0.3,0.3>;
AddElement(  "3","Li",  1,2)
AddElement( "11","Na",  1,3)
AddElement( "87","Fr",  1,7)
// ...


Post a reply to this message

From: Chris B
Subject: Re: Writing a .inc file
Date: 28 Jul 2009 17:03:00
Message: <4a6f6784@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote in message 
news:4a6f3d4d@news.povray.org...
>
> I assume you mean the periodic table. ...
>

I started playing around with the macro, changing the CSG 'union' to a 
'difference', adding the rest of the elements and a key. If this is what you 
want, it's now up on the Object Collection at:

http://lib.povray.org/searchcollection/index2.php?objectName=PeriodicTable&version=1.0&contributorTag=chrisb

Regards,
Chris B.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.