Index: src/conv/gcode/g-gcode.c
===================================================================
--- src/conv/gcode/g-gcode.c	(revision 0)
+++ src/conv/gcode/g-gcode.c	(revision 0)
@@ -0,0 +1,189 @@
+
+#include "common.h"
+
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "vmath.h"	
+#include "raytrace.h"
+#include "bu.h"
+#include "wdb.h"		
+
+#define LIMX 285
+#define LIMY 153
+#define LIMZ 155
+
+struct printer{
+  double printerRes;
+  double nozzleD;
+  double filamentD;
+};
+
+char array[2850][1530];
+int slice;
+
+double convert(double num, struct printer p){
+    num=num/p.printerRes;
+    return num;
+}
+
+double unconvert(double num, struct printer p){
+    num=num*p.printerRes;
+    return num;
+}
+
+
+int
+hit(struct application *ap, struct partition *PartHeadp, struct seg *UNUSED(segs))
+{
+    
+    double in;
+    double out;
+    int x=0;
+    struct partition *pp;
+
+    struct hit *hitp;
+
+    // point_t pt;
+   
+    for (pp=PartHeadp->pt_forw; pp != PartHeadp; pp = pp->pt_forw) {
+	
+        hitp = pp->pt_inhit;
+	in = hitp->hit_dist;
+
+	hitp = pp->pt_outhit;
+	out = hitp->hit_dist;
+
+	for(x=in; x<out; x++){
+	  array[x][slice]='1';
+	}
+
+    }
+
+    return 1;
+}
+
+
+
+int
+miss(struct application *UNUSED(ap))
+{
+  return 0;
+}
+
+int G1(FILE *fp, struct printer p, double *extrude){
+  int in, out, i, ii;
+  for(i=0; i<convert(LIMX, p); i++){
+    for(ii=0; ii<convert(LIMY, p); ii++){
+      if(array[i][ii]=='1'){
+	in=ii;
+	do{
+	  ii++;
+	}while(array[i][ii]=='1');
+	out=ii;
+	*extrude = *extrude + (unconvert(out-in, p)*p.nozzleD/p.filamentD);
+	fprintf(fp, "G1 X%g Y%g\n", unconvert(i,p), unconvert(in,p));
+	fprintf(fp, "G1 Y%g E%g\n", unconvert(out,p), *extrude);
+
+      }
+    }
+  }
+  
+  return 1;
+}
+
+int
+main(int argc, char **argv)
+{
+    
+    FILE* fp;
+
+    double extrude=0;
+
+    struct printer p;
+
+    struct application	ap;
+
+    static struct rt_i *rtip;
+
+    char title[1024] = {0};
+    char filename[1024];
+
+    int z, i, ii;
+    
+    p.printerRes = .1;
+    p.nozzleD = .4;
+    p.filamentD = 1.75;
+    
+    sprintf(filename, "%s.gcode", argv[1]);
+
+    fp = fopen(filename, "w");
+
+    if (argc < 3) {
+	bu_exit(1, "Usage: %s model.g objects...\n", argv[0]);
+    }
+
+
+    rtip = rt_dirbuild(argv[1], title, sizeof(title));
+    if (rtip == RTI_NULL) {
+	bu_exit(2, "Building the database directory for [%s] FAILED\n", argv[1]);
+    }
+
+
+    if (title[0]) {
+	bu_log("Title:\n%s\n", title);
+    }
+
+
+    while (argc > 2)  {
+	if (rt_gettree(rtip, argv[2]) < 0)
+	    bu_log("Loading the geometry for [%s] FAILED\n", argv[2]);
+	argc--;
+	argv++;
+    }
+
+    rt_prep_parallel(rtip, 1);
+
+    RT_APPLICATION_INIT(&ap);
+
+ 
+    ap.a_rt_i = rtip;
+
+    ap.a_onehit = 0;
+
+ 
+    VSET(ap.a_ray.r_pt, 0.0, 0.0, 0);
+    VSET(ap.a_ray.r_dir, 1.0, 0, 0);
+
+
+    ap.a_hit = hit;
+    ap.a_miss = miss;
+
+    fprintf(fp, "M107\n M190 S58 ; wait for bed temperature to be reached\n M104 S190 ; set temperature\n G28 ; home all axes\n M109 S190 ; wait for temperature to be reached\n G90 ; use absolute coordinates\n G21 ; set units to millimeters\n ");
+    
+    for(z=0; z<convert(LIMZ, p); z++){
+        for(i=0; i<convert(LIMX, p); i++){
+	    for(ii=0; ii<convert(LIMY, p); ii++){
+	        array[i][ii]='.';
+            }
+        }
+        for(slice=0; slice<convert(LIMY, p); slice++){
+	    (void)rt_shootray(&ap);
+	    VSET(ap.a_ray.r_pt, 0, unconvert(slice, p), unconvert(z, p));
+        }
+	printf("layer %d out of %g\n", z, convert(LIMZ, p));
+	fprintf(fp, "G1 Z%g\n", unconvert((double)z, p));
+	G1(fp, p, &extrude);
+    }
+
+    //    for(i=0; i<100; i++){
+    //      for(ii=0; ii<500; ii++)
+    //	  printf("%c",array[i][ii]);
+    //	printf("\n");
+    //    }
+ 
+    fprintf(fp, "G0 X0 Y0 Z0");
+    return 0;
+}
Index: src/conv/gcode/CMakeLists.txt
===================================================================
--- src/conv/gcode/CMakeLists.txt	(revision 0)
+++ src/conv/gcode/CMakeLists.txt	(revision 0)
@@ -0,0 +1,23 @@
+set(GCODE_INCLUDE_DIRS
+  ${BU_INCLUDE_DIRS}
+  ${RT_INCLUDE_DIRS}
+  ${WDB_INCLUDE_DIRS}
+  )
+
+LIST(REMOVE_DUPLICATES GCODE_INCLUDE_DIRS)
+include_directories(${GCODE_INCLUDE_DIRS})
+
+set(ggcode_SRCS
+  g-gcode.c
+  )
+
+
+BRLCAD_ADDEXEC(g-gcode "${ggcode_SRCS}" "libwdb;librt;libbu" NOSTRICT)
+
+# Local Variables: 
+# tab-width: 8
+# mode: cmake
+# indent-tabs-mode: t
+# End:  
+# ex: shiftwidth=2 tabstop=8                                                     
+
Index: src/conv/CMakeLists.txt
===================================================================
--- src/conv/CMakeLists.txt	(revision 55208)
+++ src/conv/CMakeLists.txt	(working copy)
@@ -11,6 +11,7 @@
 
 add_subdirectory(step)
 
+add_subdirectory(gcode)
 add_subdirectory(iges)
 add_subdirectory(intaval)
 add_subdirectory(raw)
