Index: trunk/src/Makefile.dep =================================================================== --- trunk/src/Makefile.dep (revision 35968) +++ trunk/src/Makefile.dep (revision 35969) @@ -704,7 +704,8 @@ ../src_plugins/export_stl/exp_fmt_amf.c \ ../src_plugins/export_stl/stl_models.c \ ../src_plugins/export_stl/model_load_stl.c \ - ../src_plugins/export_stl/model_load_amf.c + ../src_plugins/export_stl/model_load_amf.c \ + ../src_plugins/export_stl/verthash.c ../src_plugins/export_svg/svg.o: ../src_plugins/export_svg/svg.c \ ../config.h conf_core.h globalconst.h board.h vtroutestyle.h attrib.h \ global_typedefs.h layer.h obj_common.h flag.h data_parent.h \ Index: trunk/src_plugins/export_stl/export_stl.c =================================================================== --- trunk/src_plugins/export_stl/export_stl.c (revision 35968) +++ trunk/src_plugins/export_stl/export_stl.c (revision 35969) @@ -342,6 +342,10 @@ }; RND_INLINE void v_transform(double dst[3], double src[3], double mx[16]); +#include "verthash.c" + +static verthash_t verthash; + #include "exp_fmt_stl.c" #include "exp_fmt_amf.c" #include "stl_models.c" Index: trunk/src_plugins/export_stl/verthash.c =================================================================== --- trunk/src_plugins/export_stl/verthash.c (nonexistent) +++ trunk/src_plugins/export_stl/verthash.c (revision 35969) @@ -0,0 +1,76 @@ +#include + +typedef struct { + rnd_coord_t x, y, z; +} vertex_t; + +typedef vertex_t htvx_key_t; +typedef long int htvx_value_t; +#define HT(x) htvx_ ## x +#include +#include +#undef HT + + +typedef struct { + htvx_t vxhash; + vtl0_t triangles; + long next_id; +} verthash_t; + + +unsigned vxkeyhash(vertex_t key) +{ + return key.x ^ key.y ^ key.z; +} + +int vxkeyeq(const vertex_t a, const vertex_t b) +{ + return (a.x == b.x) && (a.y == b.y) && (a.z == b.z); +} + +static void verthash_init(verthash_t *vh) +{ + htvx_init(&vh->vxhash, vxkeyhash, vxkeyeq); + vtl0_init(&vh->triangles); + vh->next_id = 0; +} + +static void verthash_uninit(verthash_t *vh) +{ + vtl0_uninit(&vh->triangles); + htvx_uninit(&vh->vxhash); +} + +static long verthash_add_vertex(verthash_t *vh, rnd_coord_t x, rnd_coord_t y, rnd_coord_t z) +{ + long id; + vertex_t vx; + htvx_entry_t *e; + + vx.x = x; vx.y = y; vx.z = z; + e = htvx_getentry(&vh->vxhash, vx); + if (e != 0) + return e->value; + + id = vh->next_id; + vh->next_id++; + htvx_set(&vh->vxhash, vx, id); + return id; +} + +static void verthash_add_triangle(verthash_t *vh, long v1, long v2, long v3) +{ + vtl0_append(&vh->triangles, v1); + vtl0_append(&vh->triangles, v2); + vtl0_append(&vh->triangles, v3); +} + +static void verthash_add_triangle_coord(verthash_t *vh, rnd_coord_t x1, rnd_coord_t y1, rnd_coord_t z1, rnd_coord_t x2, rnd_coord_t y2, rnd_coord_t z2, rnd_coord_t x3, rnd_coord_t y3, rnd_coord_t z3) +{ + long v1, v2, v3; + v1 = verthash_add_vertex(vh, x1, y1, z1); + v2 = verthash_add_vertex(vh, x2, y2, z2); + v3 = verthash_add_vertex(vh, x3, y3, z3); + verthash_add_triangle(vh, v1, v2, v3); +}