Index: trunk/src/Makefile.dep =================================================================== --- trunk/src/Makefile.dep (revision 35993) +++ trunk/src/Makefile.dep (revision 35994) @@ -702,6 +702,7 @@ ../src_3rd/fast89-poly2tri/fast89_poly2tri.h \ ../src_plugins/export_stl/exp_fmt_stl.c \ ../src_plugins/export_stl/exp_fmt_amf.c \ + ../src_plugins/export_stl/exp_fmt_proj.c \ ../src_plugins/export_stl/stl_models.c \ ../src_plugins/export_stl/model_load_stl.c \ ../src_plugins/export_stl/model_load_amf.c \ Index: trunk/src_plugins/export_stl/exp_fmt_proj.c =================================================================== --- trunk/src_plugins/export_stl/exp_fmt_proj.c (nonexistent) +++ trunk/src_plugins/export_stl/exp_fmt_proj.c (revision 35994) @@ -0,0 +1,74 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2021 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + +static void proj_print_header(FILE *f) +{ + fprintf(f, "obj \"board\"\n"); + fprintf(f, " realempty\n"); + + verthash_init(&verthash); +} + +static void proj_print_footer(FILE *f) +{ + long n, *vx; + rnd_coord_t *c; + + + fprintf(f, " verts\n"); + for(n = 0, c = verthash.vxcoords.array; n < verthash.next_id; n++, c += 3) + rnd_fprintf(f, " %.09mm %.09mm %.09mm\n", c[0], c[1], c[2]); + + for(n = 0, vx = verthash.triangles.array; n < verthash.triangles.used; n += 3, vx += 3) { + if (vx[0] < 0) { + vx++; + n++; + fprintf(f, " color %.6f %.6f %.6f\n", (double)vx[0]/1000000, (double)vx[1]/1000000, (double)vx[2]/1000000); + continue; /* shift colors */ + } + rnd_fprintf(f, " tri :%ld :%ld :%ld\n", vx[0], vx[1], vx[2]); + } + fprintf(f, " normals\n"); + + verthash_uninit(&verthash); +} + +static const stl_fmt_t fmt_proj = { + /* output */ + ".pro", + amf_print_horiz_tri, + amf_print_vert_tri, + amf_print_facet, + amf_new_obj, + proj_print_header, + proj_print_footer, + + /* model load */ + "projector", + "projector::translate", NULL, + "projector::rotate", NULL, + NULL /* no loader yet */ +}; Index: trunk/src_plugins/export_stl/export_stl.c =================================================================== --- trunk/src_plugins/export_stl/export_stl.c (revision 35993) +++ trunk/src_plugins/export_stl/export_stl.c (revision 35994) @@ -47,7 +47,7 @@ #include "../lib_polyhelp/topoly.h" #include "../lib_polyhelp/triangulate.h" -static rnd_hid_t stl_hid, amf_hid; +static rnd_hid_t stl_hid, amf_hid, proj_hid; const char *stl_cookie = "export_stl HID"; static const rnd_export_opt_t stl_attribute_list[] = { @@ -354,8 +354,9 @@ #include "exp_fmt_stl.c" #include "exp_fmt_amf.c" +#include "exp_fmt_proj.c" -static const stl_fmt_t *fmt_all[] = {&fmt_amf, &fmt_stl, NULL}; +static const stl_fmt_t *fmt_all[] = {&fmt_amf, &fmt_stl, &fmt_proj, NULL}; #include "stl_models.c" #include "model_load_stl.c" @@ -372,6 +373,11 @@ return stl_get_export_options_(hid, n, &fmt_amf); } +static const rnd_export_opt_t *proj_get_export_options(rnd_hid_t *hid, int *n) +{ + return stl_get_export_options_(hid, n, &fmt_proj); +} + static int stl_hid_export_to_file(FILE *f, rnd_hid_attr_val_t *options, rnd_coord_t maxy, rnd_coord_t z0, rnd_coord_t z1, const stl_fmt_t *fmt) { pcb_dynf_t df; @@ -539,6 +545,11 @@ stl_do_export_(hid, options, &fmt_amf); } +static void proj_do_export(rnd_hid_t *hid, rnd_hid_attr_val_t *options) +{ + stl_do_export_(hid, options, &fmt_proj); +} + static int stl_parse_arguments(rnd_hid_t *hid, int *argc, char ***argv) { rnd_export_register_opts2(hid, stl_attribute_list, sizeof(stl_attribute_list) / sizeof(stl_attribute_list[0]), stl_cookie, 0); @@ -587,14 +598,25 @@ rnd_hid_register_hid(&stl_hid); rnd_hid_load_defaults(&stl_hid, stl_attribute_list, NUM_OPTIONS); + memcpy(&amf_hid, &stl_hid, sizeof(rnd_hid_t)); amf_hid.name = "amf"; amf_hid.description = "export board outline in 3-dimensional AMF"; - stl_hid.get_export_options = amf_get_export_options; + amf_hid.get_export_options = amf_get_export_options; amf_hid.do_export = amf_do_export; rnd_hid_register_hid(&amf_hid); rnd_hid_load_defaults(&amf_hid, stl_attribute_list, NUM_OPTIONS); + + memcpy(&proj_hid, &stl_hid, sizeof(rnd_hid_t)); + proj_hid.name = "projector"; + proj_hid.description = "export board outline as a projector(1) object for 3d rendering"; + proj_hid.get_export_options = proj_get_export_options; + proj_hid.do_export = proj_do_export; + + rnd_hid_register_hid(&proj_hid); + rnd_hid_load_defaults(&proj_hid, stl_attribute_list, NUM_OPTIONS); + return 0; }