//Include file for 'Military Camouflage Net'

#declare mcn_green_dark = color srgb < 45 / 255, 69 / 255, 42 / 255 >;
#declare mcn_brown_dark = color srgb < 87 / 255, 76 / 255, 58 / 255 >;
#declare mcn_brown = color srgb < 114 / 255, 62 / 255, 53 / 255 >;
#declare mcn_clear = color srgbft <0, 0, 0, 0, 1>;

#declare mcn_militaryPat = pigment{ bozo color_map{ [0 mcn_green_dark][0.4 mcn_green_dark][0.5 mcn_brown_dark][1.0 mcn_brown_dark] } scale 8 }
#declare mcn_dullFinish = finish{specular 0.01 roughness 0.01 diffuse 0.4}
#declare mcn_net_texture = texture{ pigment{ leopard pigment_map{[0 mcn_militaryPat ][0.16 mcn_militaryPat][0.2 mcn_clear][1.0 mcn_clear] } scale 0.025 warp{turbulence 0.1 } } finish{mcn_dullFinish} }
#declare mcn_debug_texture = texture{ pigment{ color srgb 0.8 } }

#declare ColumnWidth = 0.25;
#declare ColumnHeight = 4;
#declare Net_x_size = 8;
#declare Net_z_size = 12;
#declare Net_northWest = <-Net_x_size / 2, ColumnHeight,  Net_z_size / 2>;
#declare Net_northEast = < Net_x_size / 2, ColumnHeight,  Net_z_size / 2>;
#declare Net_southWest = <-Net_x_size / 2, ColumnHeight, -Net_z_size / 2>;
#declare Net_southEast = < Net_x_size / 2, ColumnHeight, -Net_z_size / 2>;
#declare Net_centerYpos = 3;


#declare WoodColumn = box{< ColumnWidth / 2, 0, ColumnWidth / 2>,< -ColumnWidth / 2, ColumnHeight, -ColumnWidth / 2> pigment{mcn_brown} finish{mcn_dullFinish} }

#macro GetWidthEquationValue( Width )
    (-Net_centerYpos + ColumnHeight) / 16 * Width * Width + Net_centerYpos
#end

#macro GetDepthEquationValue( Depth )
    (-Net_centerYpos + ColumnHeight) / 36 * Depth * Depth + Net_centerYpos
#end

#macro MakeCamouflageMilitaryNet(step_on_x, step_on_z)
    mesh{
    
    #for( z_pos, -Net_z_size/2, Net_z_size/2 - step_on_z, step_on_z )
        
        #for( x_pos, -Net_x_size / 2, Net_x_size / 2 - step_on_x, step_on_x )
        
            #local NW_pt = < x_pos, (GetWidthEquationValue(x_pos) + GetDepthEquationValue(z_pos) )/2, z_pos >;
            #local NE_pt = < x_pos + step_on_x, ( GetWidthEquationValue(x_pos + step_on_x) + GetDepthEquationValue(z_pos) ) / 2, z_pos >;
            #local SW_pt = < x_pos,             ( GetWidthEquationValue(x_pos)+ GetDepthEquationValue(z_pos + step_on_z) ) / 2, z_pos + step_on_z >;
            #local SE_pt = < x_pos + step_on_x, ( GetWidthEquationValue(x_pos + step_on_x) + GetDepthEquationValue(z_pos + step_on_z) )/2, z_pos + step_on_z >;
            
            triangle{ NW_pt, NE_pt, SW_pt }
            triangle{ NE_pt, SW_pt, SE_pt } 
        
        #end
    #end
        texture{mcn_net_texture}
    }
#end

#declare CamoufledBuilding = union{ 
                                   object{WoodColumn translate <-Net_x_size / 2 + ColumnWidth / 2, 0,  Net_z_size / 2 - ColumnWidth / 2>}
                                   object{WoodColumn translate < Net_x_size / 2 - ColumnWidth / 2, 0,  Net_z_size / 2 - ColumnWidth / 2>}
                                   object{WoodColumn translate <-Net_x_size / 2 + ColumnWidth / 2, 0, -Net_z_size / 2 + ColumnWidth / 2>}
                                   object{WoodColumn translate < Net_x_size / 2 - ColumnWidth / 2, 0, -Net_z_size / 2 + ColumnWidth / 2>}
                                   MakeCamouflageMilitaryNet(1, 1)
                            }
                            
