POV-Ray : Newsgroups : povray.general : Is it possible to have optional arguments in macros. Server Time
31 Jul 2024 00:35:08 EDT (-0400)
  Is it possible to have optional arguments in macros. (Message 1 to 4 of 4)  
From: Bridgeofstraws
Subject: Is it possible to have optional arguments in macros.
Date: 29 Apr 2008 07:05:01
Message: <web.4816ffbf42eefae121397d5a0@news.povray.org>
Hello everyone,

I was wondering if it is possible to develop a way so that the M22 object may
not necessarily need all 4 textures.  Whether it be by making optional macros
or special if statements that compare textures (because I could make a null
texture).  Thank you for you time and help!

The code of my macros is below.

#macro M22 (BodyTexture1, BodyTexture2, ConeTexture, ImperfectionTexture)
        object{
                union{
                        #switch(CSGOrIsosurface)
                                #case(1)
                                        object{CSGM22Chassis
                                        texture {BodyTexture1}
                                        texture {BodyTexture2}
                                        texture {ConeTexture} //This is used
with any texture to create a different coloured cone for the plane
                                        texture {ImperfectionTexture}
                                        translate z*15}
                                #break
                                //--OR--
                                #case(2)
                                        object{MeshM22Chassis
                                        //the next 2 lines, adjust for blenders
exporter
                                        translate z*-1.5
                                        scale 10
                                        //
                                        texture {BodyTexture1}
                                        texture {BodyTexture2}
                                        texture {ConeTexture} //This is used
with any texture to create a different coloured cone for the plane
                                        texture {ImperfectionTexture}
                                        translate z*15
                                        }
                                #break
                                //--OR--
                                #case(3)
                                        object{IsoM22Chassis
                                        texture {BodyTexture1}
                                        texture {BodyTexture2}
                                        texture {ConeTexture} //This is used
with any texture to create a different coloured cone for the plane
                                        texture {ImperfectionTexture}
                                        translate z*15}
                                #break
                        #end

                        object{Cockpit interior{ior 1.3}}
                        scale 1/2  //make this plane a realistic size
                        //add any weapons here

                }

        }
        #end


Post a reply to this message

From: Chris B
Subject: Re: Is it possible to have optional arguments in macros.
Date: 29 Apr 2008 11:24:17
Message: <48173da1$1@news.povray.org>
"Bridgeofstraws" <bri### [at] inboxcom> wrote in message 
news:web.4816ffbf42eefae121397d5a0@news.povray.org...
> Hello everyone,
>
> I was wondering if it is possible to develop a way so that the M22 object 
> may
> not necessarily need all 4 textures.  Whether it be by making optional 
> macros
> or special if statements that compare textures (because I could make a 
> null
> texture).  Thank you for you time and help!
>
> The code of my macros is below.
>
> #macro M22 (BodyTexture1, BodyTexture2, ConeTexture, ImperfectionTexture)
>        object{
>                union{
>                        #switch(CSGOrIsosurface)
>                                #case(1)
>                                        object{CSGM22Chassis
>                                        texture {BodyTexture1}
>                                        texture {BodyTexture2}
>                                        texture {ConeTexture} //This is 
> used
> with any texture to create a different coloured cone for the plane
>                                        texture {ImperfectionTexture}
>                                        translate z*15}
> ... snip ...

Hi,

I don't think you can 'compare' textures. However, A number of alternative 
ideas do spring to mind to enable you to selectively use them, for example:

1.  You could define a completely transparent texture and pass that into the 
macro whenever you don't want to use an actual texture for that layer. e.g.:

 #declare MyBlank = texture {pigment {rgbt 1}}
 M22(MyBlank, MyBlank, texture {...}, etc...

2.  You could use global identifiers instead of parameters, then test for 
their existence within your macro e.g.:

#declare MyGlobalBodyTexture1 = texture { ...}

#macro M22 ()
... snip ...
 object{CSGM22Chassis
   #ifdef (MyGlobalBodyTexture1)
     texture {MyGlobalBodyTexture1}
   #end
   #ifdef (MyGlobalBodyTexture2)
     texture {MyGlobalBodyTexture2}
   #end
... etc.  ...

Making sure that at least one texture is always defined. You could do that 
by using #ifndef to set a default texture whenever it hasn't been set 
globally outside the macro call e.g.:

#ifndef(MyGlobalConeTexture)
  #local MyGlobalConeTexture = texture {pigment {color Red}}
#end

>                                #break
>                                //--OR--
>                                #case(2)
>                                        object{MeshM22Chassis
>                                        //the next 2 lines, adjust for 
> blenders
>

p.s.  If you want to use the same textures for all of your different 
possible chassis object definitions, you should be able to reduce your code 
with:

object {
#switch(CSGOrIsosurface)
  #case(1) CSGM22Chassis #break
  #case(2) MeshM22Chassis #break
  #else       IsoM22Chassis
#end
texture {BodyTexture1}
texture {BodyTexture2}
... etc. ...

or by passing the object in as a parameter to the macro call, so that it 
always has the same name.

Regards,
Chris B.


Post a reply to this message

From: Bridgeofstraws
Subject: Re: Is it possible to have optional arguments in macros.
Date: 29 Apr 2008 14:30:01
Message: <web.481769204b6dcecdd67c2c340@news.povray.org>
I've used your suggestions and it works great! Thanks for the help Chris.


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Is it possible to have optional arguments in macros.
Date: 29 Apr 2008 16:33:52
Message: <48178630@news.povray.org>
Bridgeofstraws wrote:

> I was wondering if it is possible to develop a way so that the M22 object may
> not necessarily need all 4 textures.  Whether it be by making optional macros
> or special if statements that compare textures (because I could make a null
> texture). 

One possibility would be to provide flags as explicit parameters as in

#macro M22_INTERN(USE_T1, T1, USE_T2, T2)
...
#if (USE_T1)
   texture {T1}
#end
...
#end

and provide convenience macro wrappers such as

#macro M22_1(T)
   M22_INTERN(true,T,false,T)
#end

#macro M22_2(T1,T2)
   M22_INTERN(true,T1,true,T2)
#end


But actually, I think in your case it is simply possible to write

#macro M22 (TextureList)
...
   object{CSGM22Chassis
   texture {TextureList}
...
#end

and calling it like

M22(texture {BodyTexture1} texture {BodyTexture2})


Post a reply to this message

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