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.3 by greg, Fri Feb 9 11:02:29 1996 UTC

# Line 270 | Line 270 | int    cameras = 0;
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[]);
# Line 352 | Line 354 | int read_mgfmatname (char *s, int n, FILE *f);
354  
355   int main (int argc, char *argv[])
356   {
357 +    char meshfname[128];
358      Material *m;
359      int i;
360  
361      process_args (argc, argv);
362  
363 <    if (format != RAW) {
363 >    if (!no_opt) {
364          opt_set_format (format);
365          opt_set_dec (4);
366          opt_set_bound (bound);
367          opt_set_smooth (smooth);
368          opt_set_quiet (!verbose);
369          opt_set_fname (outname, "");
370 +    } else if (format == MGF) {
371 +        strcpy(meshfname, outname);
372 +        add_ext(meshfname, "inc", 1);
373 +        if (!strcmp(meshfname, outname)) {
374 +            printf ("Output and mesh file names are identical!\n");
375 +            exit (1);
376 +        }
377 +        if ((meshf = fopen (meshfname, "w")) == NULL) {
378 +            printf ("Cannot open mesh output file %s!\n", meshfname);
379 +            exit (1);
380 +        }
381      }
382  
383      if ((in = fopen (inname, "rb")) == NULL) {
# Line 407 | Line 421 | int main (int argc, char *argv[])
421      if (frame >= 0)
422          save_animation();
423  
424 <    if (format != RAW) {
424 >    if (!no_opt) {
425          write_summary (out);
426          fflush (out);
427  
428          opt_finish();
429 +    } else if (meshf != NULL) {
430 +        fclose(meshf);
431 +        fprintf (out, "i %s\n", meshfname);
432      }
433  
434      fclose (out);
# 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++) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines