-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
201 lines (157 loc) · 6.25 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
//############################################################################
//## ##
//## MAIN.CPP ##
//## ##
//## Console APP to load Q3BSP files, interpret them, organize them into ##
//## a triangle mesh, and save them out in various ASCII file formats. ##
//## ##
//## OpenSourced 12/5/2000 by John W. Ratcliff ##
//## ##
//## No warranty expressed or implied. ##
//## ##
//## Part of the Q3BSP project, which converts a Quake 3 BSP file into a ##
//## polygon mesh. ##
//############################################################################
//## ##
//## Contact John W. Ratcliff at jratcliff@verant.com ##
//############################################################################
#define STB_IMAGE_IMPLEMENTATION
#define STBI_ONLY_TGA
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#define MAIN_STRLWR_STRUPR_IMPLEMENTATION
#include "main.h"
#include "q3bsp.h"
#include "fload.h"
int main(int argc,char **argv)
{
VFormatOptions option;
char *options=NULL;
char *fileArg = NULL;
int argi=1; // the current argument
if (argc>=2 && argv[argi][0]== '-') { // we have options
options = argv[argi];
argi++;
}
if ( argi >= argc )
{
printf("Usage: q3bsp [-options] <name>.BSP\n");
printf("Where <name> is the name of a valid Quake3 BSP file.\n\n");
printf("This utility will convert a Quake3 BSP into a valid\n");
printf("polygon mesh and output the results into two seperate VRML 1.0\n");
printf("files. The first VRML file contains all the U/V mapping and\n");
printf("texture mapping information for channel #1, and the second\n");
printf("VRML file will contain all of the U/V mapping and texture names\n");
printf("for the second U/V channel, which contains all lightmap\n");
printf("information. You can then directly import these files into any\n");
printf("number of 3d editing tools, including 3d Studio Max\n");
printf("This tool also extracts the lightmap data and saves it out as a\n");
printf("series of .BMP files.\n\n");
printf("OpenSourced by John W. Ratcliff on December 5, 2000\n");
printf("Merry Christmas!\n\n");
printf("Contact Id Software about using Quake 3 data files in and\n");
printf("Quake 3 editing tools for commercial software development\n");
printf("projects.\n");
printf("Extended Options: \n");
printf("-1 VRML 1 output\n");
printf("-2 VRML 2 output 2 files \n");
printf("-2me VRML 2 output with MultiTexture extension nodes & effects\n");
exit(1);
}
fileArg = argv[argi];
if (options) {
if (strchr(options,'2'))
option.vrml2 = true;
else if (strchr(options,'1'))
option.vrml2 = false;
if (strchr(options,'m'))
option.useMultiTexturing = true;
if (strchr(options,'M'))
option.useMat = true;
if (strchr(options,'l'))
option.useLighting = true;
if (strchr(options,'b'))
option.useBsp = true;
if (strchr(options,'e'))
option.useEffects = true;
if (strchr(options,'v'))
option.verbose = true;
if (strchr(options,'n'))
option.noTextureCoordinates = true;
}
Quake3BSP q( SGET(fileArg), SGET("a") );
VertexMesh *mesh = q.GetVertexMesh();
if ( mesh )
{
String str = fileArg;
char * del = strrchr(fileArg,'\\');
if (del) str = (del+1); // use file name part only
String name1 = str + "1";
String name2 = str + "2";
if (option.vrml2) { // VRML 2 style
if (!option.useMultiTexturing) {
// save VRML file using channel #1
// save VRML file using channel #2
name1+=".wrl";
FILE *fph = fopen(name1.c_str(),"wb");
fprintf(fph,"#VRML V2.0 utf8 generated by QBSP from %s\n",fileArg);
printf("Saving U/V channel #1 to VRML2 file %s\n",name1.c_str());
option.tex1= true;
mesh->SaveVRML2(fph,option);
q.SaveEntitiesVRML2(fph,option);
fclose(fph);
printf("Saving U/V channel #2 to VRML2 file %s.wrl\n",name2.c_str());
name2+=".wrl";
fph = fopen(name2.c_str(),"wb");
fprintf(fph,"#VRML V2.0 utf8 generated by QBSP from %s\n",fileArg);
option.tex1=false;
option.matDefined=false;
option.useMat = false;
mesh->SaveVRML2(fph,option);
fclose(fph);
} else {
name1 = str;
printf("Saving MultiTexture extended VRML file %s.wrl\n",name1.c_str());
String oname = name1+".wrl";
FILE *fph = fopen(oname.c_str(),"wb");
fprintf(fph,"#VRML V2.0 utf8 generated by Q3BSP 1.1 from %s\n",fileArg);
fprintf(fph,"WorldInfo { title \"%s\" }\n\n",fileArg);
fprintf(fph,"NavigationInfo { headlight TRUE avatarSize [0.25 1.3333 2 ]} \n");
// write some PROTO's for effects
if (option.useEffects)
{
Fload effects("q3effects.wrl");
if (!effects.GetData()) {
printf("***********q3effects.wrl NOT FOUND\n");
}
else {
fprintf(fph,"%s\n",(char *)effects.GetData());
option.matDefined = true; // assume MAT is defined in this file
}
}
option.tex1= true;
if (option.useBsp)
q.SaveNodesBsp(fph,option);
else mesh->SaveVRML2(fph,option);
q.SaveEntitiesVRML2(fph,option);
fclose(fph);
}
} else { // VRML 1 style
printf("Saving U/V channel #1 to file %s.wrl\n",name1.c_str());
mesh->SaveVRML(name1,true);
printf("Saving U/V channel #2 to file %s.wrl\n",name2.c_str());
mesh->SaveVRML(name2,false);
}
}
else
{
printf("Failed to crunch %s\n", fileArg);
return -1;
}
return 0;
}