#macro CAT (OBJ,Subd,Surfacells,Status,File_name,Cell_Shape,Cell_Scale) #if (Status=0) #local Orig_OBJ = object {OBJ}; #local OBJ = object {OBJ Align_Trans(OBJ,-x-z-y,0)}; // el objeto se alinea -que no se centra- a los planos xyz #local Min_T = min_extent (OBJ) ; #local Max_T = max_extent (OBJ) ; #local Original_location=min_extent (Orig_OBJ) ; // Altura de las hileras en vertical = altura del objeto / n-subdivisiones #local Row = Max_T.y/Subd ; // opening file and adding a title and row's height // abrimos fichero y añadimos un titulo, la altura de las filas para no tener que reajustar al cargar otro fichero o modificar el numero de filas #fopen SetRow concat(File_name) append #write (SetRow,"// Include DataFile from The CAT() Macro by B. Gimeno for\n// The Persistence Of Vision Ray-Tracer v.3.6\n", "// This object is ",Subd," cells of height, "Max_T.x/Row," of width and ",Max_T.z/Row," cells of depth\n\n", "#local Row = "Max_T.y/Subd" ;\n\n" ) #fclose SetRow #end // ------------------------------------- // esta macro intersecta el objeto con una delgada caja situada a la altura de cada corte // es una macro interna, no para su uso fuera de CAT() #macro Scanner(OBJ,Num_Corte,Num_Cortes) intersection { object {OBJ} box {, translate y*Row/2 translate y*Row*Num_Corte } } #end // ------------------------------------- #local Result = #if (Status=0) union { #local Subd_r=0 ; #while (Subd_r ; #local To = ; trace (Tac_obj,From,To) #end // ------------------------------------------------- #if (Surfacells=on) // ==================================================== #switch (Subd_r) #case (0) // sólo si se procesan las celdas del primer nivel #if (vlength(Adj_C(0,0,0))!=0) #local Write_Cell = yes ; #else #local Write_Cell = no ; #end #break #range (1,Subd-2) // procesando todas las celdas alrededor #if ( (X_Cells_r!=0) & (Z_Cells_r!=0) & (vlength(Adj_C(-1, 0, 0))!=0) & (vlength(Adj_C( 1, 0, 0))!=0) & (vlength(Adj_C( 0,-1, 0))!=0) & (vlength(Adj_C( 0, 1, 0))!=0) & (vlength(Adj_C( 0, 0,-1))!=0) & (vlength(Adj_C( 0, 0, 1))!=0) & (vlength(Adj_C(-1, 0,-1))!=0) & (vlength(Adj_C( 1, 0,-1))!=0) & (vlength(Adj_C(-1, 0, 1))!=0) & (vlength(Adj_C( 1, 0, 1))!=0) ) #if (vlength(Adj_C(0,0,0))!=0) #local Write_Cell = no ; #else #local Write_Cell = yes ; #end #else #if (vlength(Adj_C(0,0,0))!=0) #local Write_Cell = yes ; #else #local Write_Cell = no ; #end #end #break #case (Subd-1) // sólo para procesar las celdas del último nivel #if (vlength(Adj_C(0,0,0))!=0) #local Write_Cell = yes ; #else #local Write_Cell = no ; #end #break #end #else // ==================================================== #if (vlength(Adj_C(0,0,0))!=0) #local Write_Cell = yes ; #else #local Write_Cell = no ; #end #end // ------------------------------------------------- #if (Write_Cell = yes) #fopen PARSER concat(File_name) append // abrimos fichero y añadimos cada resultado en él #write (PARSER,"C(S,"Adj_C(0,0,0)+Original_location")\n") #fclose PARSER #end // fin del #if condicional para generar celdas // ------------------------------------------------- #local Z_Cells_r=Z_Cells_r+(Row*.5) ; #end // end bucle Z_Cells #local X_Cells_r=X_Cells_r+(Row*.5) ; #end // end bucle X_Cells #debug concat ("\nWriting floor: ",str(Subd_r+1,1,0)," of ",str(Subd,1,0)) #local Subd_r=Subd_r+1 ; #end // end bucle Y_Cells (Subdv) // #debug concat( "\n Max_T: <",vstr(3,Max_T,",",0,3),"> \n X_Cells:",str(X_Cells,2,0)," Z_Cells:",str(Z_Cells,2,0) ) } // ------------------------------------------------------------------------------------------------------------- #else // status = 1, pasamos a tomar los datos del fichero generado y a generar el objeto // ----una pequeña macro para elegir entre distintos tipos de celulas, cuadrados, esferas, Wire_Box, etc-------- #macro C(Sh,Loc) // Cell (Shape) #if (Sh!=13) object { #end // conditional blob code #switch (Sh) #case (0) sphere {0,(Row/2)*Cell_Scale } #break #case (1) box {-(Row/2),(Row/2) scale Cell_Scale} #break #case (2) Round_Box (-*Cell_Scale,*Cell_Scale,(Row/10)*Cell_Scale,no) #break #case (3) #local p1 = <-Row/2,-Row/2,-Row/2> ; #local p2 = <-Row/2,-Row/2, Row/2> ; #local p3 = < Row/2,-Row/2,-Row/2> ; #local p4 = < Row/2,-Row/2, Row/2> ; #local p5 = <-Row/2, Row/2,-Row/2> ; #local p6 = <-Row/2, Row/2, Row/2> ; #local p7 = < Row/2, Row/2,-Row/2> ; #local p8 = < Row/2, Row/2, Row/2> ; union { sphere {p1,Row/10} sphere {p2,Row/10} sphere {p3,Row/10} sphere {p4,Row/10} sphere {p5,Row/10} sphere {p6,Row/10} sphere {p7,Row/10} sphere {p8,Row/10} cylinder {p1, p2, Row/10} cylinder {p2, p4, Row/10} cylinder {p4, p3, Row/10} cylinder {p3, p1, Row/10} cylinder {p5, p6, Row/10} cylinder {p6, p8, Row/10} cylinder {p8, p7, Row/10} cylinder {p7, p5, Row/10} cylinder {p1, p5, Row/10} cylinder {p2, p6, Row/10} cylinder {p3, p7, Row/10} cylinder {p4, p8, Row/10} scale Cell_Scale } #break #case (4) object {C(3,0) rotate 1440*rand(rnd) } #break #case (5) cylinder {-<(Row/2),0,0>,<(Row/2),0,0>,(Row/2) scale Cell_Scale} #break #case (6) cylinder {-<0,(Row/2),0>,<0,(Row/2),0>,(Row/2) scale Cell_Scale} #break #case (7) cylinder {-<0,0,(Row/2)>,<0,0,(Row/2)>,(Row/2) scale Cell_Scale} #break #case (8) union { C(5,0) C(6,0) C(7,0) } #break #case (9) #switch (rand(rnd)) #local N_shapes = 2 ; #local Accuracy = 1/100000; #range (0,1/N_shapes) C(0,0) #break #range ((1/N_shapes)+Accuracy,(2/N_shapes)) C(2,0) #break #else C(0,0) #end #break #case (10) #switch (rand(rnd)) #local N_shapes = 3 ; #local Accuracy = 1/100000; #range (0,1/N_shapes) C(5,0) #break #range ((1/N_shapes)+Accuracy,(2/N_shapes)) C(6,0) #break #range ((2/N_shapes)+Accuracy,(3/N_shapes)) C(7,0) #break #else C(0,0) #end #break #case (11) #switch (rand(rnd)) #local N_shapes = 5 ; #local Accuracy = 1/10000000; #range (0,1/N_shapes) C(0,0) #break #range ((1/N_shapes)+Accuracy,(2/N_shapes)) C(2,0) #break #range ((2/N_shapes)+Accuracy,(3/N_shapes)) C(5,0) #break #range ((3/N_shapes)+Accuracy,(4/N_shapes)) C(6,0) #break #range ((4/N_shapes)+Accuracy,(5/N_shapes)) C(7,0) #break #else C(0,0) #end #break #case (12) #local n_letters = 26 ; #local alphabet = array [n_letters]{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"} // #local n_letters = 4 ; // #local alphabet = array [n_letters]{"P","O","V","R","A","Y"} #local L = text { ttf "arial.ttf" concat( alphabet[n_letters*rand(rnd)] ) Row*.01,0 // rotate Loc*rand(rnd)*10 // randomized !!!! // rotate y*90 // orient aligned letters scale Row scale Cell_Scale } object {L Center_Trans(L,x+y+z) } #break // ------------------------------------------------------------------------------------------------------------------ // ------------// mantener siempre este #case para el objeto blob---------------------------------------------------- #case (13) sphere { Row*rand(rnd)*.5,.35+(Row*rand(rnd))*Cell_Scale,Row #break // ------------------------------ // ------------// mantener siempre este #case para el objeto blob---------------------------------------------------- // ------------------------------------------------------------------------------------------------------------------ #case (14) sphere { Row*rand(rnd)*.5,.2+(Row*Cell_Scale*rand(rnd2)) } #break #case (15) box {-Row*.75,Row*.75 rotate 720*rand(rnd) scale Cell_Scale} #break #case (16) cylinder {-<0,0,(Row*1.5)>,<0,0,(Row*1.5)>,(Row/4) scale Cell_Scale rotate 1440*rand(rnd) } #break #case (17) difference { box {-Row/2, Row/2} cylinder {<-Row,0,0>,,Row*.35} cylinder {<0,-Row,0>,<0,Row,0>,Row*.35} cylinder {<0,0,-Row>,<0,0,Row>,Row*.35} scale Cell_Scale rotate -1000*rand(rnd) } #break #case (18) torus {(Row*.5)+Row*rand(rnd),Row/10 rotate 1440*rand(rnd) scale Cell_Scale} #break #case (19) union { object {torus {Row/2,Row/6}} object {torus {Row/2,Row/6} rotate z*90} object {torus {Row/2,Row/6} rotate x*90} scale Cell_Scale translate *.5 rotate 1020*rand(rnd) } #break #else object { C(0,0) } #end // fin del #switch para el tipo de objeto (shaping) // pigment {rgb <0.5,.75,1>*(rand(rnd))} translate Loc } #end // end macro shaping // --------------------------------- union { #if (Cell_Shape=13) blob{ threshold 0.6 #end // codigo condicional para blob #local S = Cell_Shape ; #local rnd = seed(1644989); #local rnd2 = seed(987216); #include concat(File_name) #if (Cell_Shape=13) } #end // codigo condicional para blob } #end // fin de status // ----- PRESENTACION DEL OBJETO ------------------------------------------------------ object {Result} #end // final de macro // ------------------------------------------------------------------------------------ #macro CAT_Save (OBJ,Subd,Surfacells,File_name) CAT(OBJ,Subd,Surfacells,0,File_name,0,0) #end // ------------------------------------------------------------------------------------ #macro CAT_Load (File_name,Cell_Shape,Cell_scale) CAT(0,2,off,1,File_name,Cell_Shape,Cell_scale) #end // ------------------------------------------------------------------------------------