1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Convert MGF to Inventor file. |
6 |
|
* |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
|
|
12 |
+ |
#include <stdlib.h> |
13 |
+ |
|
14 |
|
#include <math.h> |
15 |
|
|
16 |
+ |
#include <ctype.h> |
17 |
+ |
|
18 |
+ |
#include <string.h> |
19 |
+ |
|
20 |
|
#include "parser.h" |
21 |
|
|
22 |
|
#include "lookup.h" |
23 |
|
|
24 |
< |
#ifndef PI |
25 |
< |
#define PI 3.14159265358979323846 |
26 |
< |
#endif |
24 |
> |
#define O_INV1 1 /* Inventor 1.0 output */ |
25 |
> |
#define O_INV2 2 /* Inventor 2.0 output */ |
26 |
> |
#define O_VRML1 3 /* VRML 1.0 output */ |
27 |
|
|
28 |
+ |
#define MAXID 48 /* maximum identifier length */ |
29 |
+ |
|
30 |
+ |
#define VERTFMT "%+16.9e %+16.9e %+16.9e\n%+6.3f %+6.3f %+6.3f" |
31 |
+ |
#define VZVECT "+0.000 +0.000 +0.000" |
32 |
+ |
#define VFSEPPOS 50 /* position of newline in above */ |
33 |
+ |
#define VFLEN 72 /* total vertex string length */ |
34 |
+ |
#define MAXVERT 10240 /* maximum cached vertices */ |
35 |
+ |
|
36 |
+ |
#define setvkey(k,v) sprintf(k,VERTFMT,(v)->p[0],(v)->p[1],(v)->p[2],\ |
37 |
+ |
(v)->n[0],(v)->n[1],(v)->n[2]); |
38 |
+ |
|
39 |
+ |
char vlist[MAXVERT][VFLEN]; /* our vertex cache */ |
40 |
+ |
int nverts; /* current cache size */ |
41 |
+ |
|
42 |
+ |
LUTAB vert_tab = LU_SINIT(NULL,NULL); |
43 |
+ |
|
44 |
+ |
struct face { |
45 |
+ |
struct face *next; /* next face in list */ |
46 |
+ |
short nv; /* number of vertices */ |
47 |
+ |
short vl[3]; /* vertex index list (variable) */ |
48 |
+ |
} *flist, *flast; /* our face cache */ |
49 |
+ |
|
50 |
+ |
#define newface(n) (struct face *)malloc(sizeof(struct face) + \ |
51 |
+ |
((n) > 3 ? (n)-3 : 0)*sizeof(short)) |
52 |
+ |
#define freeface(f) free((MEM_PTR)f) |
53 |
+ |
|
54 |
|
#define TABSTOP 8 /* assumed number of characters per tab */ |
55 |
|
#define SHIFTW 2 /* nesting shift width */ |
56 |
|
#define MAXIND 15 /* maximum indent level */ |
57 |
|
|
58 |
< |
extern int i_comment(), i_object(), i_xf(), i_include(), |
30 |
< |
i_cyl(), i_face(), i_sph(); |
58 |
> |
char tabs[MAXIND*SHIFTW+1]; /* current tab-in string */ |
59 |
|
|
60 |
< |
int vrmlout = 0; /* VRML output desired? */ |
60 |
> |
#define curmatname (c_cmname == NULL ? "mat" : to_id(c_cmname)) |
61 |
|
|
62 |
< |
int instancing = 0; /* are we in an instance? */ |
62 |
> |
int outtype = O_INV2; /* output format */ |
63 |
|
|
64 |
< |
char tabs[MAXIND*SHIFTW+1]; /* current tab-in string */ |
64 |
> |
extern int i_comment(), i_object(), i_xf(), |
65 |
> |
i_cyl(), i_face(), i_sph(); |
66 |
|
|
67 |
+ |
extern char *to_id(); |
68 |
|
|
69 |
+ |
|
70 |
|
main(argc, argv) |
71 |
|
int argc; |
72 |
|
char *argv[]; |
94 |
|
mg_ehand[MG_E_TS] = c_hmaterial; /* they get specular trans. */ |
95 |
|
mg_ehand[MG_E_VERTEX] = c_hvertex; /* they get vertices */ |
96 |
|
mg_ehand[MG_E_XF] = i_xf; /* we track transforms */ |
66 |
– |
mg_ehand[MG_E_INCLUDE] = i_include; /* we include files */ |
97 |
|
mg_init(); /* initialize the parser */ |
98 |
< |
i = 1; /* get options and print format line */ |
99 |
< |
if (i < argc && !strncmp(argv[i], "-vrml", strlen(argv[i]))) { |
100 |
< |
printf("#VRML 1.0 ascii\n"); |
101 |
< |
vrmlout++; |
102 |
< |
i++; |
103 |
< |
} else |
98 |
> |
/* get options and print format line */ |
99 |
> |
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
100 |
> |
if (!strcmp(argv[i], "-vrml")) |
101 |
> |
outtype = O_VRML1; |
102 |
> |
else if (!strcmp(argv[i], "-1")) |
103 |
> |
outtype = O_INV1; |
104 |
> |
else if (!strcmp(argv[i], "-2")) |
105 |
> |
outtype = O_INV2; |
106 |
> |
else |
107 |
> |
goto userr; |
108 |
> |
switch (outtype) { |
109 |
> |
case O_INV1: |
110 |
> |
printf("#Inventor V1.0 ascii\n"); |
111 |
> |
break; |
112 |
> |
case O_INV2: |
113 |
|
printf("#Inventor V2.0 ascii\n"); |
114 |
+ |
break; |
115 |
+ |
case O_VRML1: |
116 |
+ |
printf("#VRML V1.0 ascii\n"); |
117 |
+ |
break; |
118 |
+ |
} |
119 |
|
printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR); |
120 |
|
printf("Separator {\n"); /* begin root node */ |
121 |
|
/* general properties */ |
122 |
|
printf("MaterialBinding { value OVERALL }\n"); |
123 |
< |
printf("NormalBinding { value PER_VERTEX }\n"); |
124 |
< |
printf("ShapeHints {\n"); |
125 |
< |
printf("\tvertexOrdering CLOCKWISE\n"); |
126 |
< |
printf("\tfaceType UNKNOWN_FACE_TYPE\n"); |
127 |
< |
printf("}\n"); |
123 |
> |
printf("NormalBinding { value PER_VERTEX_INDEXED }\n"); |
124 |
> |
if (outtype != O_INV1) { |
125 |
> |
printf("ShapeHints {\n"); |
126 |
> |
printf("\tvertexOrdering CLOCKWISE\n"); |
127 |
> |
printf("\tfaceType UNKNOWN_FACE_TYPE\n"); |
128 |
> |
printf("}\n"); |
129 |
> |
} |
130 |
|
if (i == argc) { /* load standard input */ |
131 |
|
if (mg_load(NULL) != MG_OK) |
132 |
|
exit(1); |
145 |
|
printf("## %s %s: %u unknown entities\n", |
146 |
|
argv[0], argv[i], mg_nunknown); |
147 |
|
} |
148 |
< |
printf("}\n"); /* close root node */ |
148 |
> |
flush_cache(); /* flush face cache, just in case */ |
149 |
> |
printf("}\n"); /* close root node */ |
150 |
|
exit(0); |
151 |
+ |
userr: |
152 |
+ |
fprintf(stderr, "%s: [-1|-2|-vrml] [file] ..\n", argv[0]); |
153 |
+ |
exit(1); |
154 |
|
} |
155 |
|
|
156 |
|
|
179 |
|
int ac; |
180 |
|
char **av; |
181 |
|
{ |
132 |
– |
if (instancing) |
133 |
– |
return(MG_OK); |
182 |
|
fputs(tabs, stdout); |
183 |
|
putchar('#'); /* Inventor comment character */ |
184 |
|
while (--ac > 0) { |
197 |
|
{ |
198 |
|
static int objnest; |
199 |
|
|
200 |
< |
if (instancing) |
153 |
< |
return(MG_OK); |
200 |
> |
flush_cache(); /* flush cached objects */ |
201 |
|
if (ac == 2) { /* start group */ |
202 |
< |
printf("%sDEF %s Group {\n", tabs, av[1]); |
202 |
> |
printf("%sDEF %s Group {\n", tabs, to_id(av[1])); |
203 |
|
indent(1); |
204 |
|
objnest++; |
205 |
|
return(MG_OK); |
224 |
|
static long xfid; |
225 |
|
register XF_SPEC *spec; |
226 |
|
|
227 |
< |
if (instancing) |
181 |
< |
return(MG_OK); |
227 |
> |
flush_cache(); /* flush cached objects */ |
228 |
|
if (ac == 1) { /* end of transform */ |
229 |
|
if ((spec = xf_context) == NULL) |
230 |
|
return(MG_ECNTXT); |
316 |
|
|
317 |
|
|
318 |
|
int |
273 |
– |
i_include(ac, av) /* include an MGF file */ |
274 |
– |
int ac; |
275 |
– |
char **av; |
276 |
– |
{ |
277 |
– |
static LUTAB in_tab = LU_SINIT(free,free); /* instance table */ |
278 |
– |
static long nincl; |
279 |
– |
LUENT *lp; |
280 |
– |
char *xfarg[MG_MAXARGC]; |
281 |
– |
MG_FCTXT ictx; |
282 |
– |
register int i; |
283 |
– |
|
284 |
– |
if (ac < 2) |
285 |
– |
return(MG_EARGC); |
286 |
– |
if (ac > 2) { /* start transform if one */ |
287 |
– |
xfarg[0] = mg_ename[MG_E_XF]; |
288 |
– |
for (i = 1; i < ac-1; i++) |
289 |
– |
xfarg[i] = av[i+1]; |
290 |
– |
xfarg[ac-1] = NULL; |
291 |
– |
if ((i = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) |
292 |
– |
return(i); |
293 |
– |
} |
294 |
– |
/* open include file */ |
295 |
– |
if ((i = mg_open(&ictx, av[1])) != MG_OK) |
296 |
– |
return(i); |
297 |
– |
/* check for instance */ |
298 |
– |
lp = lu_find(&in_tab, ictx.fname); |
299 |
– |
if (lp == NULL) goto memerr; |
300 |
– |
if (lp->data != NULL) { /* reference original */ |
301 |
– |
instancing++; |
302 |
– |
printf("%sUSE %s\n", tabs, lp->data); |
303 |
– |
lp = NULL; |
304 |
– |
} else { /* else new original */ |
305 |
– |
lp->key = (char *)malloc(strlen(ictx.fname)+1); |
306 |
– |
if (lp->key == NULL) goto memerr; |
307 |
– |
(void)strcpy(lp->key, ictx.fname); |
308 |
– |
if (ac > 2) { /* use transform group */ |
309 |
– |
lp->data = (char *)malloc(16); |
310 |
– |
if (lp->data == NULL) goto memerr; |
311 |
– |
sprintf(lp->data, "_xf%ld", xf_context->xid); |
312 |
– |
} else { /* else make our own group */ |
313 |
– |
lp->data = (char *)malloc(strlen(av[1])+16); |
314 |
– |
if (lp->data == NULL) goto memerr; |
315 |
– |
sprintf(lp->data, "_%s%ld", av[1], ++nincl); |
316 |
– |
printf("%sDEF %s Group {\n", tabs, lp->data); |
317 |
– |
indent(1); |
318 |
– |
} |
319 |
– |
} |
320 |
– |
while ((i = mg_read()) > 0) { /* load include file */ |
321 |
– |
if (i >= MG_MAXLINE-1) { |
322 |
– |
fprintf(stderr, "%s: %d: %s\n", ictx.fname, |
323 |
– |
ictx.lineno, mg_err[MG_ELINE]); |
324 |
– |
mg_close(); |
325 |
– |
return(MG_EINCL); |
326 |
– |
} |
327 |
– |
if ((i = mg_parse()) != MG_OK) { |
328 |
– |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
329 |
– |
ictx.lineno, mg_err[i], |
330 |
– |
ictx.inpline); |
331 |
– |
mg_close(); |
332 |
– |
return(MG_EINCL); |
333 |
– |
} |
334 |
– |
} |
335 |
– |
if (lp == NULL) /* end instance? */ |
336 |
– |
instancing--; |
337 |
– |
else if (ac <= 2) { /* else end group? */ |
338 |
– |
indent(0); |
339 |
– |
printf("%s}\n", tabs); |
340 |
– |
} |
341 |
– |
mg_close(); /* close and end transform */ |
342 |
– |
if (ac > 2 && (i = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) |
343 |
– |
return(i); |
344 |
– |
return(MG_OK); |
345 |
– |
memerr: |
346 |
– |
mg_close(); |
347 |
– |
return(MG_EMEM); |
348 |
– |
} |
349 |
– |
|
350 |
– |
|
351 |
– |
int |
319 |
|
put_material() /* put out current material */ |
320 |
|
{ |
321 |
< |
char *mname = "mat"; |
321 |
> |
char *mname = curmatname; |
322 |
|
float rgbval[3]; |
323 |
|
|
357 |
– |
if (c_cmname != NULL) |
358 |
– |
mname = c_cmname; |
324 |
|
if (!c_cmaterial->clock) { /* current, just use it */ |
325 |
|
printf("%sUSE %s\n", tabs, mname); |
326 |
|
return(0); |
331 |
|
printf("%sMaterial {\n", tabs); |
332 |
|
indent(1); |
333 |
|
mgf2rgb(&c_cmaterial->rd_c, c_cmaterial->rd, rgbval); |
334 |
< |
printf("%sambientcolor %.4f %.4f %.4f\n", tabs, |
334 |
> |
printf("%sambientColor %.4f %.4f %.4f\n", tabs, |
335 |
|
rgbval[0], rgbval[1], rgbval[2]); |
336 |
< |
printf("%sdiffusecolor %.4f %.4f %.4f\n", tabs, |
336 |
> |
printf("%sdiffuseColor %.4f %.4f %.4f\n", tabs, |
337 |
|
rgbval[0], rgbval[1], rgbval[2]); |
338 |
|
if (c_cmaterial->rs > FTINY) { |
339 |
|
mgf2rgb(&c_cmaterial->rs_c, c_cmaterial->rs, rgbval); |
340 |
< |
printf("%sspecularcolor %.4f %.4f %.4f\n", tabs, |
340 |
> |
printf("%sspecularColor %.4f %.4f %.4f\n", tabs, |
341 |
|
rgbval[0], rgbval[1], rgbval[2]); |
342 |
< |
printf("%sshininess %.3f\n", tabs, 1.-c_cmaterial->rs_a); |
342 |
> |
printf("%sshininess %.3f\n", tabs, 1.-sqrt(c_cmaterial->rs_a)); |
343 |
|
} |
344 |
|
if (c_cmaterial->ed > FTINY) { |
345 |
|
mgf2rgb(&c_cmaterial->ed_c, 1.0, rgbval); |
351 |
|
c_cmaterial->ts + c_cmaterial->td); |
352 |
|
indent(0); |
353 |
|
printf("%s}\n", tabs); |
354 |
< |
printf("%sShapeHints { shapeType %s }\n", tabs, |
354 |
> |
if (outtype != O_INV1) |
355 |
> |
printf("%sShapeHints { shapeType %s }\n", tabs, |
356 |
|
c_cmaterial->sided ? "SOLID" : "UNKNOWN_SHAPE_TYPE"); |
357 |
|
indent(0); |
358 |
|
printf("%s}\n", tabs); |
366 |
|
int ac; |
367 |
|
char **av; |
368 |
|
{ |
369 |
< |
C_VERTEX *vl[MG_MAXARGC-1]; |
370 |
< |
int donorms = 1; |
369 |
> |
static char lastmat[MAXID]; |
370 |
> |
struct face *newf; |
371 |
> |
register C_VERTEX *vp; |
372 |
> |
register LUENT *lp; |
373 |
|
register int i; |
374 |
|
|
407 |
– |
if (instancing) |
408 |
– |
return(MG_OK); |
375 |
|
if (ac < 4) |
376 |
|
return(MG_EARGC); |
377 |
< |
printf("%sSeparator {\n", tabs); |
378 |
< |
indent(1); |
379 |
< |
/* put out current material */ |
380 |
< |
if (put_material() < 0) |
381 |
< |
return(MG_EBADMAT); |
377 |
> |
if ( strcmp(lastmat, curmatname) || c_cmaterial->clock || |
378 |
> |
nverts == 0 || nverts+ac-1 >= MAXVERT) { |
379 |
> |
flush_cache(); /* new cache */ |
380 |
> |
lu_init(&vert_tab, MAXVERT); |
381 |
> |
printf("%sSeparator {\n", tabs); |
382 |
> |
indent(1); |
383 |
> |
if (put_material() < 0) /* put out material */ |
384 |
> |
return(MG_EBADMAT); |
385 |
> |
(void)strcpy(lastmat, curmatname); |
386 |
> |
} |
387 |
> |
/* allocate new face */ |
388 |
> |
if ((newf = newface(ac-1)) == NULL) |
389 |
> |
return(MG_EMEM); |
390 |
> |
newf->nv = ac-1; |
391 |
|
/* get vertex references */ |
392 |
< |
for (i = 0; i < ac-1; i++) { |
393 |
< |
if ((vl[i] = c_getvert(av[i+1])) == NULL) |
392 |
> |
for (i = 0; i < newf->nv; i++) { |
393 |
> |
if ((vp = c_getvert(av[i+1])) == NULL) |
394 |
|
return(MG_EUNDEF); |
395 |
< |
if (is0vect(vl[i]->n)) |
396 |
< |
donorms = 0; |
395 |
> |
setvkey(vlist[nverts], vp); |
396 |
> |
lp = lu_find(&vert_tab, vlist[nverts]); |
397 |
> |
if (lp == NULL) |
398 |
> |
return(MG_EMEM); |
399 |
> |
if (lp->key == NULL) |
400 |
> |
lp->key = (char *)vlist[nverts++]; |
401 |
> |
newf->vl[i] = ((char (*)[VFLEN])lp->key - vlist); |
402 |
|
} |
403 |
< |
/* put out vertex coordinates */ |
404 |
< |
printf("%sCoordinate3 {\n", tabs); |
405 |
< |
indent(1); |
406 |
< |
printf("%spoint [ %13.9g %13.9g %13.9g", tabs, |
407 |
< |
vl[0]->p[0], vl[0]->p[1], vl[0]->p[2]); |
408 |
< |
for (i = 1; i < ac-1; i++) |
409 |
< |
printf(",\n%s %13.9g %13.9g %13.9g", tabs, |
410 |
< |
vl[i]->p[0], vl[i]->p[1], vl[i]->p[2]); |
431 |
< |
indent(0); |
432 |
< |
printf(" ]\n%s}\n", tabs); |
433 |
< |
/* put out normal coordinates */ |
434 |
< |
if (donorms) { |
435 |
< |
printf("%sNormal {\n", tabs); |
436 |
< |
indent(1); |
437 |
< |
printf("%svector [ %13.9g %13.9g %13.9g", tabs, |
438 |
< |
vl[0]->n[0], vl[0]->p[1], vl[0]->p[2]); |
439 |
< |
for (i = 1; i < ac-1; i++) |
440 |
< |
printf(",\n%s %13.9g %13.9g %13.9g", tabs, |
441 |
< |
vl[i]->n[0], vl[i]->n[1], vl[i]->n[2]); |
442 |
< |
indent(0); |
443 |
< |
printf(" ]\n%s}\n", tabs); |
444 |
< |
} else |
445 |
< |
printf("%sNormal { }\n", tabs); |
446 |
< |
/* put out actual face */ |
447 |
< |
printf("%sIndexedFaceSet {\n", tabs); |
448 |
< |
indent(1); |
449 |
< |
printf("%scoordIndex [", tabs); |
450 |
< |
for (i = 0; i < ac-1; i++) |
451 |
< |
printf(" %d", i); |
452 |
< |
printf(" ]\n"); |
453 |
< |
indent(0); |
454 |
< |
printf("%s}\n", tabs); |
455 |
< |
indent(0); |
456 |
< |
printf("%s}\n", tabs); |
457 |
< |
return(MG_OK); |
403 |
> |
/* add to face list */ |
404 |
> |
newf->next = NULL; |
405 |
> |
if (flist == NULL) |
406 |
> |
flist = newf; |
407 |
> |
else |
408 |
> |
flast->next = newf; |
409 |
> |
flast = newf; |
410 |
> |
return(MG_OK); /* we'll actually put it out later */ |
411 |
|
} |
412 |
|
|
413 |
|
|
418 |
|
{ |
419 |
|
register C_VERTEX *cent; |
420 |
|
|
468 |
– |
if (instancing) |
469 |
– |
return(MG_OK); |
421 |
|
if (ac != 3) |
422 |
|
return(MG_EARGC); |
423 |
+ |
flush_cache(); /* flush vertex cache */ |
424 |
|
printf("%sSeparator {\n", tabs); |
425 |
|
indent(1); |
426 |
|
/* put out current material */ |
450 |
|
FVECT va; |
451 |
|
double length, angle; |
452 |
|
|
501 |
– |
if (instancing) |
502 |
– |
return(MG_OK); |
453 |
|
if (ac != 4) |
454 |
|
return(MG_EARGC); |
455 |
+ |
flush_cache(); /* flush vertex cache */ |
456 |
|
printf("%sSeparator {\n", tabs); |
457 |
|
indent(1); |
458 |
|
/* put out current material */ |
469 |
|
va[1] = v2->p[1] - v1->p[1]; |
470 |
|
va[2] = v2->p[2] - v1->p[2]; |
471 |
|
length = sqrt(DOT(va,va)); |
472 |
< |
angle = 180./PI * acos(va[1]/length); |
473 |
< |
printf("%sRotation { rotation %.9g %.9g %.9g %.9g }\n", tabs, |
474 |
< |
va[2], 0., -va[0], angle); |
472 |
> |
if (va[1] >= length) |
473 |
> |
angle = 0.; |
474 |
> |
else if (va[1] <= -length) |
475 |
> |
angle = PI; |
476 |
> |
else |
477 |
> |
angle = acos(va[1]/length); |
478 |
|
printf("%sTranslation { translation %13.9g %13.9g %13.9g }\n", tabs, |
479 |
|
.5*(v1->p[0]+v2->p[0]), .5*(v1->p[1]+v2->p[1]), |
480 |
|
.5*(v1->p[2]+v2->p[2])); |
481 |
+ |
printf("%sRotation { rotation %.9g %.9g %.9g %.9g }\n", tabs, |
482 |
+ |
va[2], 0., -va[0], angle); |
483 |
|
/* open-ended */ |
484 |
|
printf("%sCylinder { parts SIDES height %13.9g radius %s }\n", tabs, |
485 |
|
length, av[2]); |
486 |
|
indent(0); |
487 |
|
printf("%s}\n", tabs); |
488 |
|
return(MG_OK); |
489 |
+ |
} |
490 |
+ |
|
491 |
+ |
|
492 |
+ |
char * |
493 |
+ |
to_id(name) /* make sure a name is a valid Inventor ID */ |
494 |
+ |
register char *name; |
495 |
+ |
{ |
496 |
+ |
static char id[MAXID]; |
497 |
+ |
register char *cp; |
498 |
+ |
|
499 |
+ |
for (cp = id; *name && cp < MAXID-1+id; name++) |
500 |
+ |
if (isalnum(*name) || *name == '_') |
501 |
+ |
*cp++ = *name; |
502 |
+ |
else |
503 |
+ |
*cp++ = '_'; |
504 |
+ |
*cp = '\0'; |
505 |
+ |
return(id); |
506 |
+ |
} |
507 |
+ |
|
508 |
+ |
|
509 |
+ |
flush_cache() /* put out cached faces */ |
510 |
+ |
{ |
511 |
+ |
int donorms = 0; |
512 |
+ |
register struct face *f; |
513 |
+ |
register int i; |
514 |
+ |
|
515 |
+ |
if (nverts == 0) |
516 |
+ |
return; |
517 |
+ |
/* put out coordinates */ |
518 |
+ |
printf("%sCoordinate3 {\n", tabs); |
519 |
+ |
indent(1); |
520 |
+ |
vlist[0][VFSEPPOS] = '\0'; |
521 |
+ |
printf("%spoint [ %s", tabs, vlist[0]); |
522 |
+ |
for (i = 1; i < nverts; i++) { |
523 |
+ |
vlist[i][VFSEPPOS] = '\0'; |
524 |
+ |
printf(",\n%s %s", tabs, vlist[i]); |
525 |
+ |
if (strcmp(VFSEPPOS+1+vlist[i], VZVECT)) |
526 |
+ |
donorms++; |
527 |
+ |
} |
528 |
+ |
indent(0); |
529 |
+ |
printf(" ]\n%s}\n", tabs); |
530 |
+ |
if (donorms) { /* put out normals */ |
531 |
+ |
printf("%sNormal {\n", tabs); |
532 |
+ |
indent(1); |
533 |
+ |
printf("%svector [ %s", tabs, VFSEPPOS+1+vlist[0]); |
534 |
+ |
for (i = 1; i < nverts; i++) |
535 |
+ |
printf(",\n%s %s", tabs, VFSEPPOS+1+vlist[i]); |
536 |
+ |
indent(0); |
537 |
+ |
printf(" ]\n%s}\n", tabs); |
538 |
+ |
} |
539 |
+ |
/* put out faces */ |
540 |
+ |
printf("%sIndexedFaceSet {\n", tabs); |
541 |
+ |
indent(1); |
542 |
+ |
f = flist; /* coordinate indices */ |
543 |
+ |
printf("%scoordIndex [ %d", tabs, f->vl[0]); |
544 |
+ |
for (i = 1; i < f->nv; i++) |
545 |
+ |
printf(", %d", f->vl[i]); |
546 |
+ |
for (f = f->next; f != NULL; f = f->next) { |
547 |
+ |
printf(", -1,\n%s %d", tabs, f->vl[0]); |
548 |
+ |
for (i = 1; i < f->nv; i++) |
549 |
+ |
printf(", %d", f->vl[i]); |
550 |
+ |
} |
551 |
+ |
printf(" ]\n"); |
552 |
+ |
if (donorms) { |
553 |
+ |
f = flist; /* normal indices */ |
554 |
+ |
printf("%snormalIndex [ %d", tabs, f->vl[0]); |
555 |
+ |
for (i = 1; i < f->nv; i++) |
556 |
+ |
printf(", %d", f->vl[i]); |
557 |
+ |
for (f = f->next; f != NULL; f = f->next) { |
558 |
+ |
printf(", -1,\n%s %d", tabs, f->vl[0]); |
559 |
+ |
for (i = 1; i < f->nv; i++) |
560 |
+ |
printf(", %d", f->vl[i]); |
561 |
+ |
} |
562 |
+ |
printf(" ]\n"); |
563 |
+ |
} |
564 |
+ |
indent(0); /* close IndexedFaceSet */ |
565 |
+ |
printf("%s}\n", tabs); |
566 |
+ |
indent(0); /* close face group */ |
567 |
+ |
printf("%s}\n", tabs); |
568 |
+ |
while ((f = flist) != NULL) { /* free face list */ |
569 |
+ |
flist = f->next; |
570 |
+ |
freeface(f); |
571 |
+ |
} |
572 |
+ |
lu_done(&vert_tab); /* clear lookup table */ |
573 |
+ |
nverts = 0; |
574 |
|
} |