|
![](/i/fill.gif) |
"slongay" <slo### [at] gmail com> wrote in message
news:web.48f8150ade4da0652ebc1c00@news.povray.org...
> So I tried combining my trees into two big meshes, one for the leaves and
> one
> for the branches.
>
> This works, but I have to say that it is really quite ugly. The leaves are
> one
> of three meshes but transformed differently. So when I roll out my leaves
> into
> one big mesh I have to transform the triangles for each leaf and write
> them our
> one by one. The file which contains my leaf mesh ends up being 841mb for
> an
> average sized tree! Obviously I have some optimizing I can do, it takes
> POVRay
> 27 minutes just to parse the file, but it only takes up 545mb in memory
> once
> parsed.
>
> But I guess my real question is: Is there any way to do a hierarchical
> instancing in POVray? So I can just declare my leaf mesh's and then say
> where
> they are in the scene with-out having to combine them all into one big
> mesh? I
> believe you guys have already said no but I just wanted to rephrase my
> question
> to be sure.
You can separate out the definition of your leaf coordinates from the mesh
declaration, which seems to me to give you the best of both worlds. You get
a clean, small scene file where you define your leaf shapes and normals and
you get the speed of using a mesh, without large amounts of IO to perform.
The following example declares two leaf shapes as arrays of coordinate pairs
(Vertices and Normals).
The mesh definition selects randomly between the two available leaves and
calls a macro to add the necessary number of smooth triangles, scaling,
rotating and translating the leaves into position (into a random position in
this case).
I should mention that this scene file is just intended to illustrate the way
you could code stuff and I know that the rendered image looks nothing much
like a tree :-). With 100,000 leaves this took about 30 minutes to render on
a 4-way 2.3GHz machine and with 1000 leaves just a few seconds.
Regards,
Chris B.
camera {location <0,5,-1> look_at 0}
light_source {<-10,50,-10>, rgb 1}
#declare Leaves = 1000;
#declare MySeed = seed(1);
#declare Leaf1 = array[6][3] {
{0,0,0},{0,1,0},
{0,0,1},{0,1,0},
{1,0,0},{0,1,0}
};
#declare Leaf2 = array[12][3] {
{0,0,0},{0,1,0},
{0,0,1},{0,1,0},
{1,0,1},{0,1,0},
{0,0,0},{0,1,0},
{1,0,1},{0,1,0},
{1,0,0},{0,1,0}
};
#macro DrawLeaf (Leaf)
#declare Rotation = <rand(MySeed),rand(MySeed),rand(MySeed)>*360;
#declare Translation = <rand(MySeed),rand(MySeed),rand(MySeed)>-0.5;
#declare Scale = <rand(MySeed),rand(MySeed),rand(MySeed)>*0.1+1;
#local J = 0;
#while (J<dimension_size(Leaf,1)/6)
smooth_triangle {
#local K = 0;
#while (K<3)
#declare Vertex =
<Leaf[J*6+K*2][0],Leaf[J*6+K*2][1],Leaf[J*6+K*2][2]>;
#declare Normal =
<Leaf[J*6+K*2+1][0],Leaf[J*6+K*2+1][1],Leaf[J*6+K*2+1][2]>;
#declare Vertex = vrotate(Vertex*Scale,Rotation)+Translation;
#declare Normal = vrotate(Normal,Rotation);
Vertex Normal
#local K = K + 1;
#end
}
#local J = J+1;
#end
#end
#declare Tree = mesh {
#local I = 0;
#while (I<Leaves)
#if (rand(MySeed)<0.5) DrawLeaf(Leaf1)
#else DrawLeaf(Leaf2)
#end
#local I = I+1;
#end
pigment {rgb <0,1,0>}
}
object {Tree}
Post a reply to this message
|
![](/i/fill.gif) |