home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / qbspedit / lmp2txt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  6.6 KB  |  316 lines

  1. #include "stdio.h"
  2.  
  3. typedef float scalar_t;
  4.  
  5. typedef struct
  6. {
  7.     scalar_t x;
  8.     scalar_t y;
  9.     scalar_t z;
  10. } vec3_t;
  11.  
  12. typedef struct
  13. {
  14.     vec3_t   min;
  15.     vec3_t   max;
  16. } boundbox_t;
  17.  
  18. typedef struct 
  19. {
  20.     vec3_t normal;
  21.     scalar_t dist;
  22.     long type;
  23.     long firstsurf;
  24.     long numsurf;
  25. } plane_t;
  26.  
  27. typedef struct 
  28. {
  29.     float x;
  30.     float y;
  31.     float z;
  32. } vertex_t;
  33.  
  34. typedef struct 
  35. {
  36.     long planenum;
  37.     unsigned short front;
  38.     unsigned short back;
  39.     boundbox_t box;
  40. } node_t;
  41.  
  42. typedef struct 
  43. {
  44.     unsigned short planenum;
  45.     unsigned short side;
  46.     unsigned char texnum;
  47.     unsigned char sofs;
  48.     unsigned char tofs;
  49.     unsigned char flips;
  50.     long firstedge;
  51.     long numedge;
  52.     unsigned char light;
  53.     unsigned char unknown0;
  54.     unsigned short unknown1;
  55.     unsigned long lightmap;
  56. } surface_t;
  57.  
  58. typedef struct 
  59. {
  60.     unsigned long planenum;
  61.     short front;
  62.     short back;
  63. } dhullbound_t;
  64.  
  65. typedef struct 
  66. {
  67.     unsigned long code;
  68.     boundbox_t bound;
  69.     unsigned long vislist;
  70.     long firstsurf;
  71.     long numsurf;
  72.     unsigned long zeroes[3];
  73.     unsigned short zero;
  74.     unsigned short flag;
  75. } dleaf_t;
  76.  
  77. typedef struct
  78. {
  79.     unsigned short startvertex;
  80.     unsigned short endvertex;
  81. } edge_t;
  82.  
  83. typedef struct 
  84. {
  85.     boundbox_t bound;
  86.     long zero[3];
  87.     long node;
  88.     long boundnode;
  89.     long numleafs;
  90.     long firstsurface;
  91.     long numsurfaces;
  92. } dhull_t;
  93.  
  94. long fsize(FILE * file)
  95. {
  96.     long pos, end;
  97.     pos = ftell(file);
  98.     fseek(file, 0, SEEK_END);
  99.     end = ftell(file);
  100.     fseek(file, pos, SEEK_SET);
  101.     return end;
  102. }
  103.  
  104. int main()
  105. {
  106.     FILE * lmp;
  107.     FILE * txt;
  108.     char textbuf;
  109.     unsigned short ushortbuf;
  110.     short i;
  111.     plane_t plane;
  112.     vertex_t vertex;
  113.     unsigned char visentry;
  114.     node_t node;
  115.     surface_t surface;
  116.     dhullbound_t dhullbound;
  117.     dleaf_t dleaf;
  118.     edge_t edge;
  119.     dhull_t dhull;
  120.     long entcount;
  121.     printf("\n");
  122.     printf("Quake BSP Entry To Text Converter\n");
  123.     printf("Version 1.0\n");
  124.     printf("Copyright (C) 1996 Richard Felker, aka Dalias");
  125.     printf("\n");
  126.     /*lmp = fopen("entry00.lmp", "rb"); txt = fopen("entry00.txt", "w");
  127.     for(i = 1; i <= entcount; i++)
  128.     {
  129.         fread(&textbuf, 1, 1, lmp);
  130.         fwrite(&textbuf, 1, 1, txt);
  131.     }
  132.     fclose(lmp); fclose(txt);*/
  133.     lmp = fopen("entry01.lmp", "rb"); txt = fopen("planes.txt", "w");
  134.     entcount = fsize(lmp) / sizeof(plane_t);
  135.     fprintf(txt, "%ld\n", entcount);
  136.     for(i = 1; i <= entcount; i++)
  137.     {
  138.         fread(&plane, sizeof(plane_t), 1, lmp);
  139.         fprintf(txt, "%f %f %f %f %ld %ld %ld\n",
  140.             plane.normal.x,
  141.             plane.normal.y,
  142.             plane.normal.z,
  143.             plane.dist,
  144.             plane.type,
  145.             plane.firstsurf,
  146.             plane.numsurf);
  147.     }
  148.     fclose(lmp); fclose(txt);
  149.     lmp = fopen("entry03.lmp", "rb"); txt = fopen("vertices.txt", "w");
  150.     entcount = fsize(lmp) / sizeof(vertex_t);
  151.     fprintf(txt, "%ld\n", entcount);
  152.     for(i = 1; i <= entcount; i++)
  153.     {
  154.         fread(&vertex, sizeof(vertex_t), 1, lmp);
  155.         fprintf(txt, "%.2f %.2f %.2f\n",
  156.             vertex.x,
  157.             vertex.y,
  158.             vertex.z);
  159.     }
  160.     fclose(lmp); fclose(txt);
  161.     lmp = fopen("entry05.lmp", "rb"); txt = fopen("nodes.txt", "w");
  162.     entcount = fsize(lmp) / sizeof(node_t);
  163.     fprintf(txt, "%ld\n", entcount);
  164.     for(i = 1; i <= entcount; i++)
  165.     {
  166.         fread(&node, sizeof(node_t), 1, lmp);
  167.         fprintf(txt, "%ld %hu %hu %.2f %.2f %.2f %.2f %.2f %.2f\n",
  168.             node.planenum,
  169.             node.front,
  170.             node.back,
  171.             node.box.min.x,
  172.             node.box.min.y,
  173.             node.box.min.z,
  174.             node.box.max.x,
  175.             node.box.max.y,
  176.             node.box.max.z
  177.             );
  178.     }
  179.     fclose(lmp); fclose(txt);
  180.     lmp = fopen("entry06.lmp", "rb"); txt = fopen("surfaces.txt", "w");
  181.     entcount = fsize(lmp) / sizeof(surface_t);
  182.     fprintf(txt, "%ld\n", entcount);
  183.     for(i = 1; i <= entcount; i++)
  184.     {
  185.         fread(&surface, sizeof(surface_t), 1, lmp);
  186.         fprintf(txt, "%hu %hu %hu %hu %hu %hu %ld %ld %hu %hu %hu %lu\n",
  187.             surface.planenum,
  188.             surface.side,
  189.             surface.texnum,
  190.             surface.sofs,
  191.             surface.tofs,
  192.             surface.flips,
  193.             surface.firstedge,
  194.             surface.numedge,
  195.             surface.light,
  196.             surface.unknown0,
  197.             surface.unknown1,
  198.             surface.lightmap
  199.             );
  200.     }
  201.     fclose(lmp); fclose(txt);
  202.     lmp = fopen("entry08.lmp", "rb"); txt = fopen("dhullbnd.txt", "w");
  203.     entcount = fsize(lmp) / sizeof(dhullbound_t);
  204.     fprintf(txt, "%ld\n", entcount);
  205.     for(i = 1; i <= entcount; i++)
  206.     {
  207.         fread(&dhullbound, sizeof(dhullbound_t), 1, lmp);
  208.         fprintf(txt, "%lu %hd %hd\n",
  209.             dhullbound.planenum,
  210.             dhullbound.front,
  211.             dhullbound.back
  212.             );
  213.     }
  214.     fclose(lmp); fclose(txt);
  215.     lmp = fopen("entry09.lmp", "rb"); txt = fopen("dleaves.txt", "w");
  216.     entcount = fsize(lmp) / sizeof(dleaf_t);
  217.     fprintf(txt, "%ld\n", entcount);
  218.     for(i = 1; i <= entcount; i++)
  219.     {
  220.         fread(&dleaf, sizeof(dleaf_t), 1, lmp);
  221.         fprintf(txt, "%lu %.2f %.2f %.2f %.2f %.2f %.2f %lu %ld %ld %lu %lu %lu %hu %hu\n",
  222.             dleaf.code,
  223.             dleaf.bound.min.x,
  224.             dleaf.bound.min.y,
  225.             dleaf.bound.min.z,
  226.             dleaf.bound.max.x,
  227.             dleaf.bound.max.y,
  228.             dleaf.bound.max.z,
  229.             dleaf.vislist,
  230.             dleaf.firstsurf,
  231.             dleaf.numsurf,
  232.             dleaf.zeroes[0],
  233.             dleaf.zeroes[1],
  234.             dleaf.zeroes[2],
  235.             dleaf.zero,
  236.             dleaf.flag
  237.             );
  238.     }
  239.     fclose(lmp); fclose(txt);
  240.     lmp = fopen("entry10.lmp", "rb"); txt = fopen("surflist.txt", "w");
  241.     entcount = fsize(lmp) / sizeof(unsigned short);
  242.     fprintf(txt, "%ld\n", entcount);
  243.     for(i = 1; i <= entcount; i++)
  244.     {
  245.         fread(&ushortbuf, sizeof(unsigned short), 1, lmp);
  246.         fprintf(txt, "%hu\n",
  247.             ushortbuf
  248.             );
  249.     }
  250.     fclose(lmp); fclose(txt);
  251.     lmp = fopen("entry11.lmp", "rb"); txt = fopen("edges.txt", "w");
  252.     entcount = fsize(lmp) / sizeof(edge_t);
  253.     fprintf(txt, "%ld\n", entcount);
  254.     for(i = 1; i <= entcount; i++)
  255.     {
  256.         fread(&edge, sizeof(edge_t), 1, lmp);
  257.         fprintf(txt, "%hu %hu\n",
  258.             edge.startvertex,
  259.             edge.endvertex
  260.             );
  261.     }
  262.     fclose(lmp); fclose(txt);
  263.     lmp = fopen("entry12.lmp", "rb"); txt = fopen("edgelist.txt", "w");
  264.     entcount = fsize(lmp) / sizeof(unsigned short);
  265.     fprintf(txt, "%ld\n", entcount);
  266.     for(i = 1; i <= entcount; i++)
  267.     {
  268.         fread(&ushortbuf, sizeof(unsigned short), 1, lmp);
  269.         fprintf(txt, "%hu\n",
  270.             ushortbuf
  271.             );
  272.     }
  273.     fclose(lmp); fclose(txt);
  274.     lmp = fopen("entry13.lmp", "rb"); txt = fopen("hulls.txt", "w");
  275.     entcount = fsize(lmp) / sizeof(dhull_t);
  276.     fprintf(txt, "%ld\n", entcount);
  277.     for(i = 1; i <= entcount; i++)
  278.     {
  279.         fread(&dhull, sizeof(dhull_t), 1, lmp);
  280.         fprintf(txt, "%.2f %.2f %.2f %.2f %.2f %.2f %ld %ld %ld %ld %ld %ld %ld %ld\n",
  281.             dhull.bound.min.x,
  282.             dhull.bound.min.y,
  283.             dhull.bound.min.z,
  284.             dhull.bound.max.x,
  285.             dhull.bound.max.y,
  286.             dhull.bound.max.z,
  287.             dhull.zero[0],
  288.             dhull.zero[1],
  289.             dhull.zero[2],
  290.             dhull.node,
  291.             dhull.boundnode,
  292.             dhull.numleafs,
  293.             dhull.firstsurface,
  294.             dhull.numsurfaces
  295.             );
  296.     }
  297.     fclose(lmp); fclose(txt);
  298.     return 0;
  299. }
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.