# AngelScript CSG – part 3

Windows 64bit here.
Linux (K)ubuntu 15.10 64bit here.

This is an update to previous articles part 1 and part 2 on AngelScript CSG, which is using AngelScript as a language for Constructive Solid geometry (CSG).

Today's update is to describe the latest couple of changes. One may now create polyhedrons from image files and from OpenSCAD style text files. To support images a new command “image2d” has been introduced, supporting image files of type PNG, JPG, GIF, XPM and more. It is also possible to resample an imported image before using it to create a 3d model.  From photo to 3d-model

The code:

 shape@ main_shape(){      image2d@ image = image2d("ektepar_ca.png");   uint w = image.width();   uint h = image.height();   double s =0.002;   double dx=400;   double dy=400;   auto surface = loft3d( image,dx,dy,w);   return  mirror(0,1,0)*           scale(s/5,s/5,2*s)*     polyhedron(surface,vec3d(0,0,-300),h);}

If the image is very large it is a good idea to downsize it before it is imported, or alternatively use the “resize” method supported on image2d objects. A third way is to keep the image size but reduce the final segmentation. To reduce the segmentation by half in the example above, you could enter w/2 in the call to loft3d and h/2 in the call to polyhedron.
Another example is using an
OpenSCAD surface text file to create a model of a wolf on a mug: Wolf from text file

As in the case with the image, the data is used to create a lofted surface and from that a polyhedron is created. In this case the data file contains 300 data points in X and 275 rowx (y).

 const double pi = 4.0*atan(1.0); double to_rad(double deg) { return pi*deg/180.0; }  // from degree to radian shape@ main_shape(){      double h = 30;   double r = 30;   double e = 3;    solid@ cyl = cylinder(h+10,r+e);    // model space distance between the data points   double dx=1;   double dy=1;    // specify that default segmentation shall be used, i.e.   // all points in the file in s-dir (=x) and t-dir (=y)   int ns_seg = -1;   int nt_seg = -1;   loft3d@ surface = loft3d("model.data.txt",dx,dy,ns_seg);    solid@  wolf = translate(-23.1,-0.5,h+5) *                  rotate_x(to_rad(-90)) *                   scale(0.154, 0.109, 1)*                  polyhedron(surface,vec3d(0,0,-30),nt_seg);      return union3d(cyl,wolf);} void main(){   shape@ obj = main_shape();   obj.write_csg(GetOutputFullPath('.csg')); }