generate square slots

This commit is contained in:
Trammell Hudson 2015-02-15 16:57:37 -05:00
parent 07cf132687
commit 362f1bcc2e

View File

@ -14,42 +14,29 @@
#include "stl_3d.h" #include "stl_3d.h"
int static void
main(void) make_faces(
const stl_3d_t * const stl,
const stl_vertex_t * const v,
const double thickness,
const double inset_dist,
const double hole_dist,
const double hole_rad
)
{ {
stl_3d_t * const stl = stl_3d_parse(STDIN_FILENO); int * const face_used = calloc(sizeof(*face_used), stl->num_face);
if (!stl)
return EXIT_FAILURE;
const double thickness = 3;
const double inset_dist = 2;
const double hole_dist = 4;
const double hole_rad = 3.0/2;
const double hole_height = 40; const double hole_height = 40;
// for each vertex, find the coplanar triangles // generate all of the coplanar polygons at this vertex
// \todo: do coplanar bits
const stl_vertex_t ** const vertex_list = calloc(sizeof(**vertex_list), stl->num_vertex); const stl_vertex_t ** const vertex_list = calloc(sizeof(**vertex_list), stl->num_vertex);
for(int i = 0 ; i < stl->num_vertex ; i++)
{
const stl_vertex_t * const v = &stl->vertex[i];
const v3_t origin = v->p;
printf("// vertex %d\n"
"translate([%f,%f,%f])\n"
"render() difference()\n"
"{\n"
"sphere(r=15);\n",
i, origin.p[0], origin.p[1], origin.p[2]);
int * const face_used = calloc(sizeof(*face_used), stl->num_face);
for (int j = 0 ; j < v->num_face; j++) for (int j = 0 ; j < v->num_face; j++)
{ {
// generate the polygon face for this vertex // generate the polygon face for this vertex
const stl_face_t * const f = v->face[j]; const stl_face_t * const f = v->face[j];
if (face_used[f - stl->face]) if (face_used[f - stl->face])
continue; continue;
const int start_vertex = v->face_num[j]; const int start_vertex = v->face_num[j];
const int vertex_count = stl_trace_face( const int vertex_count = stl_trace_face(
stl, stl,
@ -100,6 +87,8 @@ main(void)
printf("\n]);\n"); printf("\n]);\n");
// generate the mounting holes // generate the mounting holes
if (hole_rad)
{
for(int k=0 ; k < vertex_count ; k++) for(int k=0 ; k < vertex_count ; k++)
{ {
double x, y; double x, y;
@ -108,20 +97,62 @@ main(void)
vertex_list[(k+1) % vertex_count]->p, vertex_list[(k+1) % vertex_count]->p,
vertex_list[(k+2) % vertex_count]->p vertex_list[(k+2) % vertex_count]->p
); );
printf("translate([%f,%f,0]) cylinder(r=%f,h=%f, center=true);\n", printf("translate([%f,%f,0]) cylinder(r=%f,h=%f, center=true, $fs=1);\n",
x, y, x, y,
hole_rad, hole_rad,
hole_height hole_height
); );
} }
}
printf("}\n"); printf("}\n");
} }
free(face_used); free(face_used);
free(vertex_list);
}
int
main(void)
{
stl_3d_t * const stl = stl_3d_parse(STDIN_FILENO);
if (!stl)
return EXIT_FAILURE;
const double thickness = 3;
const double inset_dist = 2;
const double hole_dist = 4;
const double hole_rad = 3.0/2;
const double hole_height = 40;
// for each vertex, find the coplanar triangles
// \todo: do coplanar bits
for(int i = 18 ; i < stl->num_vertex ; i++)
{
const stl_vertex_t * const v = &stl->vertex[i];
const v3_t origin = v->p;
printf("// vertex %d\n"
"//translate([%f,%f,%f])\n"
"render() difference()\n"
"{\n"
"//sphere(r=%f);\n",
i, origin.p[0], origin.p[1], origin.p[2], thickness/2);
printf("render() intersection() {\n");
printf("sphere(r=20);\nunion() {\n");
make_faces(stl, v, 2*thickness, -thickness/2, 0, 0);
printf("}\n");
printf("}\n");
make_faces(stl, v, thickness, inset_dist, hole_dist, hole_rad);
printf("}\n"); printf("}\n");
//if (i == 2) break; // only do one right now
break;
//if (i == 0) break; // only do one right now
} }
return 0; return 0;