POV-Ray : Newsgroups : povray.newusers : Onion : Re: Onion Server Time
28 Jul 2024 14:27:31 EDT (-0400)
  Re: Onion  
From: Chris B
Date: 15 Feb 2009 10:52:40
Message: <49983a48$1@news.povray.org>
"Matija" <nomail@nomail> wrote in message 
news:web.49980144c811732de30e02620@news.povray.org...
> Hi!
>
> I've been tryin to make somethign resembling an onion an cutting it away. 
> Not
> that I want it to look as an onion, just a bunch of concentric spheres. I
> wanted to use the #while loop so that I wouldn't need to type much and 
> could
> change stuff easily. But only the first iteration seems to run OK, then it 
> gets
> weird. Could you please llok at my code, run it and help? Thanks!
>
> Matija
>
>
>  #include "colors.inc"
>  #include "glass.inc"
>  #include "skies.inc"
>  #include "textures.inc"
>    background{White}
>
>    camera {
>    angle 15
>    location <3,12,10>
>    look_at <0,0,0>
>    }
>    light_source { <12, 5, 3> color White }
>
> #declare Stevec=1;
> #declare Rad1 = 1;
> #declare Rad2 = 0.1;
>
> #declare Onion =
>
>        #while (Stevec >= 0.2)
>                #declare Rad1=Stevec;
>                #declare Rad2=Rad1-0.1;
>                difference {
>                        sphere {<0,0,0>, Rad1}
>                        sphere {<0,0,0>, Rad2 hollow} cutaway_textures}
>                #declare Stevec=Stevec-0.2;
>
>        #end
>
> intersection {
>         object {Onion pigment {color Green}}
>        box {<0,-1,-1>
>                <-1,1,1>
>                pigment {color Blue}}
>                }
>

Hi,

There are quite a few things wrong with this. Some are coding errors, but I 
think you also run into a problem that arises when using cutaway_textures on 
more complex CSG objects.

Firstly, your Onion declaration is started, the loop is started and, on the 
first iteration, the difference between the two spheres is assigned to 
'Onion'. This ends the Onion definition, but the loop continues. All 
subsequent iterations add a new difference directly into the scene and these 
objects are never intersected with the box, so you only see the outer 
surface of the outermost sphere. No pigment is assigned to this sphere, so 
it looks black. To fix this you can declare the Onion as a union of 
everything generated by the while loop (see below).

The cutaway_textures keyword on the differenced spheres has no effect as the 
object has no texture defined by that time.
The cutaway_textures keyword can be added to the intersection, but it 
doesn't seem to work well with complex CSG objects, which I think is a known 
problem.

The following example uses an onion pigment and a color_map to texture the 
whole object, which aviods this problem for the particular shape you have, 
but which probably won't work well with other shapes.

Another alternative would be to declare the box first. Then loop through and 
do the intersection of that box with each sphere inside the loop in turn, 
before applying a unique color to each shell.

Regards,
Chris B.

#declare Stevec=1;
#declare Rad1 = 1;
#declare Rad2 = 0.1;

#declare Onion = union {
  #while (Stevec >= 0.2)
    #declare Rad1=Stevec;
    #declare Rad2=Rad1-0.1;
    difference {
      sphere {<0,0,0>, Rad1}
      sphere {<0,0,0>, Rad2}
    }
    #declare Stevec=Stevec-0.2;
  #end
}

difference {
  object {Onion }
  box {<0,-1,-1>,<1,1,1>}
  pigment {onion
    color_map {
      [0.00 0.05 color White  color White ]
      [0.05 0.25 color Red    color Red   ]
      [0.25 0.45 color Yellow color Yellow]
      [0.45 0.65 color Green  color Green ]
      [0.65 0.85 color Blue   color Blue  ]
      [0.85 1.10 color White  color White ]
    }
  }
}


Post a reply to this message

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