![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
The #read section in the docs says that a vector identifier used in this way
should be predeclared. You've declared the array, but not initialised the
element you're trying to read into. Try:
#fopen MyFile "myData.txt" read
#local i = 1;
#while (i<2)
#local Vector[i] = <0,0,0>;
#read (MyFile,Vector[i])
#local i = i + 1;
#end
Also note that arrays are zero-based in index, and your code will only attempt
to read 1 vector from the file. You should set i = 0 instead, unless I have
misread your intentions!
Bill
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
It seems to me that arrays are unduly complicated in use here.
Personally, I would prefer the following:
#fopen MyFile "myData.txt" read
#while (defined(MyFile))
#read (MyFile,Vector)
#end
see: 3.2.2.3.3 The #read Directive
Thomas
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Thank you both Thomas and Bill for your comments.
I came up with 2 versions that work. One defines an array for the points, and
the other seems to work just as well without it.
Here are the 2 versions.
1) No array
#fopen MyFile "Set_of_PointsXYZ.txt" read
#local i = 0;
#while (defined(MyFile))
#read (MyFile,Vector)
sphere { Vector, 0.1
texture {
pigment{ rgb <1,0,0>}
finish { Substance }}}
#local i = i + 1;
#end
2) Using an array
#declare Vector = array[100000];
#fopen MyFile "Set_of_PointsXYZ.txt" read
#local i = 0;
#while (defined(MyFile))
#local Vector [i] = <0,0,0>;
#read (MyFile,Vector[i])
sphere { Vector[i], 0.1
texture {
pigment{ rgb <1,0,0>}
finish { Substance }}}
Again, thanks so much for your assistance.
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
It looks like for your no-array option, you don't need "i" either.
Charles
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
> Thank you both Thomas and Bill for your comments.
>
> I came up with 2 versions that work. One defines an array for the points, and
> the other seems to work just as well without it.
>
> Here are the 2 versions.
>
> 1) No array
>
> #fopen MyFile "Set_of_PointsXYZ.txt" read
>
> #local i = 0;
> #while (defined(MyFile))
> #read (MyFile,Vector)
> sphere { Vector, 0.1
> texture {
> pigment{ rgb<1,0,0>}
> finish { Substance }}}
> #local i = i + 1;
> #end
>
> 2) Using an array
>
> #declare Vector = array[100000];
> #fopen MyFile "Set_of_PointsXYZ.txt" read
> #local i = 0;
> #while (defined(MyFile))
> #local Vector [i] =<0,0,0>;
> #read (MyFile,Vector[i])
> sphere { Vector[i], 0.1
> texture {
> pigment{ rgb<1,0,0>}
> finish { Substance }}}
>
> Again, thanks so much for your assistance.
>
>
Unless you plan having each spheres painted with different textures, you
should use an union and aply the texture to the union as a whole.
Using your non-array solution, it gives this:
#fopen MyFile "Set_of_PointsXYZ.txt" read
#declare DotedSphere=
union{
#while (defined(MyFile))
#read (MyFile,Vector)
sphere { Vector, 0.1}
#end
texture{pigment{rgb<1,0,0>}finish{Substance}}
}
Faster to parse as it uses less statements and takes less place in
memory. If you have 100000 points or more, the memory requirement can
become an isue.
It may also be faster to render.
You can #declare the union and use it in more than one place.
Alain
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
In the no array version, there is no need for i. Defined takes care of
it all. What Alain says is important. It is a technique that I use for
all of my scenes with a write/read code. And you can make the union
and/or the while loop as complex as you want of course.
Thomas
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Thomas de Groot <tenDOTlnDOTretniATtoorgedDOTt> wrote:
> It seems to me that arrays are unduly complicated in use here.
Indeed. Although an array would be useful if the positions were to be used
repeatedly. I've had to use #read and arrays like this before.
Bill
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Thomas de Groot wrote:
> It seems to me that arrays are unduly complicated in use here.
> Personally, I would prefer the following:
>
> #fopen MyFile "myData.txt" read
> #while (defined(MyFile))
> #read (MyFile,Vector)
> #end
but for this you need a way to specify that a vector
should be read instead of a scalar, either by introducing
typed variables or requiring additional parameters.
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On 6-1-2012 15:20, Christian Froeschlin wrote:
> Thomas de Groot wrote:
>> It seems to me that arrays are unduly complicated in use here.
>> Personally, I would prefer the following:
>>
>> #fopen MyFile "myData.txt" read
>> #while (defined(MyFile))
>> #read (MyFile,Vector)
>> #end
>
> but for this you need a way to specify that a vector
> should be read instead of a scalar, either by introducing
> typed variables or requiring additional parameters.
I cannot pretend to know exactly what you mean :-) but in my simple
vision and use of this, I write and then read a vector (or a float or
whatever, e.g. text) according to my needs. You only have to take care
that you use a vector as such or a text as such and not make a
hotchpotch of things. #read reads and interprets what is between the
commas: if this is a vector, it reads a vector, etc. doesn't it?
Thomas
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Just wanted to thank Alain and Thomas for those additional comments.
It is very helpful to get this feedback. It is a great resource.
Thanks so much for taking the time to contribute to this discussion.
scott
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |