// Textured rounded box macro include // Invoke using TexturedBrick(x_size, y_size, z_size, edge_radius, // resolution, surface_amplitude, texture_scale, move_vec) // _size are axis 'radii'; e.g. width = 2*x_size // edge_radius is radius of curved edge / corner // resolution is number of facets across smallest dimension // surface_amplitude is 'height' of texturing above / below nominal box surface (-ve is valid) // texture_scale is scale vector for pigment function // move_vec is a vector to translate the perturbation texture #declare gran = function { pigment { granite color_map { [0 color rgb 0.1] [0.4 color rgb 0] [1 color rgb 1] } } } #macro Curv(posx, posy, rd, sx, sy, vx, vy, nml, result1, result2) #local vecx = vnormalize(vx); #local vecy = vnormalize(vy); #local t1 = 0; #local t2 = 0; #if (vlength(posx) < rd) #local t1 = -(rd-vlength(posx)); #end #if (vlength(posy) < rd) #local t2 = -(rd-vlength(posy)); #end #if (vlength(posx) > sx-rd) #local t1 = rd-(sx-vlength(posx)); #end #if (vlength(posy) > sy-rd) #local t2 = rd-(sy-vlength(posy)); #end #local nn = vnormalize(nml); #local vecr = t1*vecx + t2*vecy + nn*rd; #local result1 = -(vlength(vecr)-rd)*vnormalize(vecr); #local result2 = vnormalize(vecr); #end #macro Displace(posi, vect, scal, ampl, mv) ( ampl * vect * gran((mv+posi.x)/scal.x, (mv+posi.y)/scal.y, (mv+posi.z)/scal.z).x ) #end #macro Face(posit, sx,sy, nx,ny, vx,vy,norm, rad, amp, sc, mv) #local dpx = vx*sx/(nx-1); #local dpy = vy*sy/(ny-1); #local ox = -vx*sx/2; #local oy = -vy*sy/2; #local px = <0,0,0>; #local py = <0,0,0>; #local result1 = <0,0,0>; #local result2 = <0,0,0>; #local Vertices = nx*ny; #local Faces = (nx-1)*(ny-1)*2; mesh2 { vertex_vectors { Vertices, #local n = 0; #while (n < Vertices-1) #local pos = posit + ox + oy + px + py; Curv(px, py, rad, sx, sy, vx, vy, norm, result1, result2) #local pos = pos + result1 + Displace(pos+result1, vnormalize(pos+result1), sc, amp, mv); pos, #local n = n + 1; #local px = px + dpx; #if (vlength(px) = sx+vlength(dpx)) #local px = 0; #local py = py + dpy; #end #end #local pos = posit + ox + oy + px + py; Curv(px, py, rad, sx, sy, vx, vy, norm, result1, result2) #local pos = pos + result1 + Displace(pos+result1, vnormalize(pos+result1), sc, amp, mv); pos } face_indices { Faces, #local n = 0; #while (n < Vertices-nx-2) , , #local n = n + 1; #if (mod(n-(nx-1), nx) = 0) #local n = n + 1; #end #end , } } #end #macro TexturedBrick(xs, ys, zs, rad, res, amp, sc, move) #local minSize = min(xs, min(ys, zs)); union { Face(<0,ys,0>, xs*2,zs*2, int(xs*res/minSize),int(zs*res/minSize), <1,0,0>, <0,0,1>, <0,1,0>, rad, amp, sc, move) Face(<0,-ys,0>, xs*2,zs*2, int(xs*res/minSize),int(zs*res/minSize), <-1,0,0>, <0,0,1>, <0,-1,0>, rad, amp, sc, move) Face(, ys*2,zs*2, int(ys*res/minSize),int(zs*res/minSize), <0,-1,0>, <0,0,1>, <1,0,0>, rad, amp, sc, move) Face(<-xs,0,0>, ys*2,zs*2, int(ys*res/minSize),int(zs*res/minSize), <0,1,0>, <0,0,1>, <-1,0,0>, rad, amp, sc, move) Face(<0,0,-zs>, xs*2,ys*2, int(xs*res/minSize),int(ys*res/minSize), <1,0,0>, <0,1,0>, <0,0,-1>, rad, amp, sc, move) Face(<0,0,zs>, xs*2,ys*2, int(xs*res/minSize),int(ys*res/minSize), <1,0,0>, <0,-1,0>, <0,0,1>, rad, amp, sc, move) } #end