POV-Ray : Newsgroups : povray.newusers : Hi! Needin' some help with some stuff. : Re: Hi! Needin' some help with some stuff. Server Time
5 Jul 2024 04:45:35 EDT (-0400)
  Re: Hi! Needin' some help with some stuff.  
From: clipka
Date: 5 Jul 2010 12:29:54
Message: <4c320882$1@news.povray.org>
Am 05.07.2010 01:04, schrieb MCC900:

> That was my first thought as well...
> Having a patch of grass with a considerable size...
> And having it to repeat over the field.
> Still, I'm not sure on how can I achieve this...
> How do I assign a patch of grass to a mesh.
> Should be simple...

First of all, you'll want to use mesh, not mesh2; they'd generate the 
same data, but the former is usually easier to generate in SDL, while 
the latter is better suited for automatic conversion of data (e.g. .obj 
files converted for use in POV-Ray).

You'll also have to think a bit differently than you'd normally do with 
CSG objects: You can't just compose a grass patch mesh by merging grass 
blade sub-objects - you'll have to make it one huge bunch of triangles.

Maybe the easiest way to do it might be as follows:

- Think of how you'd model a single grass blade using only triangles. 
Store the necessary data in one or more arrays. (For instance, you could 
simply use one array of triangle corner points, with three consecutive 
entries defining a triangle.)

   #declare GrassTriangleCount = ...;
   #declare GrassPoints = array[GrassTriangleCount*3] {
     <...>, <...>, <...>,
     <...>, <...>, <...>,
     ...
   }

   #declare GrassPatch = mesh {

- Set up a loop construct to iterate over all the coordinates where you 
want to "plant" a grass blade inside the patch (e.g. two nested loops to 
iterate over over X and Y).

     #local X = 0;
     #while (X < 100)
       #local Y = 0;
       #while (Y < 100)

- In each iteration, compute the transformation you want to apply to 
this individual grass blade; you'll probably want a random rotation, 
maybe some random scaling, and of course the translation to its place.

         #local BladeTrans = transform {
           rotate    y * 360*rand(R)
           scale     0.5 + rand(R)
           translate <X/100-0.5, 0, Y/100-0.5>
         }

- Then, iterate over all the triangles in your array, inserting them 
into the mesh with the transformation applied.

         #local I = 0;
         #while (I < GrassTriangleCount*3)

           triangle {
             vtransform(GrassPoints[I + 0], BladeTrans),
             vtransform(GrassPoints[I + 1], BladeTrans),
             vtransform(GrassPoints[I + 2], BladeTrans)
           }

           #local I = I + 3;
         #end

- Finally, close the loops and the mesh.

         #local Y = Y + 1;
       #end
       #local X = X + 1;
     #end
   }

There: A simple patch of grass.

To avoid obvious repetitions when using the patch, you may want to 
rotate each copy randomly, or even generate a set of, say, five 
different patches to pick from.


Post a reply to this message

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