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.4 by greg, Thu May 30 11:56:43 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 349 | Line 351 | char *read_string (void);
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) {
# Line 407 | Line 423 | int main (int argc, char *argv[])
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);
# Line 436 | Line 455 | int main (int argc, char *argv[])
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");
# Line 456 | Line 474 | void process_args (int argc, char *argv[])
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");
# Line 480 | Line 498 | void process_args (int argc, char *argv[])
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, "");
# Line 536 | Line 554 | void process_args (int argc, char *argv[])
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  
# Line 991 | Line 1012 | void write_light (FILE *f, char *name, Vector pos, Col
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");
# Line 1066 | Line 1087 | void write_spot (FILE *f, char *name, Vector pos, Vect
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]);
# Line 1580 | Line 1601 | void write_mgf_material (FILE *f, MatProp *m)
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;
# Line 1607 | Line 1630 | void write_mesh (FILE *f, Mesh *mesh)
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++) {
# Line 2332 | Line 2377 | void parse_3ds (Chunk *mainchunk)
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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines