ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/3ds2mgf.c
(Generate patch)

Comparing ray/src/cv/mgflib/3ds2mgf.c (file contents):
Revision 1.1 by greg, Thu Feb 8 11:08:03 1996 UTC vs.
Revision 1.6 by greg, Fri Feb 28 20:11:29 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines