4 Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr 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 simavr 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 simavr. If not, see <http://www.gnu.org/licenses/>.
23 #include "c3/c3algebra.h"
24 #include "c3/c3geometry.h"
25 #include "c3/c3object.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;
72 fgets(line, sizeof(line), f);
75 while (l && line[l-1] < ' ')
79 char * keyword = line;
80 while (*keyword && *keyword <= ' ')
83 // printf("%d>'%s'\n", state, keyword);
87 if (!strncmp(keyword, "solid ", 6)) {
88 char * n = keyword + 6;
89 current_g = c3geometry_new(c3geometry_type(C3_TRIANGLE_TYPE, 0), o);
90 current_g->name = str_new(n);
96 if (!strncmp(keyword, "facet ", 6)) {
98 _c3stl_read_vertex(keyword + 6, &normal);
99 c3vertex_array_add(¤t_g->normals, normal);
100 c3vertex_array_add(¤t_g->normals, normal);
101 c3vertex_array_add(¤t_g->normals, normal);
103 } else if (!strncmp(keyword, "endsolid ", 9))
107 if (!strncmp(keyword, "outer loop", 10))
109 else if (!strncmp(keyword, "endfacet", 8))
113 if (!strncmp(keyword, "vertex ", 7)) {
115 _c3stl_read_vertex(keyword, &v);
116 c3vertex_array_add(¤t_g->vertice, v);
118 } else if (!strncmp(keyword, "endloop", 7))