POV-Ray : Newsgroups : povray.general : Passing macro as parameter Server Time
31 Oct 2024 12:14:48 EDT (-0400)
  Passing macro as parameter (Message 1 to 7 of 7)  
From: Alessio Sangalli
Subject: Passing macro as parameter
Date: 13 Dec 2021 13:36:49
Message: <61b792c1$1@news.povray.org>
I am working on my own little animation framework for astronomy related 
scenes.

I would like the ability to pass a macro name to another macro that will:

1) do some animation-related setup and housekeeping
2) call the macro passed as parameter
3) do some more animation-related setup and housekeeping

Unfortunately I have not found a way to pass a macro name as parameter 
and be able to call it. Is this use case really beyond the capabilities 
of the language, or I just have to find the right syntax?

Thank you


Post a reply to this message

From: Bald Eagle
Subject: Re: Passing macro as parameter
Date: 13 Dec 2021 14:10:00
Message: <web.61b79a1b80f100541f9dae3025979125@news.povray.org>
Alessio Sangalli <man### [at] gmailcom> wrote:
3) do some more animation-related setup and housekeeping
>
> Unfortunately I have not found a way to pass a macro name as parameter
> and be able to call it.


http://www.povray.org/documentation/view/3.7.0/479/


Parse_String(String). This macro takes a string, writes it to a file, and then
includes that file. This has the effect of parsing that string:
"Parse_String("MyColor")" will be seen by POV-Ray as "MyColor".
Parameters:

String = The string to be parsed.



So, the idea is that you pass the macro name as a string parameter, and then
parse that string to turn it into an SDL directive.

If you provide some scene code with some comments describing what you want your
code to do, maybe someone can suggest an alternative method for accomplishing
the same goal.


Post a reply to this message

From: Alessio Sangalli
Subject: Re: Passing macro as parameter
Date: 13 Dec 2021 16:48:58
Message: <61b7bfca$1@news.povray.org>
On 13-Dec-21 11:08, Bald Eagle wrote:

>> Unfortunately I have not found a way to pass a macro name as parameter
>> and be able to call it.

> Parse_String(String)

> So, the idea is that you pass the macro name as a string parameter, and then
> parse that string to turn it into an SDL directive.

Fantastic, I'll try that.


> If you provide some scene code with some comments describing what you want your
> code to do, maybe someone can suggest an alternative method for accomplishing
> the same goal.

I'll perform some experiments and gladly publish them.

Thanks!


Post a reply to this message

From: jr
Subject: Re: Passing macro as parameter
Date: 14 Dec 2021 03:40:00
Message: <web.61b8575e80f10054ea8869266cde94f1@news.povray.org>
hi,

Alessio Sangalli <man### [at] gmailcom> wrote:
> On 13-Dec-21 11:08, Bald Eagle wrote:
> ...
> > Parse_String(String)
> ...
> Fantastic, I'll try that.

fwiw, my recent 'Foreach()' macro too uses that "trick".  given that your
project is well underway, you may not find it very useful though :-).

<https://drive.google.com/file/d/11PqhmEP2p1nEOH6jCJC653B08NfHVmOn/view?usp=sharing>


regards, jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: Passing macro as parameter
Date: 14 Dec 2021 06:50:00
Message: <web.61b8846f80f100541f9dae3025979125@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

> fwiw, my recent 'Foreach()' macro too uses that "trick".

What, did you think you think I came up with all these great ideas on my own?
I steal them from you!   :D   :P


Post a reply to this message

From: Alessio Sangalli
Subject: Re: Passing macro as parameter
Date: 15 Dec 2021 00:57:31
Message: <61b983cb$1@news.povray.org>
On 13-Dec-21 13:48, Alessio Sangalli wrote:

> I'll perform some experiments and gladly publish them.

It worked pretty good; a simplified version of what I have done is:

#macro animation_step(step_function, duration)
     #declare local_clock = (clock - animation_framework_current_stage) 
/ duration;
     Parse_String(concat(step_function, "(local_clock)"))
#end

I put in some more work today to improve my animation framework and used 
Parse_String() a couple more times.

Thanks


Post a reply to this message

From: Dick Balaska
Subject: Re: Passing macro as parameter
Date: 19 Dec 2021 16:26:43
Message: <61bfa393$1@news.povray.org>
On 12/15/2021 12:57 AM, Alessio Sangalli wrote:
> On 13-Dec-21 13:48, Alessio Sangalli wrote:
> 
>> I'll perform some experiments and gladly publish them.
> 
> It worked pretty good; a simplified version of what I have done is:
> 
> #macro animation_step(step_function, duration)
>      #declare local_clock = (clock - animation_framework_current_stage) 
> / duration;
>      Parse_String(concat(step_function, "(local_clock)"))
> #end

This is brilliant. I wish I'd thought of it years ago.

dik


Post a reply to this message

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