|
|
"Samuel B." <stb### [at] hotmailcom> wrote:
> Macro incoming...
Here's the macro. It's not exactly easy to invoke, as you can see by the number
of parameters. Be warned that the arch height cannot fall below the window
width, nor can the window height be less than the arch height. (If that seems
confusing, just play with the params.)
Scroll below the macro definition to see how it's used (includes comments).
#macro Gothic_Window(WW, AH, WH, WD, LT, ET, NA, PT, BW)
#local Eps = .0001; // a small value
union{
// -< window width, arch height, 0 >
#local P = -<WW, AH, 0>;
// arch circle center
#local CC = <.5*(P.x-P.y/(WW/AH)), -AH, 0>;
// arch circle radius
#local CR = vlength(CC);
// window box
box{<-WW, -WH+ET, -Eps>, <-WW+ET, -AH, WD+Eps>}
box{<WW-ET, -WH+ET, -Eps>, <WW, -AH, WD+Eps>}
box{<-WW, -WH, -Eps>, <WW, -WH+ET, WD+Eps>}
difference{
box{<-WW, -AH, 0>, <WW, 0, WD>}
intersection{
cylinder{<CC.x, CC.y, -Eps>, <CC.x, CC.y, WD+Eps>, CR-ET}
cylinder{<-CC.x, CC.y, -Eps>, <-CC.x, CC.y, WD+Eps>, CR-ET}
}
}
#local LT2 = .4 * LT;
// horizonals
cylinder{-<WW, AH, 0>, <WW, -AH, 0>, LT}
cylinder{-<WW, AH, LT>, <WW, -AH, -LT>, LT2}
cylinder{-<WW, WH, 0>, <WW, -WH, 0>, LT}
cylinder{-<WW, WH, LT>, <WW, -WH, -LT>, LT2}
// bottom horizontal, if there's enough room
#if(WH-AH > 16*LT)
cylinder{-<WW, WH-8*LT, 0>, <WW, -WH+8*LT, 0>, LT}
cylinder{-<WW, WH-8*LT, LT>, <WW, -WH+8*LT, -LT>, LT2}
#end
// fancy multiarch setup
#for(I, 0, NA)
#if(I<NA)
#local ArchPiece =
intersection{
merge{
torus{
CR, LT
rotate x*90
translate CC+2*x*WW*I/NA
}
torus{
CR, LT2
rotate x*90
translate CC-z*LT+2*x*WW*I/NA
}
}
plane{y, -AH inverse}
// use vertical cut for first item, otherwise use a cylinder
#if(I=0)
plane{x, 0}
#else
cylinder{<-CC.x, CC.y, -2*LT>, <-CC.x, CC.y, 2*LT>, CR}
#end
}
object{ArchPiece}
object{ArchPiece scale <-1, 1, 1>}
#end
cylinder{-<WW, WH, 0>, -<WW, AH, 0>, LT translate x*2*WW*I/NA}
cylinder{-<WW, WH, LT>, -<WW, AH, LT>, LT2 translate x*2*WW*I/NA}
#end
// fill the corners
sphere{-<WW, WH, 0>, LT}
sphere{<WW, -WH, 0>, LT}
sphere{-<WW, WH, LT>, LT2}
sphere{<WW, -WH, -LT>, LT2}
#local TexWindow =
texture{
pigment{rgb .75 transmit .85}
finish{reflection{0, 1 fresnel} conserve_energy}
}
// window pane
box{
<-WW+Eps, -WH+Eps, PT>, <WW-Eps, -Eps, PT>
texture{TexWindow}
inverse
}
box{
<-WW+Eps, -WH+Eps, Eps>, <WW-Eps, -Eps, Eps>
texture{
TexWindow
normal{
//pigment{ // debug
#local CX = CC.x;
#local CY = CC.y;
#local FA =
function{
min(
1
#for(I, 0, NA-1)
,abs(sqrt(pow(x-CX-2*WW*I/NA, 2)+pow(y-CY, 2)*(y>-AH))-CR)
#end
)
}
function{
min(
1,
min(
FA(x, y, 0),
FA(-x, y, 0),
abs(y+AH),
abs(y+WH)
#if(WH-AH > 16*LT)
,abs(y+WH-8*LT)
#end
) / BW
)
}
bump_size 1
accuracy .003
}
}
interior{ior 1.5}
double_illuminate
}
// place object at y=0
translate y*WH
}
#end
// invoke the macro
object{
Gothic_Window(
1.0, // window width (total_width/2)
1.875, // arch height (>=WW & <=WH)
4.0, // window height
0.75, // window depth
.05/1, // line thickness
.01, // thickness of enclosure around window (window box)
3, // number of arch pieces
.1, // window pane thickness
.2 // window pane bevel width
)
pigment{rgb .75}
}
Post a reply to this message
|
|