// Parameters #declare Taille = <20,20,20>; // size of the pipe network #declare Nombre = 2; //number of pipes #declare Proba = 0.7; //probabilitof going straight #declare Essais = 6; //number of tries before stopping the pipe #declare RN= seed(22); #declare rad=true; global_settings { max_trace_level 15 #if (rad=true) ambient_light color rgb <1,1,1> radiosity { pretrace_start 0.08 pretrace_end 0.04 count 35 nearest_count 5 error_bound 1.8 recursion_limit 3 low_error_factor 0.5 gray_threshold 0.0 minimum_reuse 0.015 brightness 1 adc_bailout 0.01/2 normal on } #end } /* directions are coded as follow : 0 : -x => +x 1 : +X => -x 2 : -y => +y 3 : +y => -y 4 : -z => +z 5 : +z => -Z the transposition table gives the shape of the object when we come from a direction and we go to another */ // Constantes et déclaration #declare Transposition = array[6][6] {0,0,4,3,6,5}, // for example : Transposition [0][3] = 4 : 4 is the shape -X => +y {0,0,8,7,10,9}, {7,3,1,1,12,11}, {8,4,1,1,14,13}, {9,6,13,11,2,2}, {10,6,14,12,2,2} } #declare Table = array[Taille.x][Taille.y][Taille.z] // table contains the definition of the pipes #declare xx=0; // here we fill the table with 99 (no pipe) #while (xx=Taille.x) #declare result = false; #end #if (yy>=Taille.y) #declare result = false; #end #if (zz>=Taille.z) #declare result = false; #end #if (result = true)// we are in the table #if (Table[xx][yy][zz]<99) #declare result = false; #end #end result #end #macro Nouveaupoint (coord, dir) // give the coordinates of the new point #local xx=coord.x; // coord is the old point and dir the direction (from 0 to 5) #local yy=coord.y; #local zz=coord.z; #switch (dir) #case (0) #local xx=xx+1; #break #case (1) #local xx=xx-1; #break #case (2) #local yy=yy+1; #break #case (3) #local yy=yy-1; #break #case (4) #local zz=zz+1; #break #case (5) #local zz=zz-1; #break #else #end //return the value #end #macro Randint (A) //give an integer lesser than A int(rand(RN)*A) #end // Generation #declare Tuyau = 0; #while (Tuyau < Nombre) //creating a pipe //starting point #declare essai=0; // if we don't find a starting point in less than 100 tries we resign #declare okay=false; #while ((essai<100) * (okay=false)) #declare Dir = Randint(6); #switch (Dir) //we chose the side we start. Now let's choose the coords... #case(0) #declare Loc= <0,Randint(Taille.y),Randint(Taille.z)>; #break #case(1) #declare Loc= ; #break #case(2) #declare Loc = ; #break #case(3) #declare Loc = ; #break #case(4) #declare Loc = ; #break #case(5) #declare Loc = ; #break #else #end #declare essai=essai+1; #if ((Libre(Loc) = true) * (Libre(Nouveaupoint(Loc,Dir)) = true)) //trouvé un point valable #declare okay = true; #declare Table[Loc.x][Loc.y][Loc.z]=int(Dir/2); //0->5 => 0->2 #end #end #if (okay = true)// now we construct the pipe #while (okay = true) // while we are not stuck #if ((Libre(Nouveaupoint(Loc,Dir)) = true) * (rand(RN) // if you change the size of the pipes, change it ! look_at <11,9,9>} light_source {<14.9,15,-30> color rgb <0.6,0.6,0.3>} light_source{<15.1,15,-30> color rgb <0.3,0.3,0.6>} //textures #declare M_tuyau=material { // these texture are test textures and MUST be greatly improved texture { pigment {rgb <0.9,0.9,0.9>} finish { metallic reflection {0.2,0.4 fresnel} //conserve_energy //phong 0.2 } normal {bumps 0.1 scale 0.05} } interior {ior 1.2} } #declare M_tuyau2=material { texture { pigment {rgb <0.7,0.73,0.65>} finish { metallic reflection {0.2,0.4 fresnel} //conserve_energy //phong 0.2 } normal {bumps 0.1 scale 0.05} } interior {ior 1.2} } // objets #declare Tube = cylinder { //pipe section on x axis <-0.51,0,0>,<0.51,0,0>,0.25 material {M_tuyau} } #declare Coude = merge { // turning -X,-Y cylinder {<-0.51,0,0>,<-0.29,0,0>,0.25} cylinder {<0,-0.29,0>,<0,-0.51,0>,0.25} intersection { torus{ 0.3,0.25 rotate 90*x} box{<0,0,-0.8>,<0.6,0.6,0.8>} translate <-0.3,-0.3,0> } material {M_tuyau} } # declare Ecrou = prism { //"boulon" (don't know the english word. Sorry) linear_spline 0,1,7 <0,1>,<0.866,0.5>,<0.866,-0.5>,<0,-1>,<-0.866,-0.5>,<-0.866,0.5>,<0,1> } #declare Joint = union { // this is the fixation between two pipes sections cylinder {<-0.1,0,0>,<-0.01,0,0>,0.48} cylinder {<0.01,0,0>,<0.1,0,0>,0.48} #declare a=0; #while (a<6) object {Ecrou rotate -90*z scale 0.07 translate <0.06,0.3,0> rotate 60*a*x} object {Ecrou rotate -90*z scale 0.07 translate <-0.16,0.3,0> rotate 60*a*x} union { cylinder {<-0.165,0.3,0>,<0.165,0.3,0>,0.03} sphere {<-0.165,0.3,0>,0.03} sphere {<0.165,0.3,0>,0.03} rotate 60*a*x material {M_tuyau} } #declare a=a+1; #end material {M_tuyau2} } #macro Objet(N) //this macro generates a pipe section. N is the result of the transposition table #switch (N) #case(0) // X union{ object{Tube} #switch (Randint(10) ) #case (0) // from time to time we add junctions object{Joint} #break // here lots of decorative sections should be added #else #end } #break #case(1) // y union{ object{Tube} #switch (Randint(10) ) #case (0) object{Joint} #break #else #end rotate 90*z } #break #case(2) // z union{ object{Tube} #switch (Randint(10) ) #case (0) object{Joint} #break #else #end rotate 90*y } #break #case(3) //-X=>-y object{Coude} #break #case(4) //-X=>y object{Coude scale <1,-1,1>} #break #case(5) //-X=>-Z object{Coude matrix <1,0,0,0,0,1,0,1,0,0,0,0> } #break #case(6) //-X=>Z object{Coude matrix <1,0,0,0,0,-1,0,-1,0,0,0,0> } #break #case(7) //X=>-Y object {Coude scale <-1,1,1>} #break #case(8) //X=>Y object {Coude scale -1} #break #case(9) //X=>-Z object {Coude matrix <-1,0,0,0,0,1,0,1,0,0,0,0> } #break #case(10) //X=>Z object {Coude matrix <-1,0,0,0,0,-1,0,-1,0,0,0,0>} #break #case(11) //-Y=>-Z object {Coude matrix <0,0,1,0,1,0,1,0,0,0,0,0>} #break #case(12) //-Y=>Z object {Coude matrix <0,0,-1,0,1,0,-1,0,0,0,0,0>} #break #case(13) //y=>-Z object {Coude matrix <0,0,1,0,-1,0,1,0,0,0,0,0>} #break #case(14) //y=>z object {Coude matrix <0,0,-1,0,-1,0,-1,0,0,0,0,0>} #break #end #end //drawing #declare xx=0; // we check each case in the table #while (xx #if (Table[xx][yy][zz]<99) object {Objet(Table[xx][yy][zz]) translate } #end #declare zz=zz+1; #end #declare yy=yy+1; #end #declare xx=xx+1; #end // other objects. For now, only a plane. plane{y,0 pigment { checker color rgb <1,0,0>, color rgb <0,1,0> scale 3 } }