POV-Ray : Newsgroups : povray.text.scene-files : cells_02.pov : Re: cells_02.pov Server Time
6 Oct 2024 08:17:38 EDT (-0400)
  Re: cells_02.pov  
From: Pete
Date: 1 Oct 2000 19:00:50
Message: <9777.308T139T11193016PeterC@nym.alias.net>
Warp wrote:


>  Isn't it incredible how fast this renders?

        Yup.

>  There are more than 23 millions of triangles (exactly 23251968) in the
>scene and it took 40 seconds to render at 640x480.

        I'm glad I didn't do that calculation, or I would have been
afraid to render it!

>  I suppose that if you had used cubes instead of triangles (so there
>would have been almost 2 million cubes in the scene) it would have taken
>hours to render.

        My machine would have keeled over.

>  I actually tried using boxes instead of triangles and run out of memory,
>so I couldn't test how much time it would have taken.

>--
>main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
>):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/

        Something about how pov handles meshes is realy efficient
time-wise as well as memory-wise.  I guess that's why Gilles'
grass macro can make a prarie so fast, it is all meshes.

        Since posting that .pov file, I have been playing around with
variations on the mesh-to infinity process.  :-).
        Here is a .pov script that tiles larger more complex
shapes.  Enjoy.

--

global_settings {
  assumed_gamma 2.4
  number_of_waves 9
}


#declare ntsc = false;
#declare rseed = seed(39275360);


camera {
  location 0
  direction <0, 0, 1> //
  up < 0, 1, 0 >
  #if (ntsc = true)
    right <(640 / 400) * (10/11), 0, 0 >
  #else
    right <(640/480), 0, 0>
  #end
  rotate x*20  // positive to tilt down
  rotate y*30  // positive to turn to the right
  translate <8.05, 10, -3.0>
}


#macro rnd_rotate()
  rotate <360 * rand(rseed), 360 * rand(rseed), 360 * rand(rseed)>
#end


#macro perturb()
  translate <4 - 8 * rand(rseed), 4 - 8 * rand(rseed), 4 - 8 * rand(rseed)>
  rnd_rotate()
#end


sky_sphere { // stars
  pigment {
    bozo
    turbulence 2.21
    perturb()
    color_map {
      [ 0.0 color red 0 green 0 blue 0 ]
      [ 1/2 color red 0 green 0 blue 0 ]
      [ 3/4 color rgb <0, 0.1, 1> * 0.25 ]
      [ 1.0 color rgb <0.5, 0, 1> * 0.5 ]
    }
  }
  pigment {
    granite
    scale 1/100
    color_map {
      [ 0.0 color rgbt <1, 1, 1, 1> ]
      [ 0.75 color rgbt <1, 1, 1, 1> ]
      [ 0.75 color rgb 1 ]
      [ 1.0 color rgb 1 ]
    }
  }
}


#macro do_box(c1, c2) // same parameter format as for a box object
  // back wall
  triangle { c1, <c2.x, c1.y, c1.z>, <c2.x, c2.y, c1.z> }
  triangle { c1, <c2.x, c2.y, c1.z>, <c1.x, c2.y, c1.z> }
  // left wall
  triangle { c1, <c1.x, c1.y, c2.z>, <c1.x, c2.y, c2.z> }
  triangle { c1, <c1.x, c2.y, c2.z>, <c1.x, c2.y, c1.z> }
  // right wall
  triangle { <c2.x, c1.y, c2.z>, <c2.x, c1.y, c1.z>, c2 }
  triangle { <c2.x, c1.y, c1.z>, c2, <c2.x, c2.y, c1.z> }
  // bottom
  triangle { <c1.x, c2.y, c2.z>, <c1.x, c2.y, c1.z>, <c2.x, c2.y, c1.z> }
  triangle { <c1.x, c2.y, c2.z>, <c2.x, c2.y, c1.z>, c2 }
  // top
  triangle { <c1.x, c1.y, c2.z>, c1, <c2.x, c1.y, c1.z> }
  triangle { <c1.x, c1.y, c2.z>, <c2.x, c1.y, c1.z>, <c2.x, c1.y, c2.z> }
  // front
  triangle { <c1.x, c1.y, c2.z>, <c2.x, c1.y, c2.z>, c2 }
  triangle { <c1.x, c1.y, c2.z>, c2, <c1.x, c2.y, c2.z> }
#end


