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 |
|
#define O_INV1 1 /* Inventor 1.0 output */ |
25 |
|
#define O_INV2 2 /* Inventor 2.0 output */ |
26 |
< |
#define O_VRML 3 /* VRML output */ |
26 |
> |
#define O_VRML1 3 /* VRML 1.0 output */ |
27 |
|
|
28 |
|
#define MAXID 48 /* maximum identifier length */ |
29 |
|
|
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) |
52 |
> |
#define freeface(f) free(f) |
53 |
|
|
54 |
|
#define TABSTOP 8 /* assumed number of characters per tab */ |
55 |
|
#define SHIFTW 2 /* nesting shift width */ |
61 |
|
|
62 |
|
int outtype = O_INV2; /* output format */ |
63 |
|
|
64 |
< |
extern int i_comment(), i_object(), i_xf(), |
65 |
< |
i_cyl(), i_face(), i_sph(); |
64 |
> |
int i_comment(int ac, char **av); |
65 |
> |
int i_object(int ac, char **av); |
66 |
> |
int i_xf(int ac, char **av); |
67 |
> |
int put_xform(register XF_SPEC *spec); |
68 |
> |
int put_material(void); |
69 |
> |
int i_face(int ac, char **av); |
70 |
> |
int i_sph(int ac, char **av); |
71 |
> |
int i_cyl(int ac, char **av); |
72 |
> |
char * to_id(register char *name); |
73 |
> |
char * to_id(register char *name); |
74 |
> |
void flush_cache(void); |
75 |
|
|
66 |
– |
extern char *to_id(); |
76 |
|
|
77 |
< |
|
78 |
< |
main(argc, argv) |
79 |
< |
int argc; |
80 |
< |
char *argv[]; |
77 |
> |
int |
78 |
> |
main( |
79 |
> |
int argc, |
80 |
> |
char *argv[] |
81 |
> |
) |
82 |
|
{ |
83 |
|
int i; |
84 |
|
/* initialize dispatch table */ |
107 |
|
/* get options and print format line */ |
108 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
109 |
|
if (!strcmp(argv[i], "-vrml")) |
110 |
< |
outtype = O_VRML; |
110 |
> |
outtype = O_VRML1; |
111 |
|
else if (!strcmp(argv[i], "-1")) |
112 |
|
outtype = O_INV1; |
113 |
|
else if (!strcmp(argv[i], "-2")) |
121 |
|
case O_INV2: |
122 |
|
printf("#Inventor V2.0 ascii\n"); |
123 |
|
break; |
124 |
< |
case O_VRML: |
125 |
< |
printf("#VRML 1.0 ascii\n"); |
124 |
> |
case O_VRML1: |
125 |
> |
printf("#VRML V1.0 ascii\n"); |
126 |
|
break; |
127 |
|
} |
128 |
|
printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR); |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
< |
indent(deeper) /* indent in or out */ |
167 |
< |
int deeper; |
166 |
> |
void |
167 |
> |
indent( /* indent in or out */ |
168 |
> |
int deeper |
169 |
> |
) |
170 |
|
{ |
171 |
|
static int level; /* current nesting level */ |
172 |
|
register int i; |
186 |
|
|
187 |
|
|
188 |
|
int |
189 |
< |
i_comment(ac, av) /* transfer comment as is */ |
190 |
< |
int ac; |
191 |
< |
char **av; |
189 |
> |
i_comment( /* transfer comment as is */ |
190 |
> |
int ac, |
191 |
> |
char **av |
192 |
> |
) |
193 |
|
{ |
194 |
|
fputs(tabs, stdout); |
195 |
|
putchar('#'); /* Inventor comment character */ |
203 |
|
|
204 |
|
|
205 |
|
int |
206 |
< |
i_object(ac, av) /* group object name */ |
207 |
< |
int ac; |
208 |
< |
char **av; |
206 |
> |
i_object( /* group object name */ |
207 |
> |
int ac, |
208 |
> |
char **av |
209 |
> |
) |
210 |
|
{ |
211 |
|
static int objnest; |
212 |
|
|
230 |
|
|
231 |
|
|
232 |
|
int |
233 |
< |
i_xf(ac, av) /* transform object(s) */ |
234 |
< |
int ac; |
235 |
< |
char **av; |
233 |
> |
i_xf( /* transform object(s) */ |
234 |
> |
int ac, |
235 |
> |
char **av |
236 |
> |
) |
237 |
|
{ |
238 |
|
static long xfid; |
239 |
|
register XF_SPEC *spec; |
299 |
|
|
300 |
|
|
301 |
|
int |
302 |
< |
put_xform(spec) /* translate and print transform */ |
303 |
< |
register XF_SPEC *spec; |
302 |
> |
put_xform( /* translate and print transform */ |
303 |
> |
register XF_SPEC *spec |
304 |
> |
) |
305 |
|
{ |
306 |
|
register char **av; |
307 |
|
register int n; |
331 |
|
|
332 |
|
|
333 |
|
int |
334 |
< |
put_material() /* put out current material */ |
334 |
> |
put_material(void) /* put out current material */ |
335 |
|
{ |
336 |
|
char *mname = curmatname; |
337 |
|
float rgbval[3]; |
367 |
|
indent(0); |
368 |
|
printf("%s}\n", tabs); |
369 |
|
if (outtype != O_INV1) |
370 |
< |
printf("%sShapeHints { shapeType %s }\n", tabs, |
370 |
> |
printf("%sShapeHints { shapeType %s faceType UNKNOWN_FACE_TYPE }\n", |
371 |
> |
tabs, |
372 |
|
c_cmaterial->sided ? "SOLID" : "UNKNOWN_SHAPE_TYPE"); |
373 |
|
indent(0); |
374 |
|
printf("%s}\n", tabs); |
378 |
|
|
379 |
|
|
380 |
|
int |
381 |
< |
i_face(ac, av) /* translate an N-sided face */ |
382 |
< |
int ac; |
383 |
< |
char **av; |
381 |
> |
i_face( /* translate an N-sided face */ |
382 |
> |
int ac, |
383 |
> |
char **av |
384 |
> |
) |
385 |
|
{ |
386 |
|
static char lastmat[MAXID]; |
387 |
|
struct face *newf; |
429 |
|
|
430 |
|
|
431 |
|
int |
432 |
< |
i_sph(ac, av) /* translate sphere description */ |
433 |
< |
int ac; |
434 |
< |
char **av; |
432 |
> |
i_sph( /* translate sphere description */ |
433 |
> |
int ac, |
434 |
> |
char **av |
435 |
> |
) |
436 |
|
{ |
437 |
|
register C_VERTEX *cent; |
438 |
|
|
460 |
|
|
461 |
|
|
462 |
|
int |
463 |
< |
i_cyl(ac, av) /* translate a cylinder description */ |
464 |
< |
int ac; |
465 |
< |
char **av; |
463 |
> |
i_cyl( /* translate a cylinder description */ |
464 |
> |
int ac, |
465 |
> |
char **av |
466 |
> |
) |
467 |
|
{ |
468 |
|
register C_VERTEX *v1, *v2; |
469 |
|
FVECT va; |
478 |
|
if (put_material() < 0) |
479 |
|
return(MG_EBADMAT); |
480 |
|
/* get endpoints */ |
481 |
< |
if ((v1 = c_getvert(av[1])) == NULL | (v2 = c_getvert(av[3])) == NULL) |
481 |
> |
if (((v1 = c_getvert(av[1])) == NULL) | ((v2 = c_getvert(av[3])) == NULL)) |
482 |
|
return(MG_EUNDEF); |
483 |
|
/* get radius */ |
484 |
|
if (!isflt(av[2])) |
488 |
|
va[1] = v2->p[1] - v1->p[1]; |
489 |
|
va[2] = v2->p[2] - v1->p[2]; |
490 |
|
length = sqrt(DOT(va,va)); |
491 |
< |
angle = acos(va[1]/length); |
491 |
> |
if (va[1] >= length) |
492 |
> |
angle = 0.; |
493 |
> |
else if (va[1] <= -length) |
494 |
> |
angle = PI; |
495 |
> |
else |
496 |
> |
angle = acos(va[1]/length); |
497 |
|
printf("%sTranslation { translation %13.9g %13.9g %13.9g }\n", tabs, |
498 |
|
.5*(v1->p[0]+v2->p[0]), .5*(v1->p[1]+v2->p[1]), |
499 |
|
.5*(v1->p[2]+v2->p[2])); |
509 |
|
|
510 |
|
|
511 |
|
char * |
512 |
< |
to_id(name) /* make sure a name is a valid Inventor ID */ |
513 |
< |
register char *name; |
512 |
> |
to_id( /* make sure a name is a valid Inventor ID */ |
513 |
> |
register char *name |
514 |
> |
) |
515 |
|
{ |
516 |
|
static char id[MAXID]; |
517 |
|
register char *cp; |
526 |
|
} |
527 |
|
|
528 |
|
|
529 |
< |
flush_cache() /* put out cached faces */ |
529 |
> |
void |
530 |
> |
flush_cache(void) /* put out cached faces */ |
531 |
|
{ |
532 |
|
int donorms = 0; |
533 |
|
register struct face *f; |