|
|
On 22-10-2015 16:48, TomB wrote:
> Okay, so I have what is probably another very simple question.
>
> I have created a very simple text file, which contains the line:
>
> <0,5,0>
>
> and then us the following code to draw a sphere at the position given by teh
> vector in the file:
>
> #include "colors.inc"
> light_source { <100,1000,-1000>, White}
> camera { location <0,0,-20> look_at <0,0,0>}
>
> #fopen FileHandle "coords.txt" read
> #read (FileHandle,coordVector)
> #fclose FileHandle
>
> sphere{<coordVector.x,coordVector.y,coordVector.z>,1 pigment{color Red}}
>
> This all works nicely. However, is there a way to read in an arbitrary number of
> lines from the text file, like:
>
> <0,5,0>
> <0,0,0>
> ....
> ....
> <xn,yn,zn>
>
>
> and draw the corresponding spheres, without using any loops... i.e. is it
> possible for POV-Ray to import and work with a single matrix, where the first
> column is all the x coordinates, etc.
>
> Many thanks,
>
> Tom
>
>
>
>
Yes, that is very simple to do with a defined() function. In your case
that would be:
#fopen FileHandle "coords.txt" read
union {
#while (defined (FileHandle))
#read (FileHandle,coordVector)
sphere {coordVector, Radius
texture {MyTexture}
}
#end
} //close union
#fclose FileHandle
Note that your text file needs separators between entries, except the
last one:
<0,5,0>,
<0,0,0>,
....,
....,
<xn,yn,zn>
--
Thomas
Post a reply to this message
|
|