| 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 |
#include "q3map2.h" |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
void PseudoCompileBSP( qboolean need_tree, const char *BSPFilePath, const char *surfaceFilePath ){ |
| 41 |
int models; |
| 42 |
char modelValue[10]; |
| 43 |
entity_t *entity; |
| 44 |
face_t *faces; |
| 45 |
tree_t *tree; |
| 46 |
node_t *node; |
| 47 |
brush_t *brush; |
| 48 |
side_t *side; |
| 49 |
int i; |
| 50 |
|
| 51 |
SetDrawSurfacesBuffer(); |
| 52 |
mapDrawSurfs = safe_malloc0( sizeof( mapDrawSurface_t ) * MAX_MAP_DRAW_SURFS ); |
| 53 |
numMapDrawSurfs = 0; |
| 54 |
|
| 55 |
BeginBSPFile(); |
| 56 |
models = 1; |
| 57 |
for ( mapEntityNum = 0; mapEntityNum < numEntities; mapEntityNum++ ) |
| 58 |
{ |
| 59 |
|
| 60 |
entity = &entities[ mapEntityNum ]; |
| 61 |
if ( entity->brushes == NULL && entity->patches == NULL ) { |
| 62 |
continue; |
| 63 |
} |
| 64 |
|
| 65 |
if ( mapEntityNum != 0 ) { |
| 66 |
sprintf( modelValue, "*%d", models++ ); |
| 67 |
SetKeyValue( entity, "model", modelValue ); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
Sys_FPrintf( SYS_VRB, "############### model %i ###############\n", numBSPModels ); |
| 72 |
BeginModel(); |
| 73 |
|
| 74 |
entity->firstDrawSurf = numMapDrawSurfs; |
| 75 |
|
| 76 |
ClearMetaTriangles(); |
| 77 |
PatchMapDrawSurfs( entity ); |
| 78 |
|
| 79 |
if ( mapEntityNum == 0 && need_tree ) { |
| 80 |
faces = MakeStructuralBSPFaceList( entities[0].brushes ); |
| 81 |
tree = FaceBSP( faces ); |
| 82 |
node = tree->headnode; |
| 83 |
} |
| 84 |
else |
| 85 |
{ |
| 86 |
node = AllocNode(); |
| 87 |
node->planenum = PLANENUM_LEAF; |
| 88 |
tree = AllocTree(); |
| 89 |
tree->headnode = node; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
for ( brush = entity->brushes; brush; brush = brush->next ) |
| 94 |
{ |
| 95 |
|
| 96 |
for ( i = 0; i < brush->numsides; i++ ) |
| 97 |
{ |
| 98 |
|
| 99 |
side = &brush->sides[ i ]; |
| 100 |
if ( side->winding == NULL ) { |
| 101 |
continue; |
| 102 |
} |
| 103 |
|
| 104 |
if ( side->shaderInfo == NULL ) { |
| 105 |
continue; |
| 106 |
} |
| 107 |
|
| 108 |
DrawSurfaceForSide( entity, brush, side, side->winding ); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
if ( meta ) { |
| 113 |
ClassifyEntitySurfaces( entity ); |
| 114 |
MakeEntityDecals( entity ); |
| 115 |
MakeEntityMetaTriangles( entity ); |
| 116 |
SmoothMetaTriangles(); |
| 117 |
MergeMetaTriangles(); |
| 118 |
} |
| 119 |
FilterDrawsurfsIntoTree( entity, tree ); |
| 120 |
|
| 121 |
FilterStructuralBrushesIntoTree( entity, tree ); |
| 122 |
FilterDetailBrushesIntoTree( entity, tree ); |
| 123 |
|
| 124 |
EmitBrushes( entity->brushes, &entity->firstBrush, &entity->numBrushes ); |
| 125 |
EndModel( entity, node ); |
| 126 |
} |
| 127 |
EndBSPFile( qfalse, BSPFilePath, surfaceFilePath ); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
mesh_t *TessellatePatch( bspDrawSurface_t *ds ){ |
| 136 |
mesh_t src, *subdivided, *mesh; |
| 137 |
|
| 138 |
src.width = ds->patchWidth; |
| 139 |
src.height = ds->patchHeight; |
| 140 |
src.verts = &bspDrawVerts[ ds->firstVert ]; |
| 141 |
|
| 142 |
subdivided = SubdivideMesh2( src, 8 ); |
| 143 |
PutMeshOnCurve( *subdivided ); |
| 144 |
mesh = RemoveLinearMeshColumnsRows( subdivided ); |
| 145 |
FreeMesh( subdivided ); |
| 146 |
|
| 147 |
return mesh; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
int ConvertBSPMain( int argc, char **argv ){ |
| 157 |
int i; |
| 158 |
int ( *convertFunc )( char * ); |
| 159 |
game_t *convertGame; |
| 160 |
char ext[1024]; |
| 161 |
char BSPFilePath [ 1024 ]; |
| 162 |
char surfaceFilePath [ 1024 ]; |
| 163 |
qboolean map_allowed, force_bsp, force_map; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
convertFunc = ConvertBSPToASE; |
| 168 |
convertGame = NULL; |
| 169 |
map_allowed = qfalse; |
| 170 |
force_bsp = qfalse; |
| 171 |
force_map = qfalse; |
| 172 |
|
| 173 |
|
| 174 |
if ( argc < 2 ) { |
| 175 |
Sys_Printf( "Usage: q3map -convert [-format <ase|obj|gltf|map_bp|map>] [-shadersasbitmap|-lightmapsastexcoord|-deluxemapsastexcoord] [-readbsp|-readmap [-meta|-patchmeta]] [-v] <mapname>\n" ); |
| 176 |
return 0; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
for ( i = 1; i < ( argc - 1 ); i++ ) |
| 181 |
{ |
| 182 |
|
| 183 |
if ( !strcmp( argv[ i ], "-format" ) ) { |
| 184 |
i++; |
| 185 |
if ( !Q_stricmp( argv[ i ], "ase" ) ) { |
| 186 |
convertFunc = ConvertBSPToASE; |
| 187 |
map_allowed = qfalse; |
| 188 |
} |
| 189 |
else if ( !Q_stricmp( argv[ i ], "obj" ) ) { |
| 190 |
convertFunc = ConvertBSPToOBJ; |
| 191 |
map_allowed = qfalse; |
| 192 |
} |
| 193 |
else if ( !Q_stricmp( argv[ i ], "gltf" ) ) { |
| 194 |
convertFunc = ConvertBSPToGLTF; |
| 195 |
map_allowed = qfalse; |
| 196 |
} |
| 197 |
else if ( !Q_stricmp( argv[ i ], "map_bp" ) ) { |
| 198 |
convertFunc = ConvertBSPToMap_BP; |
| 199 |
map_allowed = qtrue; |
| 200 |
} |
| 201 |
else if ( !Q_stricmp( argv[ i ], "map" ) ) { |
| 202 |
convertFunc = ConvertBSPToMap; |
| 203 |
map_allowed = qtrue; |
| 204 |
} |
| 205 |
else |
| 206 |
{ |
| 207 |
convertGame = GetGame( argv[ i ] ); |
| 208 |
map_allowed = qfalse; |
| 209 |
if ( convertGame == NULL ) { |
| 210 |
Sys_FPrintf( SYS_WRN, "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] ); |
| 211 |
} |
| 212 |
} |
| 213 |
} |
| 214 |
else if ( !strcmp( argv[ i ], "-ne" ) ) { |
| 215 |
normalEpsilon = atof( argv[ i + 1 ] ); |
| 216 |
i++; |
| 217 |
Sys_Printf( "Normal epsilon set to %f\n", normalEpsilon ); |
| 218 |
} |
| 219 |
else if ( !strcmp( argv[ i ], "-de" ) ) { |
| 220 |
distanceEpsilon = atof( argv[ i + 1 ] ); |
| 221 |
i++; |
| 222 |
Sys_Printf( "Distance epsilon set to %f\n", distanceEpsilon ); |
| 223 |
} |
| 224 |
else if ( !strcmp( argv[ i ], "-shaderasbitmap" ) || !strcmp( argv[ i ], "-shadersasbitmap" ) ) { |
| 225 |
shadersAsBitmap = qtrue; |
| 226 |
} |
| 227 |
else if ( !strcmp( argv[ i ], "-lightmapastexcoord" ) || !strcmp( argv[ i ], "-lightmapsastexcoord" ) ) { |
| 228 |
lightmapsAsTexcoord = qtrue; |
| 229 |
} |
| 230 |
else if ( !strcmp( argv[ i ], "-deluxemapastexcoord" ) || !strcmp( argv[ i ], "-deluxemapsastexcoord" ) ) { |
| 231 |
lightmapsAsTexcoord = qtrue; |
| 232 |
deluxemap = qtrue; |
| 233 |
} |
| 234 |
else if ( !strcmp( argv[ i ], "-readbsp" ) ) { |
| 235 |
force_bsp = qtrue; |
| 236 |
} |
| 237 |
else if ( !strcmp( argv[ i ], "-readmap" ) ) { |
| 238 |
force_map = qtrue; |
| 239 |
} |
| 240 |
else if ( !strcmp( argv[ i ], "-meta" ) ) { |
| 241 |
meta = qtrue; |
| 242 |
} |
| 243 |
else if ( !strcmp( argv[ i ], "-patchmeta" ) ) { |
| 244 |
meta = qtrue; |
| 245 |
patchMeta = qtrue; |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
LoadShaderInfo(); |
| 250 |
|
| 251 |
|
| 252 |
strcpy( source, ExpandArg( argv[i] ) ); |
| 253 |
ExtractFileExtension( source, ext ); |
| 254 |
|
| 255 |
if ( !map_allowed && !force_map ) { |
| 256 |
force_bsp = qtrue; |
| 257 |
} |
| 258 |
|
| 259 |
if ( force_map || ( !force_bsp && !Q_stricmp( ext, "map" ) && map_allowed ) ) { |
| 260 |
if ( !map_allowed ) { |
| 261 |
Sys_FPrintf( SYS_WRN, "WARNING: the requested conversion should not be done from .map files. Compile a .bsp first.\n" ); |
| 262 |
} |
| 263 |
StripExtension( source ); |
| 264 |
DefaultExtension( source, ".map" ); |
| 265 |
Sys_Printf( "Loading %s\n", source ); |
| 266 |
LoadMapFile( source, qfalse, convertGame == NULL ); |
| 267 |
sprintf( BSPFilePath, "%s.bsp", source ); |
| 268 |
sprintf( surfaceFilePath, "%s.srf", source ); |
| 269 |
PseudoCompileBSP( convertGame != NULL, BSPFilePath, surfaceFilePath ); |
| 270 |
} |
| 271 |
else |
| 272 |
{ |
| 273 |
StripExtension( source ); |
| 274 |
DefaultExtension( source, ".bsp" ); |
| 275 |
Sys_Printf( "Loading %s\n", source ); |
| 276 |
LoadBSPFile( source ); |
| 277 |
ParseEntities(); |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
if ( convertGame != NULL ) { |
| 282 |
|
| 283 |
game = convertGame; |
| 284 |
|
| 285 |
|
| 286 |
StripExtension( source ); |
| 287 |
DefaultExtension( source, "_c.bsp" ); |
| 288 |
Sys_Printf( "Writing %s\n", source ); |
| 289 |
WriteBSPFile( source ); |
| 290 |
|
| 291 |
|
| 292 |
return 0; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
return convertFunc( source ); |
| 297 |
} |