#macro do_quad(c1, c2, c3, c4) // clockwise or counterclockwise order, not
col-row order
  triangle { c1, c2, c3 }
  triangle { c1, c3, c4 }
#end


#macro do_poly(numpts, pts)  // pts is an array of points in clockwise or
counterclockwise
// order.  Also: the polygon had better be convex (as in Opticks)
// it can nadle noncoplaner although the results might be a bit wrinkly
  #local cc = 1;
  #while (cc < (numpts - 1))
    triangle {
      pts[0],
      pts[cc],
      pts[mod(cc + 1, numpts)]
    }
    #local cc = cc + 1;
  #end
#end


#macro rotate_vector_y(invect, roty)
  #local rady = radians(roty);
  <
   cos(rady) * invect.x - sin(rady) * invect.z,
   invect.y,
   sin(rady) * invect.x + cos(rady) * invect.z
  >
#end


#macro rotate_vector_x(invect, rotx)
  #local radx = radians(rotx);
  <
   invect.x,
   cos(radx) * invect.y - sin(radx) * invect.z,
   sin(radx) * invect.y + cos(radx) * invect.z
  >
#end


#macro rotate_vector_z(invect, rotz)
  #local radz = radians(rotz);
  <
   cos(radz) * invect.x - sin(radz) * invect.y,
   sin(radz) * invect.x + cos(radz) * invect.y,
   invect.z
  >
#end


// the do_cylinder_x macro fakes a cyilnder using many triangles.
// Normally, this is a silly thing to do in povray as povray
// will make mathematically perfect cylinders.  The only sane
// reason for making a cylinder out of triangles is for inclusion
// into a larger mesh object that will be repeated *many* times.
// A mesh saves memory when repeated *many* times.
#macro do_cylinder_x( x1, x2, yy, zz, c_radius, num_pts)
  #local pts1 = array[num_pts]
  #local pts2 = array[num_pts]
  #local rotx = 0;
  #while (rotx < num_pts)
    #local pts1[rotx] = <
      0,
      c_radius * cos(radians(rotx * (360 / num_pts))),
      c_radius * sin(radians(rotx * (360 / num_pts)))
    >;
    #local pts2[rotx] = pts1[rotx];
    #local pts1[rotx] = pts1[rotx] + <x1, yy, zz>; // translate
    #local pts2[rotx] = pts2[rotx] + <x2, yy, zz>; // translate
    #local rotx = rotx + 1;
  #end
  do_poly(num_pts, pts1)
  do_poly(num_pts, pts2)
  // Ok. endcaps are done.  Now for tubular part
  #local rotx = 0;
  #while (rotx < num_pts)
    do_quad(
      pts1[rotx],
      pts2[rotx],
      pts2[mod(rotx + 1, num_pts)],
      pts1[mod(rotx + 1, num_pts)]
    )
    #local rotx = rotx + 1;
  #end
#end


#macro do_cylinder_y( y1, y2, xx, zz, c_radius, num_pts)
  #local pts1 = array[num_pts]
  #local pts2 = array[num_pts]
  #local roty = 0;
  #while (roty < num_pts)
    #local pts1[roty] = <
      c_radius * cos(radians(roty * (360 / num_pts))),
      0,
      c_radius * sin(radians(roty * (360 / num_pts)))
    >;
    #local pts2[roty] = pts1[roty];
    #local pts1[roty] = pts1[roty] + <xx, y1, zz>; // translate
    #local pts2[roty] = pts2[roty] + <xx, y2, zz>; // translate
    #local roty = roty + 1;
  #end
  do_poly(num_pts, pts1)
  do_poly(num_pts, pts2)
  // Ok. endcaps are done.  Now for tubular part
  #local roty = 0;
  #while (roty < num_pts)
    do_quad(
      pts1[roty],
      pts2[roty],
      pts2[mod(roty + 1, num_pts)],
      pts1[mod(roty + 1, num_pts)]
    )
    #local roty = roty + 1;
  #end
#end


