47 |
|
#define MGF 4 |
48 |
|
#define RAW 99 |
49 |
|
|
50 |
< |
#define DEG(x) ((180.0/M_PI)*(x)) |
51 |
< |
#define RAD(x) ((M_PI/180.0)*(x)) |
50 |
> |
#define DEG(x) ((double)(180.0/M_PI)*(x)) |
51 |
> |
#define RAD(x) ((double)(M_PI/180.0)*(x)) |
52 |
|
|
53 |
|
#ifndef M_PI |
54 |
|
#define M_PI (3.14159265358979323846) |
270 |
|
int libs = 0; |
271 |
|
float vue_version = 1.0; |
272 |
|
Matrix *ani_matrix = NULL; |
273 |
+ |
int no_opt = FALSE; |
274 |
+ |
FILE *meshf = NULL; |
275 |
|
|
276 |
|
|
277 |
|
void process_args (int argc, char *argv[]); |
351 |
|
float findfov (float lens); |
352 |
|
int read_mgfmatname (char *s, int n, FILE *f); |
353 |
|
|
354 |
+ |
char *progname; |
355 |
|
|
356 |
+ |
|
357 |
|
int main (int argc, char *argv[]) |
358 |
|
{ |
359 |
+ |
char meshfname[128]; |
360 |
|
Material *m; |
361 |
|
int i; |
362 |
|
|
363 |
|
process_args (argc, argv); |
364 |
|
|
365 |
< |
if (format != RAW) { |
365 |
> |
if (!no_opt) { |
366 |
|
opt_set_format (format); |
367 |
|
opt_set_dec (4); |
368 |
|
opt_set_bound (bound); |
369 |
|
opt_set_smooth (smooth); |
370 |
|
opt_set_quiet (!verbose); |
371 |
|
opt_set_fname (outname, ""); |
372 |
+ |
} else if (format == MGF) { |
373 |
+ |
strcpy(meshfname, outname); |
374 |
+ |
add_ext(meshfname, "inc", 1); |
375 |
+ |
if (!strcmp(meshfname, outname)) { |
376 |
+ |
printf ("Output and mesh file names are identical!\n"); |
377 |
+ |
exit (1); |
378 |
+ |
} |
379 |
+ |
if ((meshf = fopen (meshfname, "w")) == NULL) { |
380 |
+ |
printf ("Cannot open mesh output file %s!\n", meshfname); |
381 |
+ |
exit (1); |
382 |
+ |
} |
383 |
|
} |
384 |
|
|
385 |
|
if ((in = fopen (inname, "rb")) == NULL) { |
423 |
|
if (frame >= 0) |
424 |
|
save_animation(); |
425 |
|
|
426 |
< |
if (format != RAW) { |
426 |
> |
if (!no_opt) { |
427 |
|
write_summary (out); |
428 |
|
fflush (out); |
429 |
|
|
430 |
|
opt_finish(); |
431 |
+ |
} else if (meshf != NULL) { |
432 |
+ |
fclose(meshf); |
433 |
+ |
fprintf (out, "i %s\n", meshfname); |
434 |
|
} |
435 |
|
|
436 |
|
fclose (out); |
455 |
|
void process_args (int argc, char *argv[]) |
456 |
|
{ |
457 |
|
int i; |
439 |
– |
char *progname; |
458 |
|
char *env_opt, *option; |
459 |
|
|
460 |
|
printf("\n\nAutodesk 3D Studio to Raytracer file Translator. Feb/96\n"); |
474 |
|
printf (" -b<object> - Convert this object as a box\n"); |
475 |
|
printf (" +i, -i - Turn internal bounding on or off\n"); |
476 |
|
printf (" +v, -v - Turn verbose status messages on or off\n"); |
477 |
< |
printf (" -op - Output to POV-Ray 2.0 format (default)\n"); |
477 |
> |
printf (" -op - Output to POV-Ray 2.0 format\n"); |
478 |
|
printf (" -op1 - Output to POV-Ray 1.0 format\n"); |
479 |
|
printf (" -ov - Output to Vivid format\n"); |
480 |
|
printf (" -ol - Output to poLyray format\n"); |
498 |
|
else if (!strcmp(progname, "3ds2raw")) |
499 |
|
format = RAW; |
500 |
|
else |
501 |
< |
format = MGF; /* default if program name strange */ |
501 |
> |
format = POV20; /* default if program name strange */ |
502 |
|
|
503 |
|
strcpy (inname, ""); |
504 |
|
strcpy (outname, ""); |
554 |
|
|
555 |
|
if ((strlen(vuename) > 0) != (frame >= 0)) |
556 |
|
abortmsg ("The -a and -f parameters must be used together", 1); |
557 |
+ |
|
558 |
+ |
if (format == RAW || (format == MGF && smooth < 0.1)) |
559 |
+ |
no_opt = TRUE; |
560 |
|
} |
561 |
|
|
562 |
|
|
1012 |
|
if (name[0]) fprintf (f, "o %s\n", name); |
1013 |
|
fprintf (f, "m\n\tsides 1\n\tc\n\t\t\tcmix %.3f R %.3f G %.3f B\n\ted %e\n", |
1014 |
|
CIE_Y_r*col.red, CIE_Y_g*col.green, CIE_Y_b*col.blue, |
1015 |
< |
10000.0*(CIE_Y_r*col.red + CIE_Y_g*col.green + CIE_Y_b*col.blue)); |
1015 |
> |
100000.0*(CIE_Y_r*col.red + CIE_Y_g*col.green + CIE_Y_b*col.blue)); |
1016 |
|
fprintf (f, "v c =\n\tp %.4f %.4f %.4f\nsph c .01\n", |
1017 |
|
pos[X], pos[Y], pos[Z]); |
1018 |
|
if (name[0]) fprintf (f, "o\n"); |
1087 |
|
fprintf (f, "# hotspot: %.2f\n# falloff: %.2f\n", hotspot, falloff); |
1088 |
|
fprintf (f, "m\n\tsides 1\n\tc\n\t\t\tcmix %.3f R %.3f G %.3f B\n\ted %e\n", |
1089 |
|
CIE_Y_r*col.red, CIE_Y_g*col.green, CIE_Y_b*col.blue, |
1090 |
< |
10000.0*(CIE_Y_r*col.red + CIE_Y_g*col.green + CIE_Y_b*col.blue)); |
1090 |
> |
100000.0*(CIE_Y_r*col.red + CIE_Y_g*col.green + CIE_Y_b*col.blue)); |
1091 |
|
fprintf (f, "v c =\n\tp %.4f %.4f %.4f\n\tn %.4f %.4f %.4f\n", |
1092 |
|
pos[X], pos[Y], pos[Z], |
1093 |
|
target[X]-pos[X], target[Y]-pos[Y], target[Z]-pos[Z]); |
1601 |
|
/* Write a mesh file */ |
1602 |
|
void write_mesh (FILE *f, Mesh *mesh) |
1603 |
|
{ |
1604 |
+ |
FILE *fi; |
1605 |
|
int i; |
1606 |
+ |
char curmat[80]; |
1607 |
|
Vector va, vb, vc; |
1608 |
|
Summary *new_summary; |
1609 |
|
Matrix obj_matrix; |
1630 |
|
} |
1631 |
|
|
1632 |
|
switch (format) { |
1633 |
+ |
case MGF: |
1634 |
+ |
if (no_opt) { |
1635 |
+ |
if (mesh->name[0]) fprintf (meshf, "o %s\n", mesh->name); |
1636 |
+ |
for (i = 0; i < mesh->vertices; i++) { |
1637 |
+ |
vect_copy(va, mesh->vertex[i]); |
1638 |
+ |
if (ani_matrix != NULL) |
1639 |
+ |
vect_transform (va, va, obj_matrix); |
1640 |
+ |
fprintf (meshf, "v v%d =\n\tp %.5f %.5f %.5f\n", |
1641 |
+ |
i, va[X], va[Y], va[Z]); |
1642 |
+ |
} |
1643 |
+ |
curmat[0] = '\0'; |
1644 |
+ |
for (i = 0; i < mesh->faces; i++) { |
1645 |
+ |
if (strcmp(mesh->mtl[i]->name, curmat)) { |
1646 |
+ |
strcpy(curmat, mesh->mtl[i]->name); |
1647 |
+ |
fprintf (meshf, "m %s\n", curmat); |
1648 |
+ |
} |
1649 |
+ |
fprintf (meshf, "f v%d v%d v%d\n", mesh->face[i].a, |
1650 |
+ |
mesh->face[i].b, mesh->face[i].c); |
1651 |
+ |
} |
1652 |
+ |
if (mesh->name[0]) fprintf (meshf, "o\n"); |
1653 |
+ |
break; |
1654 |
+ |
} |
1655 |
+ |
/*FALL THROUGH*/ |
1656 |
|
case POV10: |
1657 |
|
case POV20: |
1658 |
|
case VIVID: |
1659 |
|
case POLYRAY: |
1614 |
– |
case MGF: |
1660 |
|
opt_set_vert (mesh->vertices); |
1661 |
|
|
1662 |
|
for (i = 0; i < mesh->faces; i++) { |
2377 |
|
|
2378 |
|
do { |
2379 |
|
start_chunk (&chunk); |
2380 |
< |
|
2380 |
> |
if (feof(in)) { |
2381 |
> |
fprintf(stderr, "%s: unexpected EOF\n", progname); |
2382 |
> |
break; |
2383 |
> |
} |
2384 |
|
if (chunk.end <= mainchunk->end) { |
2385 |
|
switch (chunk.tag) { |
2386 |
|
case 0x3D3D: parse_mdata (&chunk); |