POV-Ray : Newsgroups : povray.general : Grass macro : Re: Grass macro Server Time
4 May 2024 01:32:46 EDT (-0400)
  Re: Grass macro  
From: Jonathan
Date: 17 Jul 2006 11:34:15
Message: <44bbadf7@news.povray.org>
This should get you started. Note that to cover only the floor that I had to 
take the difference of the area. The translate -y is to move the cube down 
to intersect the floor. That difference object is never put into the scene 
but only used as a reference for the trace() function. I did not implement 
rotation or random placement to make the grass look more "natural" random 
placement should be calculated before the trace() function is used. If the 
area your trying to cover is viewed from a distance, do not worry about 
blade intersection; however, if viewed up-close, the bounding box or the 
trace() function (which would allow closer blades at the cost of 
calculations and multiple testing, perhaps a hybrid method?) could be used 
to make sure blades don't intersect.  Again I hope this gets you started. 
Sorry my last post wasn't of much use.

Thanks,
Jonathan

#include "functions.inc"
#include "colors.inc"
#include "mgrass.pov"

#declare Which = 0;             //0= Sample 1=Floor

#declare lPatch=1;               // size of patch
#declare nBlade=2;                // number of blades per line (there will 
be nBlade x nBlade blades)
#declare ryBlade = 0;            // initial y rotation of blade
#declare segBlade= 15;            // number of blade segments
#declare lBlade = 25;             // length of blade
#declare wBlade = 1;              // width of blade at start
#declare wBladeEnd = 0.3;         // width of blade at the end
#declare doSmooth=false;          // true makes smooth triangles
#declare startBend = <0,1,0.3>;   // bending of blade at start (<0,1,0>=no 
bending)
#declare vBend = <0,-0.5,0>;         // force bending the blade (<0,1,1> = 

#declare pwBend = 3;              // bending power (how slowly the curve 
bends)
#declare rd = 459;                // seed
#declare stdposBlade = 1;         // standard deviation of blade position 
0..1
#declare stdrotBlade = 360;       // standard deviation of rotation
#declare stdBlade = 1.2;           // standard deviation of blade scale;
#declare stdBend = 2;            // standard deviation of blade bending;
#declare dofold = true;          // true creates a central fold in the blade 
(twice more triangles)
#declare dofile = false;          // true creates a mesh file
#declare fname = "fgrass1.inc"     // name of the mesh file to create


background { color rgb <225,245,246>/255 }
camera {
location <-2,1,-5> //<-2,4,-4>
look_at <0,1,0>
}

//------------floor box--------------
#declare Floor=box {
<-3,0,-3>
<3,0,3>
texture {pigment {color rgb<155,155,200>/255}}
}



//----------- sample box-------------
#declare Sample = box {
<-1,0,-1>
<1,2,1>
texture {pigment{color Red}}
}



 #if (Which)
  #declare Surface=difference { object {Floor} object {Sample translate -y}}
  #declare Area=3;
  #declare Step=1.5;
 #else
   #declare Surface=object {Sample}
   #declare Area=1;
   #declare Step=.5;
 #end

light_source {
<-1,10,-4>
color White}

//-----------------------------------------------------------


object {Sample}
object {Floor}

#local Z=-Area;
#while (Z < Area)
        #local X=-Area;
        #while (X < Area)

                #declare Norm = <0, 0, 0>;
                #declare Start = <X, 4, Z>;
                #declare Inter= trace ( Surface, Start, <X, 0, Z>-Start, 
Norm );

                #if (vlength(Norm)!=0)
                       
object{MakeGrassPatch(lPatch,nBlade,ryBlade,segBlade,lBlade,wBlade,wBladeEnd,doSmooth,startBend,vBend,pwBend,rd,stdposBlade,stdrotBlade,stdBlade,stdBend,dofold,dofile,fname)
scale .1 translate Inter pigment { color Green }}
                        #end
                #local X=X+Step;
                #end
        #local Z=Z+Step;

        #end


Post a reply to this message

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