// Wood floor building macro // Bill Walker "Bald Eagle" // Original code part of "The Secret Passage" TINA-CheP Challenge // Portions of code adapted from Dan Hentschel, Nicolas Rougier, Thomas deGroot, and Warp // Rewritten April 2018 // Include file Macro version 1.0 // TO DO // selectable unis via array // parameterize border dimensions // Make width and depth same scale // Fix any other bugs I've missed first time around #version version; #ifdef (SDL) // do nothing #else #version 3.7; global_settings {assumed_gamma 1.0} #include "colors.inc" #include "rand.inc" #debug "\nWood Floor include file - standalone mode\n" #end // end ifdef SDL #ifndef (Feet) #declare Feet = 12; #end #ifndef (Meters) #declare Meters = 39.37; #end #declare Units = array [2] {Feet, Meters} #declare UnitName = array [2] {"Feet", "Meters"} #macro BuildWoodFloor (Width, Depth, PlankWidth, Unit, Border, optional Wood1, optional Wood2, optional Wood3) #declare Width2 = Width/2; #declare Start = 0; #declare AddBorder = Border; #debug concat ( " Dimensions: Width (x) ", str (Width, 3, 1), " {", str (-Width2, 3, 1), " to ", str (Width2, 3, 1), "} Depth (z) = ", str (Depth, 3, 1), " Planks = ", str (PlankWidth, 3, 1), UnitName[Unit], " wide \n\n") #if (AddBorder) #debug "\n Including a block border\n" #end //(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o) //(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o) #declare PlankNormal = normal { gradient x 2 slope_map { [0.00 <0, 1>] [0.05 <1, 0>] [0.95 <1, 0>] [1.00 <0,-1>] } scale 2 } // NR = Nicolas Rougier //============= NR_Wood (2003) ============= #declare NR_wood_grain = pigment { wood warp {cylindrical orientation y dist_exp 1} warp {turbulence 1.25} scale <0.5, 30, 1> warp {turbulence 0.25} scale <1, 10, 1> warp { black_hole <0, 0.5, 0>, 1 falloff 2 strength 1.5 repeat 7 turbulence 2 inverse } } #ifndef (NR_wood_normal) #declare NR_wood_normal = function { pigment { wood warp {cylindrical orientation y dist_exp 1} warp {turbulence 1.25} scale <0.5, 30, 1> warp {turbulence 0.25} scale <1, 5, 1> color_map {[0 rgb <0, 0, 0>] [1 rgb <1, 1, 1>]} } // end pigment } // end function #end #declare NR_woodmap = color_map { [0.00 srgb <0.949, 0.792, 0.514 >] [0.30 srgb <0.855, 0.651, 0.376 >] [0.60 srgb <0.831, 0.596, 0.275 >] [0.90 srgb <0.620, 0.447, 0.204 >] } #declare Tone2 = <1.2, 1.2, 0.3>; #declare NR_woodmap2 = color_map { [0.0 srgb <121, 52, 13>/255 * Tone2] [0.1 srgb <142, 73, 18>/255 * Tone2] [0.3 srgb <184, 115, 48>/255 * Tone2] [0.8 srgb <157, 81, 23>/255 * Tone2] [1.0 srgb <156, 72, 26>/255 * Tone2] } #declare Tone3 = Tone2 * 1.05; #declare NR_woodmap3 = color_map { [0.0 srgb <121, 52, 13>/255 * Tone3] [0.1 srgb <142, 73, 18>/255 * Tone3] [0.3 srgb <184, 115, 48>/255 * Tone3] [0.8 srgb <157, 81, 23>/255 * Tone3] [1.0 srgb <156, 72, 26>/255 * Tone3] } #declare Tone4 = Tone2 * 0.95; #declare NR_woodmap4 = color_map { [0.0 srgb <121, 52, 13>/255 * Tone4] [0.1 srgb <142, 73, 18>/255 * Tone4] [0.3 srgb <184, 115, 48>/255 * Tone4] [0.8 srgb <157, 81, 23>/255 * Tone4] [1.0 srgb <156, 72, 26>/255 * Tone4] } #declare FloorNormal = 0.8; #declare NR_Wood = texture { pigment { NR_wood_grain color_map {NR_woodmap2} ramp_wave } normal {function {NR_wood_normal(x,y,z).grey*FloorNormal}} finish {diffuse 0.6 specular 0.1 roughness 0.005} } #declare NR_Wood2 = texture { pigment {NR_wood_grain color_map {NR_woodmap3} ramp_wave } normal {function {NR_wood_normal(x,y,z).grey*FloorNormal}} finish {diffuse 0.6 specular 0.1 roughness 0.005} } #declare NR_Wood3 = texture { pigment { NR_wood_grain color_map {NR_woodmap4} ramp_wave } normal {function {NR_wood_normal(x,y,z).grey*FloorNormal}} finish {diffuse 0.6 specular 0.1 roughness 0.005} } #ifndef (Wood1) #debug "\n No Wood1 supplied\n" #declare Wood1 = NR_Wood ; #end #ifndef (Wood2) #debug "\n No Wood2 supplied\n" #declare Wood2 = NR_Wood2; #end #ifndef (Wood3) #debug "\n No Wood3 supplied\n" #declare Wood3 = NR_Wood3; #declare Wood5 = texture{pigment{srgb <121, 52, 13>/255 * Tone4}}; // NR_woodmap4 color_map entry 1 #else #declare Wood5 = texture {Wood3} #end #declare Woods = array [3] {Wood1, Wood2, Wood3} //(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o) //(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o)(o) //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| #if (AddBorder) #declare WVD = -1; // set to 1 or -1 to change precedence for width vs depth being on top #declare Rx = seed (356); #declare Ry = seed (876); #declare Rz = seed (159); #declare FloorBorder = union { #declare BorderSize = 2; #declare Offset = 10*Feet; //Left box {<-(Width2)+0, -0.1, Start>, <-(Width2)+(2*BorderSize), 2.0+(0.001*WVD), (Depth*Feet)> texture {Woods[1] rotate <90, 0, 0>}} box {<-(Width2)+(2*BorderSize), -0.1, Start>, <-(Width2)+(6*BorderSize), 2.0+(0.001*WVD), (Depth*Feet)> texture {Wood5}} #declare BlockRow = 0; #declare Alternate = 1; #declare Index = 1; #while (BlockRow < (Depth*Feet)) #declare Randx = rand(Rx) * Offset; // number between zero and Offset #declare Randy = rand(Ry) * Offset; // number between zero and Offset #declare Randz = rand(Rz) * Offset; // number between zero and Offset box {<-(Width2)+(2*BorderSize+0.25), -0.1, BlockRow+0.25>, <-(Width2)+(6*BorderSize-0.25), 2.001+(0.001*WVD), BlockRow+1.75> texture {Woods[Index] rotate <90, 90, 0> translate }} #declare BlockRow = BlockRow + (1*BorderSize); #declare Index = Index + Alternate; #declare Alternate = -Alternate; #end box {<-(Width2)+(6.0*BorderSize), -0.1, Start>, <-(Width2)+(7.5*BorderSize), 2.0+(0.001*WVD), (Depth*Feet)> texture {Woods[1] rotate <90, 0, 0> translate }} box {<-(Width2)+(7.5*BorderSize), -0.1, Start>, <-(Width2)+(8.0*BorderSize), 2.0+(0.001*WVD), (Depth*Feet)> texture {Wood5}} // Right box {<(Width2)-0, -0.1, Start>, <(Width2)-(2*BorderSize), 2.0+(0.001*WVD), (Depth*Feet)> texture {Woods[1] rotate <90, 0, 0>}} box {<(Width2)-(2*BorderSize), -0.1, Start>, <(Width2)-(6*BorderSize), 2.0+(0.001*WVD), (Depth*Feet)> texture {Wood5}} #declare BlockRow = 0; #declare Alternate = 1; #declare Index = 1; #while (BlockRow < (Depth*Feet)) box {<(Width2)-(2*BorderSize+0.25), -0.1, BlockRow+0.25>, <(Width2)-(6*BorderSize-0.25), 2.001+(0.001*WVD), BlockRow+1.75> texture {Woods[Index] rotate <90, 90, 0> translate }} #declare BlockRow = BlockRow + (1*BorderSize); #declare Index = Index + Alternate; #declare Alternate = -Alternate; #end box {<(Width2)-(6*BorderSize), -0.1, Start>, <(Width2)-(7.5*BorderSize), 2.0+(0.001*WVD), (Depth*Feet)> texture {Woods[1] rotate <90, 0, 0> translate }} box {<(Width2)-(7.5*BorderSize), -0.1, Start>, <(Width2)-(8*BorderSize), 2.0+(0.001*WVD), (Depth*Feet)> texture {Wood5}} //----------------------------------------------------------------------------------------------------------------- // Back box {<-(Width2)+12, -0.1, (Depth*Feet)-0>, <(Width2)-12, 2.0-(0.001*WVD), (Depth*Feet)-(2*BorderSize)> texture {Woods[1] rotate <90, 90, 0>}} box {<-(Width2)+12, -0.1, (Depth*Feet)-(2*BorderSize)>, <(Width2)-12, 2.0-(0.001*WVD), (Depth*Feet)-(6*BorderSize)> texture {Wood5}} #declare BlockRow = -(Width2)+12; #declare Alternate = 1; #declare Index = 1; #while (BlockRow < (Width2)-12) box {, texture {Woods[Index] rotate <90, 0, 0>}} #declare BlockRow = BlockRow + (1*BorderSize); #declare Index = Index + Alternate; #declare Alternate = -Alternate; #end box {<-(Width2)+12, -0.1, (Depth*Feet)-(6.0*BorderSize)>, <(Width2)-12, 2.0-(0.001*WVD), (Depth*Feet)-(7.5*BorderSize)> texture {Woods[1] rotate <90, 90, 0>}} box {<-(Width2)+12, -0.1, (Depth*Feet)-(7.5*BorderSize)>, <(Width2)-12, 2.0-(0.001*WVD), (Depth*Feet)-(8*BorderSize)> texture {Wood5}} // Front //box {<-(Width2)+12, -0.1, Start+0>, <(Width2)-12, 2.0, Start+ 4> texture {Woods[1] rotate <90, 0, 0>}} //box {<-(Width2)+12, -0.1, Start+4>, <(Width2)-12, 2.0, Start+ 8> texture {Woods[2] rotate <90, 0, 0>}} //box {<-(Width2)+12, -0.1, Start+8>, <(Width2)-12, 2.0, Start+12> texture {Woods[1] rotate <90, 0, 0>}} box {<-(Width2)+12, -0.1, 0>, <(Width2)-12, 2.0-(0.001*WVD), (2*BorderSize)> texture {Woods[1] rotate <90, 90, 0>}} box {<-(Width2)+12, -0.1, (2*BorderSize)>, <(Width2)-12, 2.0-(0.001*WVD), (6*BorderSize)> texture {Wood5}} #declare BlockRow = -(Width2)+12; #declare Alternate = 1; #declare Index = 1; #while (BlockRow < (Width2)-12) box {, texture {Woods[Index] rotate <90, 0, 0>}} #declare BlockRow = BlockRow + (1*BorderSize); #declare Index = Index + Alternate; #declare Alternate = -Alternate; #end box {<-(Width2)+12, -0.1, (6.0*BorderSize)>, <(Width2)-12, 2.0-(0.001*WVD), (7.5*BorderSize)> texture {Woods[1] rotate <90, 90, 0>}} box {<-(Width2)+12, -0.1, (7.5*BorderSize)>, <(Width2)-12, 2.0-(0.001*WVD), (8*BorderSize)> texture {Wood5}} } // end union #end // end if AddBorder // ################################################################################################ // Wood Floor building loop #debug "Building Floor ...\n" // declare seeds for randomization #declare BL = seed (113); // for board length // for random translation of wood grain texture #declare Rx = seed (356); #declare Ry = seed (876); #declare Rz = seed (159); // random flipping of boards #declare Flip = seed (542); // max amount of translation of wood texture #declare Offset = 10*Feet; #declare MinBoard = 1; // min and max board length in feet #declare MaxBoard = 6; #declare EndGap = 1/2; // gaps between boards in units (inches) #declare SideGap = 1/4; #declare Floor = union { #declare Row = -Width2; #while (Row < Width2) #debug concat("Building Row# ", str(Row, 3, 0), " \n") #declare OverallLength = 0; #declare BoardNo = 1; #while (OverallLength < Depth) #declare RotY = SRand(BL)*5; // number between -5 and 5 #declare Randx = rand(Rx) * Offset; // number between zero and Offset #declare Randy = rand(Ry) * Offset; // number between zero and Offset #declare Randz = rand(Rz) * Offset; // number between zero and Offset //#declare BoardLength = (int(rand (BL)*4)+1)*3; // Some magical calculation that made sense at the time #declare BoardLength = RRand(MinBoard, MaxBoard,BL); #if (rand (Flip) > 0.5) #declare Amt = 180; #else #declare Amt = 0; #end // end if Flip #if (rand (Flip) < 0.3) #declare OakFloor = texture {Woods[0] rotate <90, 0, 0>}; #elseif (rand (Flip) > 0.6) #declare OakFloor = texture {Woods[1]rotate <90, 0, 0>}; #else #declare OakFloor = texture {Woods[2] rotate <90, 0, 0>}; #end // if rand flip #if (OverallLength+BoardLength > Depth) #declare BoardLength = (Depth - OverallLength); #end #declare FloorPlank = box {, } object {FloorPlank texture {OakFloor rotate y*RotY translate } } #declare OverallLength = OverallLength + BoardLength; #debug concat (" Board#", str(BoardNo, 3, 0), " | Rotation:", str(Amt+RotY, 3, 0), " | Overall:", str(OverallLength, 3, 0)," \n") //#if (OverallLength > Depth) #break #end #declare BoardNo = BoardNo + 1; #end // end while OverallLength #declare Row = Row + PlankWidth; #end // end while Row // Dark cracks between floorboards box {<-Width2, 0, Start>, texture {pigment {rgbt <0, 0, 0, 0.4>}} } // Show specified dimensions (for testing) //box {<-Width2, -1, Start>, texture {pigment {Green}} translate -x*1} } // end union #declare Woodfloor = union { object {Floor} #if (AddBorder) object {FloorBorder} #end // end if AddBorder //clipped_by {box {<-Width2, -0.2, 0>, } } } #end // end macro BuildWoodFloor #ifdef (SDL) // do nothing #else #declare _Width = 9*12; #declare _Depth = 15; #declare _PlankWidth = 4; #declare _Unit = 1; #declare WholeFloor = camera { location <0, 17*12, (_Depth*Feet)/2> right x*image_width/image_height look_at <0, 0, (_Depth*Feet)/2+0.1> } #declare Back = camera { location <0, 9*12, (_Depth*Feet)> right x*image_width/image_height look_at <0, 0, (_Depth*Feet)+0.1> } camera {WholeFloor} light_source { <_Width/2, 20*12, _Depth> color rgb <1, 1, 1>} //#declare _Wood1 = texture {pigment {Red}} //#declare _Wood2 = texture {pigment {Green}} //#declare _Wood3 = texture {pigment {Blue}} BuildWoodFloor (_Width, _Depth, _PlankWidth, _Unit, true, _Wood1, _Wood2, _Wood3) #debug concat ( "Max = ", vstr(3, max_extent(Woodfloor), ", ", 3, 0), " \n") object {Woodfloor} #end // end ifdef SDL