4 Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
6 This file is part of libc3.
8 libc3 is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 libc3 is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with libc3. If not, see <http://www.gnu.org/licenses/>.
23 #include "c3algebra.h"
24 #include "c3geometry.h"
41 /*char * key =*/ strsep(&l, " \t");
42 char * x = strsep(&l, " \t");
43 char * y = strsep(&l, " \t");
44 char * z = strsep(&l, " \t");
46 if (x) sscanf(x, "%f", out->n);
47 if (y) sscanf(y, "%f", out->n + 1);
48 if (z) sscanf(z, "%f", out->n + 2);
49 // printf("'%s' '%s' '%s' '%s' = %.2f %.2f %.2f\n",
50 // key, x, y, z, out->n[0], out->n[1], out->n[2]);
56 const char * filename,
59 FILE *f = fopen(filename, "r");
65 c3object_p o = c3object_new(parent);
66 c3geometry_p current_g = NULL;
67 o->name = str_new(filename);
73 fgets(line, sizeof(line), f);
76 while (l && line[l-1] < ' ')
80 char * keyword = line;
81 while (*keyword && *keyword <= ' ')
84 // printf("%d>'%s'\n", state, keyword);
88 if (!strncmp(keyword, "solid ", 6)) {
89 char * n = keyword + 6;
90 current_g = c3geometry_new(c3geometry_type(C3_TRIANGLE_TYPE, 0), o);
91 current_g->name = str_new(n);
97 if (!strncmp(keyword, "facet ", 6)) {
99 _c3stl_read_vertex(keyword + 6, &normal);
100 normal = c3vec3_normalize(normal);
101 c3vertex_array_add(¤t_g->normals, normal);
102 c3vertex_array_add(¤t_g->normals, normal);
103 c3vertex_array_add(¤t_g->normals, normal);
105 } else if (!strncmp(keyword, "endsolid ", 9))
109 if (!strncmp(keyword, "outer loop", 10))
111 else if (!strncmp(keyword, "endfacet", 8))
115 if (!strncmp(keyword, "vertex ", 7)) {
117 _c3stl_read_vertex(keyword, &v);
118 c3vertex_array_add(¤t_g->vertice, v);
120 } else if (!strncmp(keyword, "endloop", 7))