#macro do_cylinder_z( z1, z2, xx, yy, c_radius, num_pts)
  #local pts1 = array[num_pts]
  #local pts2 = array[num_pts]
  #local rotz = 0;
  #while (rotz < num_pts)
    #local pts1[rotz] = <
      c_radius * cos(radians(rotz * (360 / num_pts))),
      c_radius * sin(radians(rotz * (360 / num_pts))),
      0
    >;
    #local pts2[rotz] = pts1[rotz];
    #local pts1[rotz] = pts1[rotz] + <xx, yy, z1>; // translate
    #local pts2[rotz] = pts2[rotz] + <xx, yy, z2>; // translate
    #local rotz = rotz + 1;
  #end
  do_poly(num_pts, pts1)
  do_poly(num_pts, pts2)
  // Ok. endcaps are done.  Now for tubular part
  #local rotz = 0;
  #while (rotz < num_pts)
    do_quad(
      pts1[rotz],
      pts2[rotz],
      pts2[mod(rotz + 1, num_pts)],
      pts1[mod(rotz + 1, num_pts)]
    )
    #local rotz = rotz + 1;
  #end
#end


#declare t1 = mesh {
  #declare xx = -5;
  #while (xx < 5)
    do_box(<-5, 1, xx>, <5, 0.9, xx + 0.1> ) // ceiling crosspeice
    do_box(<xx, 1, -5>, <xx + 0.1, 0.9, 5> ) // ceilign crosspeice
    #declare zz = -5;
    #while (zz < 5)
      do_box(<xx, 0, zz>, <xx + 0.1, 0.91, zz + 0.1> ) // upright beam
      #declare zz = zz + 1;
    #end
    #declare xx = xx + 1;
  #end
}


#declare t2 = mesh {
  #declare xx = -5;
  #while (xx < 5)
    do_box(<-5, 1, xx>, <5, 0.9, xx + 0.1> ) // ceiling crosspeice
    do_box(<xx, 1, -5>, <xx + 0.1, 0.9, 5> ) // ceilign crosspeice
    do_box(<-5, 2, xx>, <5, 1.9, xx + 0.1> ) // ceiling crosspeice
    do_box(<xx, 2, -5>, <xx + 0.1, 1.9, 5> ) // ceilign crosspeice
    #declare zz = -5;
    #while (zz < 5)
      do_box(<xx, 0, zz>, <xx + 0.1, 1.91, zz + 0.1> ) // upright beam
      #declare zz = zz + 1;
    #end
    #declare xx = xx + 1;
  #end
}


#declare t4 = mesh {
  #declare xx = -5;
  #while (xx < 5)
    #declare yy = 0;
    #while (yy < 4)
      do_box(<-5, yy + 1, xx>, <5, yy + 0.9, xx + 0.1> ) // ceiling crosspeice
      do_box(<xx, yy + 1, -5>, <xx + 0.1, yy + 0.9, 5> ) // ceiling crosspeice
      #declare yy = yy + 1;
    #end
    #declare zz = -5;
    #while (zz < 5)
      do_box(<xx, 0, zz>, <xx + 0.1, 3.91, zz + 0.1> ) // upright beam
      #declare zz = zz + 1;
    #end
    #declare xx = xx + 1;
  #end
}


#declare t8 = mesh {
  #declare xx = -5;
  #while (xx < 5)
    #declare yy = 0;
    #while (yy < 8)
      do_box(<-5, yy + 1, xx>, <5, yy + 0.9, xx + 0.1> ) // ceiling crosspeice
      do_box(<xx, yy + 1, -5>, <xx + 0.1, yy + 0.9, 5> ) // ceiling crosspeice
      #declare yy = yy + 1;
    #end
    #declare zz = -5;
    #while (zz < 5)
      do_box(<xx, 0, zz>, <xx + 0.1, 7.91, zz + 0.1> ) // upright beam
      #declare zz = zz + 1;
    #end
    #declare xx = xx + 1;
  #end
}


# render "\ndone building meshes, now placing them\n"
#declare zz = 0;
#while (zz < 65)
  #declare xx = 0;
  #while (xx < 65)
    object {
      #declare wo = int(4 * rand(rseed));
      #switch (wo)
        #case (0)
          t1
          #break
        #case (1)
          t2
          #break
        #case (2)
          t4
          #break
        #else
          t8
      #end
      pigment { rgb <0.9, 0.4, 0.2> }
      finish { ambient 0.4 diffuse 0.6 }
      translate <xx * 10, 0, zz * 10>
    }
    #declare xx = xx + 1;
  #end
  #declare zz = zz + 1;
#end


plane { // ground
  <0, 1, 0>, 0
  pigment { color rgb 0.8 }
  finish { ambient 0.5 diffuse 0.5 }
}


light_source {
  <3000, 3000, -3000>
  color rgb 0.5
}
light_source {
  <-2000, 2900, -2200>
  color rgb 0.5
}


/* actual end of this file */


Post a reply to this message

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