POV-Ray : Newsgroups : povray.newusers : Very slow rendering of an object with many holes : Re: Very slow rendering of an object with many holes Server Time
28 Jul 2024 12:30:02 EDT (-0400)
  Re: Very slow rendering of an object with many holes  
From: Chris B
Date: 23 May 2009 10:01:51
Message: <4a1801cf@news.povray.org>
"Tomohiro" <nomail@nomail> wrote in message 
news:web.4a172aa8dc3f4a9c20aaa4ac0@news.povray.org...
> "stevenvh" <nomail@nomail> wrote:
>> I think the following link provide an answer:
>> http://www.econym.demon.co.uk/holetut/index.htm
>
> Thank you for your helps.
>
> My object has regular arrangement of cylindrical holes, but
> I cannot guess a function because:
>
> - holes are arranged in hexagonal way
> - no "half" holes at edge of the object
> - (if possible) a small part of edge of holes should be cut in 45 degree
>
> On the other hand, usage of blob worked almost well, but
> it cannot satisfy the third requirement written above.
>

The following example took a little longer than I'd anticipated to write, 
mainly because I'd not read your first posting carefully enough and didn't 
initially realise you wanted a cylindrical object. Anyway, the approach I 
took was basically the same and could be made to work with a variety of 
shapes:  I've declared a 'blank' box without a hole and a 'holed' box of the 
same size so that they can be slotted together in the same sort of way that 
Mike's tutorial shows, but each of the boxes is just big enough to take one 
hole.

The nested #while loops lay the boxes out in a grid, with a few conditional 
statements to determine what to place where (based on the calculated centre 
point for that box). The first condition is that, if it's well outside the 
circle it doesn't bother placing an object there at all. The second says 
that, if it overlaps the edge, trim it using a CSG intersection with a 
cylinder. If the centre would make the hole touch the edge it uses the 
'blank' object, otherwise it uses the 'holed' object.

I hope I've correctly interpreted what you meant when said you wanted the 
holes laid out in an 'hexagonal way'. I've interpreted this as a 50% offset 
in successive rows, giving a hexagonal/triangular pattern (ie with prominent 
diagonal lines of holes), but it should be fairly easy to replace every 
third hole on each line with a 'blank' giving a pure hexagonal pattern.

This example rendered 1618 holes in 2 seconds on my machine.

camera {location  <-1, 2,-4> look_at 0}
light_source {< 70, 200, -80> color rgb 0.8}

#declare XHoles = 50;
#declare XSep = 0.1;
#declare ZSep = 0.5*XSep*sqrt(3);
#declare ZHoles = int(XHoles*XSep/ZSep);
#declare Radius = (XHoles*ZSep)/2;

#declare BlankObject = box {<-XSep/2,-0.1,-ZSep/2><XSep/2,0,ZSep/2> }

#declare HoledObject = difference {
  object {BlankObject}
  cylinder {<0,-0.05,0><0,0.05,0>,0.02}
  cone {<0,-0.05,0>,0,<0,0.05,0>,XSep/2}
}

#declare HoleCount = 0;
union {
  #declare I =-(XHoles-1)/2;
  #while (I<(XHoles/2))
    #declare J = -(ZHoles-1)/2;
    #while (J<(ZHoles/2))
      #local ThisCentre = <XSep*(I+mod(J,2)/2),0,J*ZSep>;
      // If it's part of the object
      #if (vlength(ThisCentre)<(Radius+XSep/sqrt(2)))
        // If it's part of the edge
        #if (vlength(ThisCentre)>(Radius-XSep/sqrt(2)))
          intersection {
            #if (vlength(ThisCentre)<(Radius-0.05))
              object {HoledObject translate ThisCentre}
              #declare HoleCount = HoleCount + 1;
            #else
              object {BlankObject translate ThisCentre}
            #end
            cylinder {<0,-0.11,0><0,0.1,0>,Radius}
          }
        // If it's clear of the edge
        #else
          object {HoledObject translate ThisCentre}
          #declare HoleCount = HoleCount + 1;
        #end
      #end
      #declare J = J + 1;
    #end
    #declare I = I + 1;
  #end
  pigment {rgb 1}
}

cylinder {<0,-0.5,0><0,-0.12,0>,Radius pigment {rgb <1,1,0>}}
#debug concat(str(HoleCount,3,0)," Holes.\n")

Regards,
Chris B.


Post a reply to this message

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