POV-Ray : Newsgroups : povray.text.scene-files : Corroded Torus - scene Server Time
22 Dec 2024 04:14:03 EST (-0500)
  Corroded Torus - scene (Message 1 to 1 of 1)  
From: Trevor G Quayle
Subject: Corroded Torus - scene
Date: 16 Nov 2006 16:30:00
Message: <web.455cd75c892c95b8c150d4c10@news.povray.org>
From p.b.i, scene file demonstrating my corroded torus.  Feel free to modify
and use as you see fit.

-tgq


//START

// Persistence of Vision Ray Tracer Scene Description File
// File: CorTor.pov
// Desc: Corroded torus
// Date: 16/11/06
// Auth: Trevor G Quayle

//#version unofficial megapov 1.1;

global_settings {
  assumed_gamma 1.0
  ambient_light 1
  adc_bailout 0.001
  max_trace_level 10
}

camera {
  right x*image_width/image_height
  location  <0,3,-3>*20
  look_at   <0,0,0>
}

#declare LB=
sphere{0 10 hollow no_image
  photons {collect off pass_through}
  texture{pigment{rgb 1} finish{ambient 25}}
}

light_source {
  <5, 5, -5>*10
  color rgb <1,1,1>
  looks_like{LB}
}


light_source {
  <-5, 1, -5>*10
  color rgb <1,1,1>
  looks_like{LB}
}

light_source {
  <0,50,0>
  color rgb <1,1,1>
  looks_like{LB}
}


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

plane {
  -y, 0.0 hollow
  pigment {rgb 1}
  finish {ambient 0 diffuse 0.6}
}


#declare TexOut= //Chrome texture
  texture{
    pigment{rgb 1}
    finish{
      conserve_energy
      diffuse 0.0
      ambient 0
      reflection{0 1 fresnel on metallic 1}
    }
  }


#declare RSteel= //Rust texture
  texture{
    pigment {
      granite
      color_map {
        [0.20 rgb <0.89, 0.51, 0.28>]
        [0.40 rgb <0.70, 0.13, 0.00>]
        [0.60 rgb <0.69, 0.41, 0.08>]
        [0.80 rgb <0.49, 0.31, 0.28>]
        [1.00 rgb <0.89, 0.51, 0.28>]
      }
    }
    finish {ambient 0 diffuse 0.6}
    normal{
      average
      normal_map{
        [1 granite 1]
        [2 granite 1 scale 1/10]
      }
    }
    scale 2
  }

#declare axis1=20; //major radius
#declare axis2=5;  //minor radius

#declare mm=400;   //mesh divisions around major axis
#declare nn=100;   //mesh divisions around minor axis

#declare Cor=0.5;  //Corrosion amount

#declare FF=function{pigment{granite colour_map{[(1-Cor) rgb 0][1.0 rgb 1]}
 scale 15}} //Corrosion function

#declare Thk=0.01;  //Thickness of outer material
#declare Tor1=torus{axis1,axis2-Thk}

#declare TorMat=
material{
  texture{
    object{
      Tor1
      texture{TexOut}
      texture{RSteel}
    }
  }
  interior{ior 25}
}

#declare OS=0.025;

#declare FF2=function(k){abs(pow(k,1)*(1+2*OS)-OS)-OS}  //Creates a raised
ridge around corroded spots based on OS value

#macro Pont (m0,n0) //Calculate deformed vertices
  #local
Norm=vnormalize(vaxis_rotate(vaxis_rotate(y*axis2,x,n0*360/nn),y,m0*360/mm));
  #local
PT=vaxis_rotate(vaxis_rotate(y*axis2,x,n0*360/nn)+z*axis1,y,m0*360/mm);
  PT-FF2(FF(PT.x,PT.y,PT.z).gray)*Norm*Cor*3
#end

#declare PTt=array[3][3];

#declare Torus2=
mesh2 {
  vertex_vectors {
    mm*nn
    #declare m=0; #while (m<mm)
      #declare n=0; #while (n<nn)
        ,Pont(m,n)
      #declare n=n+1;#end
    #declare m=m+1;#end
  }
  normal_vectors {
    mm*nn
    #declare m=0; #while (m<mm)
      #declare n=0; #while (n<nn)
        #declare i=-1;#while (i<2)
          #declare j=-1;#while (j<2)
            #declare PTt[i+1][j+1]=Pont(mod(m+mm+i,mm),mod(n+nn+j,nn));
          #declare j=j+1;#end
        #declare i=i+1;#end
        #declare V1=vnormalize(PTt[2][1]-PTt[1][1]);
        #declare V2=vnormalize(PTt[1][2]-PTt[1][1]);
        #declare V3=vnormalize(PTt[0][1]-PTt[1][1]);
        #declare V4=vnormalize(PTt[1][0]-PTt[1][1]);
        #declare N=  vcross(V1,V2)*(vlength(V1)+vlength(V2));
        #declare N=N+vcross(V2,V3)*(vlength(V2)+vlength(V3));
        #declare N=N+vcross(V3,V4)*(vlength(V3)+vlength(V4));
        #declare N=N+vcross(V4,V1)*(vlength(V4)+vlength(V1));
        #declare
N=vnormalize(N/(2*(vlength(V1)+vlength(V2)+vlength(V3)+vlength(V4))));
        ,N
      #declare n=n+1;#end
    #declare m=m+1;#end
  }
  face_indices {
    mm*nn*2
    #declare m=0; #while (m<mm)
      #declare n=0; #while (n<nn)
        #declare m0=mod(m-1,mm);#declare m1=mod(m+1,mm);
        #declare n0=mod(n-1,nn);#declare n1=mod(n+1,nn);
        #declare F1=<m*nn+n,m*nn+n1,m1*nn+n>;
        #declare F2=<m*nn+n1,m1*nn+n,m1*nn+n1>;
        ,F1,F2

      #declare n=n+1;#end
    #declare m=m+1;#end
  }
  normal_indices {
    mm*nn*2
    #declare m=0; #while (m<mm)
      #declare n=0; #while (n<nn)
        #declare m0=mod(m-1,mm);#declare m1=mod(m+1,mm);
        #declare n0=mod(n-1,nn);#declare n1=mod(n+1,nn);
        #declare F1=<m*nn+n,m*nn+n1,m1*nn+n>;
        #declare F2=<m*nn+n1,m1*nn+n,m1*nn+n1>;
        ,F1,F2
      #declare n=n+1;#end
    #declare m=m+1;#end
  }
  material{TorMat}
}

object{Torus2 translate <0,axis2,0>}


//END


Post a reply to this message

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