117 char buffer[
LBUF], dummy[
LBUF], *pbuf;
122 fp = fopen(fname,
"r");
124 PRINT_MESG(
"JBXL::readSTLFileA: ERROR: File open Error! (%s)\n", fname);
128 fgets(buffer,
LBUF, fp);
131 while(*pbuf==
' '||*pbuf==
CHAR_TAB) pbuf++;
135 fgets(buffer,
LBUF, fp);
140 if (vno!=0 && vno==(*fno)*3) {
142 if (stldata!=NULL) memset(stldata, 0,
sizeof(
STLData)*(*fno));
151 fp = fopen(fname,
"r");
153 PRINT_MESG(
"JBXL::readSTLFileA: ERROR: File re-open Error! (%s)\n", fname);
157 fgets(buffer,
LBUF, fp);
160 while(*pbuf==
' '||*pbuf==
CHAR_TAB) pbuf++;
163 sscanf(buffer,
"%s %s %f %f %f", dummy, dummy, &vect[0], &vect[1], &vect[2]);
164 for (
int k=0; k<3; k++) stldata[i].vect[k] = vect[k];
167 else if (!
strncasecmp(pbuf,
"vertex ", 7) && j>=3 && j<12) {
168 sscanf(buffer,
"%s %f %f %f", dummy, &vect[0], &vect[1], &vect[2]);
169 for (
int k=0; k<3; k++) stldata[i].vect[j+k] = vect[k];
173 fgets(buffer,
LBUF, fp);
277 char message[80]=
"STL Binary Data Program by Fumi.Iseki";
280 fp = fopen(fname,
"wb");
282 PRINT_MESG(
"JBXL::writeSTLFileB: ERROR: Solid file open Error! (%s)\n", fname);
287 fwrite(message, 80, 1, fp);
288 fwrite(&fno, 4, 1, fp);
290 BREP_CONTOUR_LIST::iterator icon;
292 stldata.
vect[0] = (float)(*icon)->normal.x;
293 stldata.
vect[1] = (float)(*icon)->normal.y;
294 stldata.
vect[2] = (float)(*icon)->normal.z;
297 for (
int i=0; i<3; i++) {
299 stldata.
vect[3*i+3] = (float)vect.
x;
300 stldata.
vect[3*i+4] = (float)vect.
y;
301 stldata.
vect[3*i+5] = (float)vect.
z;
304 fwrite(&stldata, 50, 1, fp);
322 fp = fopen(fname,
"wa");
324 PRINT_MESG(
"JBXL::writeSTLFileA: ERROR: Solid list file open Error! (%s)\n", fname);
328 fprintf(fp,
"solid %s\n", fname);
330 BREP_SOLID_LIST::iterator isolid;
331 for (isolid=solid_list.begin(); isolid!=solid_list.end(); isolid++){
333 BREP_CONTOUR_LIST::iterator icon;
334 for (icon=(*isolid)->contours.begin(); icon!=(*isolid)->contours.end(); icon++){
335 fprintf(fp,
"facet normal %g %g %g\n", (*icon)->normal.x, (*icon)->normal.y, (*icon)->normal.z);
336 fprintf(fp,
" outer loop\n");
339 for (
int i=0; i<3; i++) {
341 fprintf(fp,
" vertex %g %g %g\n", vect.
x, vect.
y, vect.
z);
344 fprintf(fp,
" endloop\n");
345 fprintf(fp,
"endfacet\n");
349 fprintf(fp,
"endsolid %s\n", fname);
365 char message[80]=
"STL Binary Data Program by Fumi.Iseki";
368 fp = fopen(fname,
"wb");
370 PRINT_MESG(
"JBXL::writeSTLFileB: ERROR: Solid list file open Error! (%s)\n", fname);
374 BREP_SOLID_LIST::iterator isolid;
375 for (isolid=solid_list.begin(); isolid!=solid_list.end(); isolid++){
376 fno += (int)((*isolid)->contours.size());
378 fwrite(message, 80, 1, fp);
379 fwrite(&fno, 4, 1, fp);
382 for (isolid=solid_list.begin(); isolid!=solid_list.end(); isolid++){
384 BREP_CONTOUR_LIST::iterator icon;
385 for (icon=(*isolid)->contours.begin(); icon!=(*isolid)->contours.end(); icon++){
386 stldata.
vect[0] = (float)(*icon)->normal.x;
387 stldata.
vect[1] = (float)(*icon)->normal.y;
388 stldata.
vect[2] = (float)(*icon)->normal.z;
391 for (
int i=0; i<3; i++) {
393 stldata.
vect[3*i+3] = (float)vect.
x;
394 stldata.
vect[3*i+4] = (float)vect.
y;
395 stldata.
vect[3*i+5] = (float)vect.
z;
398 fwrite(&stldata, 50, 1, fp);