home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / qbspedit / txt2lmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  6.4 KB  |  308 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. int main()
  95. {
  96.     FILE * lmp;
  97.     FILE * txt;
  98.     char textbuf;
  99.     unsigned short ushortbuf;
  100.     short i;
  101.     plane_t plane;
  102.     vertex_t vertex;
  103.     unsigned char visentry;
  104.     node_t node;
  105.     surface_t surface;
  106.     dhullbound_t dhullbound;
  107.     dleaf_t dleaf;
  108.     edge_t edge;
  109.     dhull_t dhull;
  110.     float fpsupport;
  111.     short entcount;
  112.     fpsupport = (float)1.0000;
  113.     printf("\n");
  114.     printf("Quake Text To BSP Entry Converter\n");
  115.     printf("Version 1.0\n");
  116.     printf("Copyright (C) 1996 Richard Felker, aka Dalias");
  117.     printf("\n");
  118.     /*lmp = fopen("entry00.lmp", "r"); txt = fopen("entry00.txt", "w");
  119.     for (i = 1; i <= entcount; i++)
  120.     {
  121.         fwrite(&textbuf, 1, 1, lmp);
  122.         fwrite(&textbuf, 1, 1, txt);
  123.     }
  124.     fclose(lmp); fclose(txt);*/
  125.     printf("Converting Planes...\n");
  126.     lmp = fopen("entry01.lmp", "wb"); txt = fopen("planes.txt", "r");
  127.     fscanf(txt, "%hd", &entcount);
  128.     for (i = 1; i <= entcount; i++)
  129.     {
  130.         fscanf(txt, "%f %f %f %f %ld %ld %ld",
  131.             &plane.normal.x,
  132.             &plane.normal.y,
  133.             &plane.normal.z,
  134.             &plane.dist,
  135.             &plane.type,
  136.             &plane.firstsurf,
  137.             &plane.numsurf);
  138.         fwrite(&plane, sizeof(plane_t), 1, lmp);
  139.     }
  140.     fclose(lmp); fclose(txt);
  141.     printf("Converting Vertices...\n");
  142.     lmp = fopen("entry03.lmp", "wb"); txt = fopen("vertices.txt", "r");
  143.     fscanf(txt, "%hd", &entcount);
  144.     for (i = 1; i <= entcount; i++)
  145.     {
  146.         fscanf(txt, "%f %f %f",
  147.             &vertex.x,
  148.             &vertex.y,
  149.             &vertex.z);
  150.         fwrite(&vertex, sizeof(vertex_t), 1, lmp);
  151.     }
  152.     fclose(lmp); fclose(txt);
  153.     printf("Converting Nodes...\n");
  154.     lmp = fopen("entry05.lmp", "wb"); txt = fopen("nodes.txt", "r");
  155.     fscanf(txt, "%hd", &entcount);
  156.     for (i = 1; i <= entcount; i++)
  157.     {
  158.         fscanf(txt, "%ld %hu %hu %f %f %f %f %f %f",
  159.             &node.planenum,
  160.             &node.front,
  161.             &node.back,
  162.             &node.box.min.x,
  163.             &node.box.min.y,
  164.             &node.box.min.z,
  165.             &node.box.max.x,
  166.             &node.box.max.y,
  167.             &node.box.max.z
  168.             );
  169.         fwrite(&node, sizeof(node_t), 1, lmp);
  170.     }
  171.     fclose(lmp); fclose(txt);
  172.     printf("Converting Surfaces...\n");
  173.     lmp = fopen("entry06.lmp", "wb"); txt = fopen("surfaces.txt", "r");
  174.     fscanf(txt, "%hd", &entcount);
  175.     for (i = 1; i <= entcount; i++)
  176.     {
  177.         fscanf(txt, "%hu %hu %hu %hu %hu %hu %ld %ld %hu %hu %hu %lu",
  178.             &surface.planenum,
  179.             &surface.side,
  180.             &surface.texnum,
  181.             &surface.sofs,
  182.             &surface.tofs,
  183.             &surface.flips,
  184.             &surface.firstedge,
  185.             &surface.numedge,
  186.             &surface.light,
  187.             &surface.unknown0,
  188.             &surface.unknown1,
  189.             &surface.lightmap
  190.             );
  191.         fwrite(&surface, sizeof(surface_t), 1, lmp);
  192.     }
  193.     fclose(lmp); fclose(txt);
  194.     printf("Converting Hull Bound Nodes...\n");
  195.     lmp = fopen("entry08.lmp", "wb"); txt = fopen("dhullbnd.txt", "r");
  196.     fscanf(txt, "%hd", &entcount);
  197.     for (i = 1; i <= entcount; i++)
  198.     {
  199.         fscanf(txt, "%lu %hd %hd",
  200.             &dhullbound.planenum,
  201.             &dhullbound.front,
  202.             &dhullbound.back
  203.             );
  204.         fwrite(&dhullbound, sizeof(dhullbound_t), 1, lmp);
  205.     }
  206.     fclose(lmp); fclose(txt);
  207.     printf("Converting Leaves...\n");
  208.     lmp = fopen("entry09.lmp", "wb"); txt = fopen("dleaves.txt", "r");
  209.     fscanf(txt, "%hd", &entcount);
  210.     for (i = 1; i <= entcount; i++)
  211.     {
  212.         fscanf(txt, "%lu %f %f %f %f %f %f %lu %ld %ld %lu %lu %lu %hu %hu",
  213.             &dleaf.code,
  214.             &dleaf.bound.min.x,
  215.             &dleaf.bound.min.y,
  216.             &dleaf.bound.min.z,
  217.             &dleaf.bound.max.x,
  218.             &dleaf.bound.max.y,
  219.             &dleaf.bound.max.z,
  220.             &dleaf.vislist,
  221.             &dleaf.firstsurf,
  222.             &dleaf.numsurf,
  223.             &dleaf.zeroes[0],
  224.             &dleaf.zeroes[1],
  225.             &dleaf.zeroes[2],
  226.             &dleaf.zero,
  227.             &dleaf.flag
  228.             );
  229.         fwrite(&dleaf, sizeof(dleaf_t), 1, lmp);
  230.     }
  231.     fclose(lmp); fclose(txt);
  232.     printf("Converting Surface List...\n");
  233.     lmp = fopen("entry10.lmp", "wb"); txt = fopen("surflist.txt", "r");
  234.     fscanf(txt, "%hd", &entcount);
  235.     for (i = 1; i <= entcount; i++)
  236.     {
  237.         fscanf(txt, "%hu",
  238.             &ushortbuf
  239.             );
  240.         fwrite(&ushortbuf, sizeof(unsigned short), 1, lmp);
  241.     }
  242.     fclose(lmp); fclose(txt);
  243.     printf("Converting Edges...\n");
  244.     lmp = fopen("entry11.lmp", "wb"); txt = fopen("edges.txt", "r");
  245.     fscanf(txt, "%hd", &entcount);
  246.     for (i = 1; i <= entcount; i++)
  247.     {
  248.         fscanf(txt, "%hu %hu",
  249.             &edge.startvertex,
  250.             &edge.endvertex
  251.             );
  252.         fwrite(&edge, sizeof(edge_t), 1, lmp);
  253.     }
  254.     fclose(lmp); fclose(txt);
  255.     printf("Converting Edge List...\n");
  256.     lmp = fopen("entry12.lmp", "wb"); txt = fopen("edgelist.txt", "r");
  257.     fscanf(txt, "%hd", &entcount);
  258.     for (i = 1; i <= entcount; i++)
  259.     {
  260.         fscanf(txt, "%hu",
  261.             &ushortbuf
  262.             );
  263.         fwrite(&ushortbuf, sizeof(unsigned short), 1, lmp);
  264.     }
  265.     fclose(lmp); fclose(txt);
  266.     printf("Converting Hulls...\n");
  267.     lmp = fopen("entry13.lmp", "wb"); txt = fopen("hulls.txt", "r");
  268.     fscanf(txt, "%hd", &entcount);
  269.     for (i = 1; i <= entcount; i++)
  270.     {
  271.         fscanf(txt, "%f %f %f %f %f %f %ld %ld %ld %ld %ld %ld %ld %ld",
  272.             &dhull.bound.min.x,
  273.             &dhull.bound.min.y,
  274.             &dhull.bound.min.z,
  275.             &dhull.bound.max.x,
  276.             &dhull.bound.max.y,
  277.             &dhull.bound.max.z,
  278.             &dhull.zero[0],
  279.             &dhull.zero[1],
  280.             &dhull.zero[2],
  281.             &dhull.node,
  282.             &dhull.boundnode,
  283.             &dhull.numleafs,
  284.             &dhull.firstsurface,
  285.             &dhull.numsurfaces
  286.             );
  287.         fwrite(&dhull, sizeof(dhull_t), 1, lmp);
  288.     }
  289.     fclose(lmp); fclose(txt);
  290.     return 0;
  291. }
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.