/**************************** each bezier curve segment has 'resolution+1' amout sphere. each sphere and cylinder are just union. ****************************/ #include "shapes.inc" #macro Shape_Bezierpoints_Sphere_Sweep(_resolution, _points_array, _radius) #if(_resolution <= 1) #local res = 1; #else #local res = int(_resolution); #end #if(dimensions(_points_array) != 1) #error "" #elseif(div(dimension_size(_points_array,1),4) - dimension_size(_points_array,1)/4 != 0) #error "" #else #local n_of_seg = div(dimension_size(_points_array,1), 4); #local ctrl_pts_array = array[n_of_seg] #for(i, 0, n_of_seg-1) #local ctrl_pts_array[i] = array[4] {_points_array[4*i], _points_array[4*i+1], _points_array[4*i+2], _points_array[4*i+3]} #end #end #local sphere_r = abs(_radius); #local mockup1 = union{ #for(i, 0, n_of_seg-1) #local para_t = (1/2)/res; #local this_point = ctrl_pts_array[i][0]*pow(1-para_t,3) + ctrl_pts_array[i][1]*3*pow(1-para_t,2)*para_t + ctrl_pts_array[i][2]*3*(1-para_t)*pow(para_t,2) + ctrl_pts_array[i][3]*pow(para_t,3); #if(i = 0) sphere{ ctrl_pts_array[i][0], sphere_r } #end object{ Connect_Spheres(ctrl_pts_array[i][0], sphere_r, this_point, sphere_r) } sphere{ this_point, sphere_r } #for(j, 1, res-1) #local last_point = this_point; #local para_t = (1/2+j)/res; #local this_point = ctrl_pts_array[i][0]*pow(1-para_t,3) + ctrl_pts_array[i][1]*3*pow(1-para_t,2)*para_t + ctrl_pts_array[i][2]*3*(1-para_t)*pow(para_t,2) + ctrl_pts_array[i][3]*pow(para_t,3); object{ Connect_Spheres(last_point, sphere_r, this_point, sphere_r) } sphere{ this_point, sphere_r } #end #local last_point = this_point; #local this_point = ctrl_pts_array[i][3]; object{ Connect_Spheres(last_point, sphere_r, this_point, sphere_r) } sphere{ this_point, sphere_r } #end } mockup1 #end