//----------------------------------------------------------------------------- #macro strvect(vect) concat ("<",str(vect.x,0,2),",",str(vect.y,0,2),",",str(vect.z,0,2),">") #end //----------------------------------------------------------------------------- #macro bound(obj,nb_samples,resmin,resmax) #local oMin = min_extent(obj); #local oMax = max_extent(obj); #local dist = oMax-oMin; // Recherche la plus grande direction #if (dist.x>dist.y) #if (dist.x>dist.z) #local dir=x; #local dir1=y; #local dir2=z; #else #local dir=z; #local dir1=y; #local dir2=x; #end #else #if (dist.y>dist.z) #local dir=y; #local dir1=z; #local dir2=x; #else #local dir=z; #local dir1=y; #local dir2=x; #end #end // Calcul des pas pour les samples, et des pts de departs #local pas1=vdot(dir1,dist)/nb_samples; #local pas2=vdot(dir2,dist)/nb_samples; #local pt1=vdot(oMin,dir)*dir; #local pt2=vdot(oMax,dir)*dir; #local orgn=vdot(oMin,dir1)*dir1+vdot(oMin,dir2)*dir2; #local norm=<0,0,0>; #local bmin=oMax; #local bmax=oMin; #local i=1; #while (i0) #if (inter.x; #end #if (inter.y; #end #if (inter.z; #end #if (inter.x>bmax.x) #local bmax=; #end #if (inter.y>bmax.y) #local bmax=; #end #if (inter.z>bmax.z) #local bmax=; #end #end #local inter=trace(obj, orgn+i*pas1*dir1+j*pas2*dir2+pt2, -dir, norm); #if (vlength(norm)>0) #if (inter.x; #end #if (inter.y; #end #if (inter.z; #end #if (inter.x>bmax.x) #local bmax=; #end #if (inter.y>bmax.y) #local bmax=; #end #if (inter.z>bmax.z) #local bmax=; #end #end #local j=j+1; #end #local i=i+1; #end #declare resmin=bmin-pas1*dir1-pas2*dir2; #declare resmax=bmax+pas1*dir1+pas2*dir2; #end //----------------------------------------------------------------------------- #macro transfo(view,sxy,sxz,syz) #if (strcmp(view,"front")=0) scale sxy #end #if (strcmp(view,"back")=0) scale sxy rotate 180*y #end #if (strcmp(view,"left")=0) scale syz rotate -90*y #end #if (strcmp(view,"right")=0) scale syz rotate 90*y #end #if (strcmp(view,"top")=0) scale sxz rotate -90*x #end #if (strcmp(view,"bottom")=0) scale sxz rotate 90*x #end #if (strcmp(view,"perspective")=0) scale min(min(sxy,sxz),syz)*1/sqrt(2) rotate 25*x rotate -35*y #end #end //----------------------------------------------------------------------------- #macro Views(obj,view1,view2,view3,view4,same_scale,view_bound,nb_samples) #local sv = 50; #local unpix = 2*sv/image_width; #local border = 15*unpix; #local h_texte = 10*unpix; #local b_texte = 2*unpix; #local texte=text { ttf "timrom.ttf" "f" 5, 0 } #local stexte=h_texte/(max_extent(texte).y-min_extent(texte).y); //----------------------------------------------------------------------------- // Definition des lumières #local lum1 = light_source { <-sv/2,sv/4,-sv> color rgb 1 } #local lum2 = light_source { color rgb .3 } #local lum3 = light_source { <0,sv,sv> color rgb .5 } //----------------------------------------------------------------------------- // Definition du repere #local len = 10*(2*sv/image_width); #local repere = union { cylinder { <0,0,0>, , unpix/2 pigment { color rgb <1,0,0> } finish { ambient 1 } } cone { , unpix*2, , 0 pigment { color rgb <1,0,0> } finish { ambient 1 } } cylinder { <0,0,0>, <0,len,0>, unpix/2 pigment { color rgb <0,1,0> } finish { ambient 1 } } cone { <0,len,0>, unpix*2, <0,len+len/3,0>, 0 pigment { color rgb <0,1,0> } finish { ambient 1 } } cylinder { <0,0,0>, <0,0,len>, unpix/2 pigment { color rgb <0,0,1> } finish { ambient 1 } } cone { <0,0,len>, unpix*2, <0,0,len+len/3>, 0 pigment { color rgb <0,0,1> } finish { ambient 1 } } translate <2*unpix,2*unpix,2*unpix> } #local taille_repere= 4/3*len+2*unpix; #local centre_repere= ; //----------------------------------------------------------------------------- // Dimensions de l'objet #local oMin = min_extent(obj); #local oMax = max_extent(obj); #if (nb_samples>0) bound(obj,nb_samples,oMin,oMax) #end #if (view_bound) #local objbound = object { box { oMin,oMax } pigment { color rgbf <1,1,1,.5> } } #end #if (same_scale) #local leng = max(max(oMax.x-oMin.x,oMax.y-oMin.y),oMax.z-oMin.z); #local scxy=(sv-2*border)/leng; #local scxz=scxy; #local scyz=scxy; #else #local leng=max(oMax.x-oMin.x,oMax.y-oMin.y); #local scxy=(sv-2*border)/leng; #local leng=max(oMax.x-oMin.x,oMax.z-oMin.z); #local scxz=(sv-2*border)/leng; #local leng=max(oMax.z-oMin.z,oMax.y-oMin.y); #local scyz=(sv-2*border)/leng; #end #local to_origin=-(oMin+(oMax-oMin)/2); //----------------------------------------------------------------------------- // Camera camera { orthographic right x*sv*2 up y*sv*2 location <0,0,-sv*4> look_at <0,0,0> } //----------------------------------------------------------------------------- // Axes pour séparer les vues cylinder { <0,-sv,0>,<0,sv,0>, unpix/2 pigment { color rgb 1 } finish { ambient 1 } } cylinder { <-sv,0,0>,, unpix/2 pigment { color rgb 1 } finish { ambient 1 } } //----------------------------------------------------------------------------- // View1 #local transl = <-sv/2,sv/2,0>; light_group { object { obj translate to_origin transfo(view1,scxy,scxz,scyz) translate transl } light_source { lum1 translate transl } light_source { lum2 translate transl } light_source { lum3 translate transl } #if (view_bound) object { objbound translate to_origin transfo(view1,scxy,scxz,scyz) translate transl } #end } text { ttf "timrom.ttf" view1 5, 0 pigment { color rgb 1 } finish { ambient 1 } scale stexte translate <-sv+b_texte,sv-h_texte-b_texte,-3*sv> } object { repere translate -centre_repere transfo(view1,1,1,1) translate centre_repere translate <-taille_repere-4*unpix,4*unpix,-3*sv> } //----------------------------------------------------------------------------- // View2 #local transl = ; light_group { object { obj translate to_origin transfo(view2,scxy,scxz,scyz) translate transl } light_source { lum1 translate transl } light_source { lum2 translate transl } light_source { lum3 translate transl } #if (view_bound) object { objbound translate to_origin transfo(view2,scxy,scxz,scyz) translate transl } #end } text { ttf "timrom.ttf" view2 5, 0 pigment { color rgb 1 } finish { ambient 1 } scale stexte translate } object { repere translate -centre_repere transfo(view2,1,1,1) translate centre_repere translate } //----------------------------------------------------------------------------- // view3 #local transl = <-sv/2,-sv/2,0>; light_group { object { obj translate to_origin transfo(view3,scxy,scxz,scyz) translate transl } light_source { lum1 translate transl } light_source { lum2 translate transl } light_source { lum3 translate transl } #if (view_bound) object { objbound translate to_origin transfo(view3,scxy,scxz,scyz) translate transl } #end } text { ttf "timrom.ttf" view3 5, 0 pigment { color rgb 1 } finish { ambient 1 } scale stexte translate <-sv+b_texte,-h_texte-b_texte,-3*sv> } object { repere translate -centre_repere transfo(view3,1,1,1) translate centre_repere translate <-taille_repere-4*unpix,-sv+4*unpix,-3*sv> } //----------------------------------------------------------------------------- // view4 #local transl = ; light_group { object { obj translate to_origin transfo(view4,scxy,scxz,scyz) translate transl } light_source { lum1 translate transl } light_source { lum2 translate transl } light_source { lum3 translate transl } #if (view_bound) object { objbound translate to_origin transfo(view4,scxy,scxz,scyz) translate transl } #end } text { ttf "timrom.ttf" view4 5, 0 pigment { color rgb 1 } finish { ambient 1 } scale stexte translate } object { repere translate -centre_repere transfo(view4,1,1,1) translate centre_repere translate } #end //-----------------------------------------------------------------------------