POV-Ray : Newsgroups : povray.binaries.animations : Uberpov persistent feature for animation of big scene : Re: Uberpov persistent feature for animation of big scene Server Time: 8 Mar 2021 12:51:42 GMT
  Re: Uberpov persistent feature for animation of big scene  
From: Kenneth
Date: 7 Jan 2018 20:10:01
clipka <ano### [at] anonymousorg> wrote:
>
> Take a look at the following macro, and compare it to your code:
>
>     #macro MyMacro()
>       #ifndef(FOO)
>       #declare FOO =
>         union {
>           #local TEX_1 = texture{...}
>           #local MY_BOX = box{0,1}
>           object{MY_BOX texture{TEX_1}
>           ...
>         }
>       #end
>       object{FOO}
>     #end
>
> Note how this assembles a union from local variables (which "die" each
> time the end of the macro is reached), and assigns the resulting object
> to a global variable, which will still be "alive" if the macro is
> invoked again later.
>

I never realized that a macro's result-- object(FOO)-- was a global variable
that remained 'alive' in a scene once the macro was invoked. Is that
specifically because #ifndef is used here? (Actually, I'm guessing that it has
nothing to do with #ifndef.)

I always thought the *entire* contents of a macro died after each use (as if
object(FOO) was always a #local thing as well.) So in effect, the result is
'cached' for use later. Very interesting!

I'm thinking of another example, just to help clarify the concept:

#macro MyMacro()
pigment{image_map{tiff "MY_IMAGE.tif"}} // a large hi-res file
#end

Same cached behavior? (i.e., is the pigment already treated as a 'global'
thing)? Or does the macro need to be like this instead:

#macro MyMacro()
#local FOO = pigment{image_map{tiff "MY_IMAGE.tif"}}
pigment{FOO}
// or maybe just FOO by itself?
#end

Sorry for getting a bit off-topic. Although I've used macros plenty of times,
there are still a few mysteries that I need to fully understand.


Post a reply to this message

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