Index: trunk/src_plugins/export_stl/exp_fmt_amf.c =================================================================== --- trunk/src_plugins/export_stl/exp_fmt_amf.c (revision 35994) +++ trunk/src_plugins/export_stl/exp_fmt_amf.c (revision 35995) @@ -24,64 +24,6 @@ * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") */ -static void amf_print_horiz_tri(FILE *f, fp2t_triangle_t *t, int up, rnd_coord_t z) -{ - if (up) { - verthash_add_triangle_coord(&verthash, - t->Points[0]->X, t->Points[0]->Y, z, - t->Points[1]->X, t->Points[1]->Y, z, - t->Points[2]->X, t->Points[2]->Y, z - ); - } - else { - verthash_add_triangle_coord(&verthash, - t->Points[2]->X, (rnd_coord_t)t->Points[2]->Y, z, - t->Points[1]->X, (rnd_coord_t)t->Points[1]->Y, z, - t->Points[0]->X, (rnd_coord_t)t->Points[0]->Y, z - ); - } -} - -static void amf_print_vert_tri(FILE *f, rnd_coord_t x1, rnd_coord_t y1, rnd_coord_t x2, rnd_coord_t y2, rnd_coord_t z0, rnd_coord_t z1) -{ - verthash_add_triangle_coord(&verthash, - x2, y2, z1, - x1, y1, z1, - x1, y1, z0 - ); - - verthash_add_triangle_coord(&verthash, - x2, y2, z1, - x1, y1, z0, - x2, y2, z0 - ); -} - - -static void amf_print_facet(FILE *f, stl_facet_t *head, double mx[16], double mxn[16]) -{ - double v[3], p[3]; - long vert[3]; - int n; - - for(n = 0; n < 3; n++) { - p[0] = head->vx[n]; p[1] = head->vy[n]; p[2] = head->vz[n]; - v_transform(v, p, mx); - vert[n] = verthash_add_vertex(&verthash, - (rnd_coord_t)RND_MM_TO_COORD(v[0]), - (rnd_coord_t)RND_MM_TO_COORD(v[1]), - (rnd_coord_t)RND_MM_TO_COORD(v[2]) - ); - } - - verthash_add_triangle(&verthash, vert[0], vert[1], vert[2]); -} - -static void amf_new_obj(float r, float g, float b) -{ - verthash_new_obj(&verthash, r, g, b); -} - static void amf_print_header(FILE *f) { fprintf(f, "\n"); @@ -138,10 +80,10 @@ static const stl_fmt_t fmt_amf = { /* output */ ".amf", - amf_print_horiz_tri, - amf_print_vert_tri, - amf_print_facet, - amf_new_obj, + vhs_print_horiz_tri, + vhs_print_vert_tri, + vhs_print_facet, + vhs_new_obj, amf_print_header, amf_print_footer, Index: trunk/src_plugins/export_stl/exp_fmt_proj.c =================================================================== --- trunk/src_plugins/export_stl/exp_fmt_proj.c (revision 35994) +++ trunk/src_plugins/export_stl/exp_fmt_proj.c (revision 35995) @@ -59,10 +59,10 @@ static const stl_fmt_t fmt_proj = { /* output */ ".pro", - amf_print_horiz_tri, - amf_print_vert_tri, - amf_print_facet, - amf_new_obj, + vhs_print_horiz_tri, + vhs_print_vert_tri, + vhs_print_facet, + vhs_new_obj, proj_print_header, proj_print_footer, Index: trunk/src_plugins/export_stl/export_stl.c =================================================================== --- trunk/src_plugins/export_stl/export_stl.c (revision 35994) +++ trunk/src_plugins/export_stl/export_stl.c (revision 35995) @@ -320,8 +320,6 @@ #include "verthash.c" -static verthash_t verthash; - typedef struct { /* output */ const char *suffix; Index: trunk/src_plugins/export_stl/verthash.c =================================================================== --- trunk/src_plugins/export_stl/verthash.c (revision 35994) +++ trunk/src_plugins/export_stl/verthash.c (revision 35995) @@ -93,3 +93,67 @@ vtl0_append(&vh->triangles, rnd_round(g*1000000)); vtl0_append(&vh->triangles, rnd_round(b*1000000)); } + +/* The following functions implement the standard API of export_stl for building + a verthash so that the export format needs to deal with verthash->output + conversion only */ + +static verthash_t verthash; + +static void vhs_print_horiz_tri(FILE *f, fp2t_triangle_t *t, int up, rnd_coord_t z) +{ + if (up) { + verthash_add_triangle_coord(&verthash, + t->Points[0]->X, t->Points[0]->Y, z, + t->Points[1]->X, t->Points[1]->Y, z, + t->Points[2]->X, t->Points[2]->Y, z + ); + } + else { + verthash_add_triangle_coord(&verthash, + t->Points[2]->X, (rnd_coord_t)t->Points[2]->Y, z, + t->Points[1]->X, (rnd_coord_t)t->Points[1]->Y, z, + t->Points[0]->X, (rnd_coord_t)t->Points[0]->Y, z + ); + } +} + +static void vhs_print_vert_tri(FILE *f, rnd_coord_t x1, rnd_coord_t y1, rnd_coord_t x2, rnd_coord_t y2, rnd_coord_t z0, rnd_coord_t z1) +{ + verthash_add_triangle_coord(&verthash, + x2, y2, z1, + x1, y1, z1, + x1, y1, z0 + ); + + verthash_add_triangle_coord(&verthash, + x2, y2, z1, + x1, y1, z0, + x2, y2, z0 + ); +} + + +static void vhs_print_facet(FILE *f, stl_facet_t *head, double mx[16], double mxn[16]) +{ + double v[3], p[3]; + long vert[3]; + int n; + + for(n = 0; n < 3; n++) { + p[0] = head->vx[n]; p[1] = head->vy[n]; p[2] = head->vz[n]; + v_transform(v, p, mx); + vert[n] = verthash_add_vertex(&verthash, + (rnd_coord_t)RND_MM_TO_COORD(v[0]), + (rnd_coord_t)RND_MM_TO_COORD(v[1]), + (rnd_coord_t)RND_MM_TO_COORD(v[2]) + ); + } + + verthash_add_triangle(&verthash, vert[0], vert[1], vert[2]); +} + +static void vhs_new_obj(float r, float g, float b) +{ + verthash_new_obj(&verthash, r, g, b); +}