POV-Ray : Newsgroups : povray.general : Where to put initialisation code? Server Time
24 Dec 2024 20:37:13 EST (-0500)
  Where to put initialisation code? (Message 1 to 5 of 5)  
From: pbrants
Subject: Where to put initialisation code?
Date: 14 Apr 2014 12:50:01
Message: <web.534c109829bb6ea84e8159130@news.povray.org>
As the word says, initialisation instructions should be running just ONCE before
the calculation of an animation should start. If I put these instructions in the
POV-file which is to be animated with the INI-file and clock-variable, then they
are executed with each change of the clock. How can I prevent this happening?

Paul


Post a reply to this message

From: Le Forgeron
Subject: Re: Where to put initialisation code?
Date: 14 Apr 2014 13:12:06
Message: <534c16e6$1@news.povray.org>
Le 14/04/2014 18:46, pbrants nous fit lire :
> As the word says, initialisation instructions should be running just ONCE before
> the calculation of an animation should start. If I put these instructions in the
> POV-file which is to be animated with the INI-file and clock-variable, then they
> are executed with each change of the clock. How can I prevent this happening?
> 

use a condition on clock or frame_number.

something like:

#if (clock <= 0)
...
#else
...
#end


Post a reply to this message

From: Ger
Subject: Re: Where to put initialisation code?
Date: 14 Apr 2014 13:31:41
Message: <534c1b7d$1@news.povray.org>
Le_Forgeron wrote:

> Le 14/04/2014 18:46, pbrants nous fit lire :
>> As the word says, initialisation instructions should be running just ONCE
>> before the calculation of an animation should start. If I put these
>> instructions in the POV-file which is to be animated with the INI-file
>> and clock-variable, then they are executed with each change of the clock.
>> How can I prevent this happening?
>> 
> 
> use a condition on clock or frame_number.
> 
> something like:
> 
> #if (clock <= 0)
> ...
> #else
> ...
> #end

All init stuff is lost at the start of the second frame unless it's written to a file.
At the start of any frame povray has no knowledge of what happened in the previous
frame unless stored.
So I would alter the example into

#if (clock <= 0)
  init your stuff
  #write stuff to disk
#else
  read stuff from disk
#end


-- 

Ger


Post a reply to this message

From: pbrants
Subject: Re: Where to put initialisation code?
Date: 14 Apr 2014 14:00:01
Message: <web.534c2045e6597704e8159130@news.povray.org>
OK, the #fopen statement should go into the init stuff, and what should I do to
prevent the file being closed after the first frame? Otherwise stated, what is
the sequence of #fopen read write append statements in the #if block? The
documentation of POV mentions something like this: "You may open, read, write,
append, and close plain ASCII text files while parsing POV-Ray scenes. This
feature is primarily intended to help pass information between frames of an
animation. Values such as an object's position can be written while parsing the
current frame and read back during the next frame", but nothing is elaborated.

Paul


Ger <No.### [at] ThankYou> wrote:
> Le_Forgeron wrote:
>
> > Le 14/04/2014 18:46, pbrants nous fit lire :
> >> As the word says, initialisation instructions should be running just ONCE
> >> before the calculation of an animation should start. If I put these
> >> instructions in the POV-file which is to be animated with the INI-file
> >> and clock-variable, then they are executed with each change of the clock.
> >> How can I prevent this happening?
> >>
> >
> > use a condition on clock or frame_number.
> >
> > something like:
> >
> > #if (clock <= 0)
> > ...
> > #else
> > ...
> > #end
>
> All init stuff is lost at the start of the second frame unless it's written to a
file.
> At the start of any frame povray has no knowledge of what happened in the previous
frame unless stored.
> So I would alter the example into
>
> #if (clock <= 0)
>   init your stuff
>   #write stuff to disk
> #else
>   read stuff from disk
> #end
>
>
> --
>
> Ger


Post a reply to this message

From: Ger
Subject: Re: Where to put initialisation code?
Date: 14 Apr 2014 14:47:03
Message: <534c2d27$1@news.povray.org>
pbrants wrote:

> OK, the #fopen statement should go into the init stuff, and what should I
> do to prevent the file being closed after the first frame? Otherwise
> stated, what is the sequence of #fopen read write append statements in the
> #if block? The documentation of POV mentions something like this: "You may
> open, read, write, append, and close plain ASCII text files while parsing
> POV-Ray scenes. This feature is primarily intended to help pass
> information between frames of an animation. Values such as an object's
> position can be written while parsing the current frame and read back
> during the next frame", but nothing is elaborated.
> 
> Paul
> 
The file WILL be closed at the end of the first frame.
So what you need to do is 

#if(clock<=0)
  [ whole bunch of init code here ]

  #fopen FileHandle "FileWithInitData" write
  #write(FileHandle, [all my data ])
  #fclose FileHandle

#else
  #fopen FileHandle "FileWithInitData" read
  #read (FileHandle, [ all my data ])
  #fclose FileHandle
#end

Keep in mind that whatever is written in the first block HAS to be read in the exact
same order in the second block.

However, sometimes it's far simpler to create an include file in the first block. The
second block then looks like this

#else
  #include "PreviouslyCreatedFile"
#end

-- 

Ger


Post a reply to this message

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