POV-Ray Reproducable Compound Object ?

POV-Ray Reproducable Compound Object ?

Post by br_spambuc » Sun, 19 Jun 2005 05:11:11

Hi Guys,

I come from a programming background. In POV-Ray, I would like to be
able to create a "class" or "function" in the programming sense so that
I can make multiple instances of a type of compound object, all similar
to each other, but with different locations and other attributes

For example, now that I know how to put text on a box to make a sign, I
would like to create a new type of class or function, called "sign",
which will be callable with attributes such as location, orientation,
background color, text color, and text content. Each time POV-Ray
executes "sign{attribute, attribute...}, a new sign will appear in the
3-D image.

It appears that I may be able to create a macro to do this. I'm
wondering if this is the right way to do this type of thing. Is there
some better construct?

Your comments greatly appreciated.


POV-Ray Reproducable Compound Object ?

Post by Mike Willi » Sun, 19 Jun 2005 06:17:36

Yes, #macro is exactly what you want. It goes something like this:

#version 3.6;
global_settings {assumed_gamma 1.0}
camera {location <0,1,-10> look_at <0,1,0> angle 50}
background {rgb 1}
light_source {<-30, 100, -30> color rgb 2}

// Create the macro
#macro Sign(Location,Rotation,BGColour,FGColour,Text)
// Temporary text object
#local T=text{ttf "crystal.ttf" Text 2 0 }
// Centred text object
#local Tc = object{T translate -(min_extent(T)+max_extent(T))/2}
// The sign
box {<min_extent(Tc).x-0.5,min_extent(Tc).y-0.5,-0.5>,
pigment {object {Tc rgb BGColour rgb FGColour}}
rotate Rotation
translate Location

// Invoke the macro as required
// Location Rotation B-Colour F-Colour Text
Sign(<0,0,0>, <0,0,0>, <0,0,0>, <0,1,0>, "EXIT")
Sign(<0,2,0>, <0,20,20>, <1,0,0>, <1,1,1>, "Entrance")

Mike Williams
Gentleman of Leisure


POV-Ray Reproducable Compound Object ?

Post by Chri » Mon, 20 Jun 2005 05:48:56

I agree with Mike, macros are very good for this sort of thing.
Furthermore, with Mike's example you can also assign the output from the
macro to a variable, then use the variable as an object:

#declare ExitSign = Sign(<0,0,0>, <0,0,0>, <0,0,0>, <0,1,0>, "EXIT")
object {ExitSign translate -y rotate y*70}
object {ExitSign translate 5*x rotate -y*40}

Chris B.