POV-Ray : Newsgroups : povray.advanced-users : Write macro-generated objects to file? Server Time
1 Nov 2024 03:15:34 EDT (-0400)
  Write macro-generated objects to file? (Message 1 to 4 of 4)  
From: Torsten Crass
Subject: Write macro-generated objects to file?
Date: 22 Jul 2003 11:49:28
Message: <3f1d5d08@news.povray.org>
Ooops - actually I wanted to post this to the "advanced" group right 
from the begining... I hope you don't mind that I still post it here 
although I accidently sent it to "general" first...

---8<---

Hi there!

When populating a scene with loads of macro-generated objects, I thought 
it would be a nice idea to run those time-consuming macros only once, 
write their "return values" (in this case: unions of triangles) to an 
.inc file and re-use this file when further experimenting with the 
scene. However, I couldn't figure out a way to write those objects to a 
file - the #write directive apparently only accepts strings, numbers and 
vectors.
Does anybody have a clue how one could save macro-generated objects to a 
file - i.e. use PovRay for creating its own .inc files?

Thanx in advance -

     Torsten


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Write macro-generated objects to file?
Date: 22 Jul 2003 12:36:27
Message: <3f1d680b$1@news.povray.org>
If you prepare the objects like strings, you can write your
own include files during parsing time:

#declare Sphere_Pos=<0,0,0>;
#fopen OutputFile "file_io.inc" write
#write (OutputFile, "sphere{",Sphere_Pos,",.5 pigment{rgb 1}}\n")
#fclose OutputFile

This would create file with sphere as content.
You just have to be a little creative! :-)

-- 
Tim Nikias v2.0
Homepage: http://www.digitaltwilight.de/no_lights

> Ooops - actually I wanted to post this to the "advanced" group right
> from the begining... I hope you don't mind that I still post it here
> although I accidently sent it to "general" first...
>
> ---8<---
>
> Hi there!
>
> When populating a scene with loads of macro-generated objects, I thought
> it would be a nice idea to run those time-consuming macros only once,
> write their "return values" (in this case: unions of triangles) to an
> .inc file and re-use this file when further experimenting with the
> scene. However, I couldn't figure out a way to write those objects to a
> file - the #write directive apparently only accepts strings, numbers and
> vectors.
> Does anybody have a clue how one could save macro-generated objects to a
> file - i.e. use PovRay for creating its own .inc files?
>
> Thanx in advance -
>
>      Torsten
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.501 / Virus Database: 299 - Release Date: 14.07.2003


Post a reply to this message

From: Torsten Crass
Subject: Re: Write macro-generated objects to file?
Date: 23 Jul 2003 06:35:11
Message: <3f1e64df$1@news.povray.org>
Hi Tim,

> #declare Sphere_Pos=<0,0,0>;
> #fopen OutputFile "file_io.inc" write
> #write (OutputFile, "sphere{",Sphere_Pos,",.5 pigment{rgb 1}}\n")
> #fclose OutputFile
> 
> This would create file with sphere as content.
> You just have to be a little creative! :-)

_that_ creative I've been already... ;-) I just would like to use the 
same (complex) macro to create both .inc files and ready-to-use objects. 
  Seems, however, not possible due to the lack of some kind of 
to_string(OBJECT) function... sigh!

Thanx anyway -

	Torsten


Post a reply to this message

From: Florian Brucker
Subject: Re: Write macro-generated objects to file?
Date: 24 Jul 2003 11:00:45
Message: <3f1ff49d$1@news.povray.org>
Hey Torsten!

What is the problem with using File-Output-Macros only?

<code>
#include "colors.inc"

camera {
    location 5
    look_at 0
}

light_source { 100 White }

#macro Thingy(X1,X2,Filename,AutoInclude)
    #fopen MyFile Filename write
    #write(MyFile, "sphere { 0,1 scale ",X1," translate ",X2," }")
    #fclose MyFile
    #if (AutoInclude) #include Filename #end
#end

object {
    Thingy(<1,0.2,3>,2,"thingy.inc",on)
    pigment { Green }
}
</code>

The only problem is that you'll have the overhead of writing to disk /
parsing include-files every render, but that should not be the problem.

HTH,
Florian


Post a reply to this message

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