POV-Ray : Newsgroups : povray.newusers : meshes and rotation Server Time
26 Nov 2024 21:28:33 EST (-0500)
  meshes and rotation (Message 1 to 3 of 3)  
From: Justin Smith
Subject: meshes and rotation
Date: 20 Nov 2003 22:20:02
Message: <web.3fbd82efbdd378f4a5634560@news.povray.org>
I'm trying to use a mesh to generate a clump of grass. I'm having a problem
because apparently I can't rotate the individual triangles within the mesh.
I'll show the erroneous code I'm using, so you can see what I am trying to
do:

#declare grassclump =
mesh
{
  #local numblades = 0;
  #local maxblades = 60+int((rand(randseed)*40));
  #while(numblades < maxblades)
    #local rotationx = rand(randseed)*30;
    #local rotationy = rand(randseed)*360;
    triangle
    {
      <.02,0,0>,<-.02,0,0>,<.018,1.2,0>
      rotate < rotationx,0,0>
      rotate <0,rotationy,0>
    }
    triangle
    {
      <-.02,0,0>,<-.018,1.2,0>,<.018,1.2,0>
      rotate < rotationx,0,0>
      rotate <0,rotationy,0>
    }
    triangle
    {
      <-.018,1.2,0>,<.018,1.2,0>,<0,2.5,0>
      rotate < rotationx,0,0>
      rotate <0,rotationy,0>
    }
    #local numblades = numblades+1;
  #end
  texture
  {
    pigment
    {
      color rgb <.1,1,.26>
    }
  }
}

I am using 500,000 of these clumps of grass in my scene, randomly placed. I
could just keep the grassblade as the individual mesh and then use union to
form the clump, but as I have so many, I think I need to be able to keep
the whole clump as a single mesh to keep the number of objects down, right?


Post a reply to this message

From: Mike Williams
Subject: Re: meshes and rotation
Date: 20 Nov 2003 23:32:33
Message: <U+zGgFAOUZv$EwsQ@econym.demon.co.uk>
Wasn't it Justin Smith who wrote:
>I'm trying to use a mesh to generate a clump of grass. I'm having a problem
>because apparently I can't rotate the individual triangles within the mesh.
>I'll show the erroneous code I'm using, so you can see what I am trying to
>do:

You could use syntax like this to rotate the points individually and
then use the rotated points to form the mesh

#declare grassclump =
mesh
{
  #local numblades = 0;
  #local maxblades = 60+int((rand(randseed)*40));
  #while(numblades < maxblades)
    #local rotationx = rand(randseed)*30;
    #local rotationy = rand(randseed)*360;
    triangle
    {
      #declare P1 = vrotate(<.02,0,0>,<rotationx,rotationy,0>);
      #declare P2 = vrotate(<-.02,0,0>,<rotationx,rotationy,0>);
      #declare P3 = vrotate(<.018,1.2,0>,<rotationx,rotationy,0>);
      P1,P2,P3
    }
    triangle
    {
      #declare P1 = vrotate(<-.02,0,0>,<rotationx,rotationy,0>);
      #declare P2 = vrotate(<-.018,1.2,0>,<rotationx,rotationy,0>);
      #declare P3 = vrotate(<.018,1.2,0>,<rotationx,rotationy,0>);
      P1,P2,P3
    }
    triangle
    {
      #declare P1 = vrotate(<-.018,1.2,0>,<rotationx,rotationy,0>);
      #declare P2 = vrotate(<.018,1.2,0>,<rotationx,rotationy,0>);
      #declare P3 = vrotate(<0,2.5,0>,<rotationx,rotationy,0>);
      P1,P2,P3
    }
    #local numblades = numblades+1;
  #end
  texture
  {
    pigment
    {
      color rgb <.1,1,.26>
    }
  }
}

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Christopher James Huff
Subject: Re: meshes and rotation
Date: 21 Nov 2003 14:38:44
Message: <cjameshuff-C8A151.14332621112003@netplex.aussie.org>
In article <web.3fbd82efbdd378f4a5634560@news.povray.org>,
 "Justin Smith" <t74### [at] yahoocom> wrote:

> I'm trying to use a mesh to generate a clump of grass. I'm having a problem
> because apparently I can't rotate the individual triangles within the mesh.
> I'll show the erroneous code I'm using, so you can see what I am trying to
> do:
...snip...
> I am using 500,000 of these clumps of grass in my scene, randomly placed. I
> could just keep the grassblade as the individual mesh and then use union to
> form the clump, but as I have so many, I think I need to be able to keep
> the whole clump as a single mesh to keep the number of objects down, right?

Right general idea...you need to have it a single mesh, so you can copy 
it and have several objects that refer to the same object. However, you 
can't apply transformations to individual mesh triangles as you can to 
triangle objects. Someone already mentioned the vrotate() function, if 
you have a more complex transformation, you might try the vtransform() 
macro in transforms.inc. To keep things fairly organized, you might want 
to make a macro to create transformed triangles:

#macro Triangle(PtA, PtB, PtC, Trans)
    #local tmpFn = function {transform {Trans}};
    triangle {
        tmpFn(PtA.x, PtA.y, PtA.z),
        tmpFn(PtB.x, PtB.y, PtB.z),
        tmpFn(PtC.x, PtC.y, PtC.z),
    }
#end

mesh {
    ...
    Triangle(<.02,0,0>, <-.02,0,0>, <.018,1.2,0>,
        transform {
            rotate < rotationx,0,0>
            rotate <0,rotationy,0>
        }
    }

(the transform{} block is necessary)

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

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