1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 ----------------------------------------------------------------------------------
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
27 ------------------------------------------------------------------------------- */
46 #define SNAP_FLOAT_TO_INT 4
47 #define SNAP_INT_TO_FLOAT (1.0 / SNAP_FLOAT_TO_INT)
49 typedef vec_t vec2_t[2];
51 static vec_t Det3x3(vec_t a00, vec_t a01, vec_t a02,
52 vec_t a10, vec_t a11, vec_t a12,
53 vec_t a20, vec_t a21, vec_t a22)
56 a00 * (a11 * a22 - a12 * a21)
57 - a01 * (a10 * a22 - a12 * a20)
58 + a02 * (a10 * a21 - a11 * a20);
61 void GetBestSurfaceTriangleMatchForBrushside(side_t *buildSide, bspDrawVert_t *bestVert[3])
69 vec3_t v1v0, v2v0, norm;
70 bspDrawVert_t *vert[3];
72 plane_t *buildPlane = &mapplanes[buildSide->planenum];
75 // first, start out with NULLs
76 bestVert[0] = bestVert[1] = bestVert[2] = NULL;
78 // brute force through all surfaces
79 for(s = bspDrawSurfaces; s != bspDrawSurfaces + numBSPDrawSurfaces; ++s)
81 if(s->surfaceType != MST_PLANAR && s->surfaceType != MST_TRIANGLE_SOUP)
83 if(strcmp(buildSide->shaderInfo->shader, bspShaders[s->shaderNum].shader))
85 for(t = 0; t + 3 <= s->numIndexes; t += 3)
87 vert[0] = &bspDrawVerts[s->firstVert + bspDrawIndexes[s->firstIndex + t + 0]];
88 vert[1] = &bspDrawVerts[s->firstVert + bspDrawIndexes[s->firstIndex + t + 1]];
89 vert[2] = &bspDrawVerts[s->firstVert + bspDrawIndexes[s->firstIndex + t + 2]];
90 if(s->surfaceType == MST_PLANAR)
92 VectorSubtract(vert[0]->normal, buildPlane->normal, normdiff); if(VectorLength(normdiff) >= normalEpsilon) continue;
93 VectorSubtract(vert[1]->normal, buildPlane->normal, normdiff); if(VectorLength(normdiff) >= normalEpsilon) continue;
94 VectorSubtract(vert[2]->normal, buildPlane->normal, normdiff); if(VectorLength(normdiff) >= normalEpsilon) continue;
98 // this is more prone to roundoff errors, but with embedded
99 // models, there is no better way
100 VectorSubtract(vert[1]->xyz, vert[0]->xyz, v1v0);
101 VectorSubtract(vert[2]->xyz, vert[0]->xyz, v2v0);
102 CrossProduct(v2v0, v1v0, norm);
103 VectorNormalize(norm, norm);
104 VectorSubtract(norm, buildPlane->normal, normdiff); if(VectorLength(normdiff) >= normalEpsilon) continue;
106 if(abs(DotProduct(vert[0]->xyz, buildPlane->normal) - buildPlane->dist) >= distanceEpsilon) continue;
107 if(abs(DotProduct(vert[1]->xyz, buildPlane->normal) - buildPlane->dist) >= distanceEpsilon) continue;
108 if(abs(DotProduct(vert[2]->xyz, buildPlane->normal) - buildPlane->dist) >= distanceEpsilon) continue;
109 // Okay. Correct surface type, correct shader, correct plane. Let's start with the business...
110 polygon = CopyWinding(buildSide->winding);
111 for(i = 0; i < 3; ++i)
116 vec3_t *v1 = &vert[(i+1)%3]->xyz;
117 vec3_t *v2 = &vert[(i+2)%3]->xyz;
120 vec3_t sideDirection;
121 // we now need to generate triNormal and triDist so that they represent the plane spanned by normal and (v2 - v1).
122 VectorSubtract(*v2, *v1, sideDirection);
123 CrossProduct(sideDirection, buildPlane->normal, triNormal);
124 triDist = DotProduct(*v1, triNormal);
125 ChopWindingInPlace(&polygon, triNormal, triDist, distanceEpsilon);
129 thisarea = WindingArea(polygon);
135 bestVert[0] = vert[0];
136 bestVert[1] = vert[1];
137 bestVert[2] = vert[2];
139 FreeWinding(polygon);
144 //if(strncmp(buildSide->shaderInfo->shader, "textures/common/", 16))
145 // fprintf(stderr, "brushside with %s: %d matches (%f area)\n", buildSide->shaderInfo->shader, matches, best);
148 static void ConvertOriginBrush( FILE *f, int num, vec3_t origin )
150 char pattern[6][5][3] = {
151 { "+++", "+-+", "-++", " - ", "- " },
152 { "+++", "-++", "++-", "+ ", " +" },
153 { "+++", "++-", "+-+", " - ", " +" },
154 { "---", "+--", "-+-", " - ", "+ " },
155 { "---", "--+", "+--", "- ", " +" },
156 { "---", "-+-", "--+", " + ", " +" }
159 #define S(a,b,c) (pattern[a][b][c] == '+' ? +1 : pattern[a][b][c] == '-' ? -1 : 0)
160 #define FRAC(x) ((x) - floor(x))
163 fprintf( f, "\t// brush %d\n", num );
164 fprintf( f, "\t{\n" );
165 fprintf( f, "\tbrushDef\n" );
166 fprintf( f, "\t{\n" );
167 /* print brush side */
168 /* ( 640 24 -224 ) ( 448 24 -224 ) ( 448 -232 -224 ) common/caulk 0 48 0 0.500000 0.500000 0 0 0 */
170 for(i = 0; i < 6; ++i)
171 fprintf( f, "\t\t( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( ( %.8f %.8f %.8f ) ( %.8f %.8f %.8f ) ) %s %d 0 0\n",
172 origin[0] + 8 * S(i,0,0), origin[1] + 8 * S(i,0,1), origin[2] + 8 * S(i,0,2),
173 origin[0] + 8 * S(i,1,0), origin[1] + 8 * S(i,1,1), origin[2] + 8 * S(i,1,2),
174 origin[0] + 8 * S(i,2,0), origin[1] + 8 * S(i,2,1), origin[2] + 8 * S(i,2,2),
175 1/16.0, 0.0, FRAC((S(i,3,0) * origin[0] + S(i,3,1) * origin[1] + S(i,3,2) * origin[2]) / 16.0 + 0.5),
176 0.0, 1/16.0, FRAC((S(i,4,0) * origin[0] + S(i,4,1) * origin[1] + S(i,4,2) * origin[2]) / 16.0 + 0.5),
184 fprintf( f, "\t}\n" );
185 fprintf( f, "\t}\n\n" );
188 static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, vec3_t origin, qboolean brushPrimitives )
191 bspBrushSide_t *side;
198 bspDrawVert_t *vert[3];
203 fprintf( f, "\t// brush %d\n", num );
204 fprintf( f, "\t{\n" );
207 fprintf( f, "\tbrushDef\n" );
208 fprintf( f, "\t{\n" );
211 /* clear out build brush */
212 for( i = 0; i < buildBrush->numsides; i++ )
214 buildSide = &buildBrush->sides[ i ];
215 if( buildSide->winding != NULL )
217 FreeWinding( buildSide->winding );
218 buildSide->winding = NULL;
221 buildBrush->numsides = 0;
223 /* iterate through bsp brush sides */
224 for( i = 0; i < brush->numSides; i++ )
227 side = &bspBrushSides[ brush->firstSide + i ];
230 if( side->shaderNum < 0 || side->shaderNum >= numBSPShaders )
232 shader = &bspShaders[ side->shaderNum ];
233 if( !Q_stricmp( shader->shader, "default" ) || !Q_stricmp( shader->shader, "noshader" ) )
237 plane = &bspPlanes[ side->planeNum ];
240 buildSide = &buildBrush->sides[ buildBrush->numsides ];
241 buildBrush->numsides++;
244 buildSide->shaderInfo = ShaderInfoForShader( shader->shader );
245 buildSide->planenum = side->planeNum;
246 buildSide->winding = NULL;
249 /* make brush windings */
250 if( !CreateBrushWindings( buildBrush ) )
253 /* iterate through build brush sides */
254 for( i = 0; i < buildBrush->numsides; i++ )
257 buildSide = &buildBrush->sides[ i ];
260 buildPlane = &mapplanes[ buildSide->planenum ];
263 if( buildSide->shaderInfo == NULL || buildSide->winding == NULL )
266 // st-texcoords -> texMat block
267 // start out with dummy
268 VectorSet(buildSide->texMat[0], 1/32.0, 0, 0);
269 VectorSet(buildSide->texMat[1], 0, 1/32.0, 0);
271 // find surface for this side (by brute force)
273 // - meshverts point in pairs of three into verts
275 // - find the triangle that has most in common with our side
276 GetBestSurfaceTriangleMatchForBrushside(buildSide, vert);
279 /* get texture name */
280 if( !Q_strncasecmp( buildSide->shaderInfo->shader, "textures/", 9 ) )
281 texture = buildSide->shaderInfo->shader + 9;
283 texture = buildSide->shaderInfo->shader;
285 /* get plane points and offset by origin */
286 for( j = 0; j < 3; j++ )
288 VectorAdd( buildSide->winding->p[ j ], origin, pts[ j ] );
289 //% pts[ j ][ 0 ] = SNAP_INT_TO_FLOAT * floor( pts[ j ][ 0 ] * SNAP_FLOAT_TO_INT + 0.5f );
290 //% pts[ j ][ 1 ] = SNAP_INT_TO_FLOAT * floor( pts[ j ][ 1 ] * SNAP_FLOAT_TO_INT + 0.5f );
291 //% pts[ j ][ 2 ] = SNAP_INT_TO_FLOAT * floor( pts[ j ][ 2 ] * SNAP_FLOAT_TO_INT + 0.5f );
294 if(vert[0] && vert[1] && vert[2])
300 vec2_t xyI, xyJ, xyK;
301 vec2_t stI, stJ, stK;
304 ComputeAxisBase(buildPlane->normal, texX, texY);
306 Vector2Set(xyI, DotProduct(vert[0]->xyz, texX), DotProduct(vert[0]->xyz, texY));
307 Vector2Set(xyJ, DotProduct(vert[1]->xyz, texX), DotProduct(vert[1]->xyz, texY));
308 Vector2Set(xyK, DotProduct(vert[2]->xyz, texX), DotProduct(vert[2]->xyz, texY));
309 stI[0] = vert[0]->st[0]; stI[1] = vert[0]->st[1];
310 stJ[0] = vert[1]->st[0]; stJ[1] = vert[1]->st[1];
311 stK[0] = vert[2]->st[0]; stK[1] = vert[2]->st[1];
313 // - solve linear equations:
314 // - (x, y) := xyz . (texX, texY)
315 // - st[i] = texMat[i][0]*x + texMat[i][1]*y + texMat[i][2]
316 // (for three vertices)
324 for(i = 0; i < 2; ++i)
337 xyI[0], xyI[1], stI[i],
338 xyJ[0], xyJ[1], stJ[i],
339 xyK[0], xyK[1], stK[i]
341 VectorSet(buildSide->texMat[i], D0 / D, D1 / D, D2 / D);
346 fprintf(stderr, "degenerate triangle found when solving texMat equations for\n(%f %f %f) (%f %f %f) (%f %f %f)\n( %f %f %f )\n( %f %f %f ) -> ( %f %f )\n( %f %f %f ) -> ( %f %f )\n( %f %f %f ) -> ( %f %f )\n",
347 buildPlane->normal[0], buildPlane->normal[1], buildPlane->normal[2],
348 vert[0]->normal[0], vert[0]->normal[1], vert[0]->normal[2],
349 texX[0], texX[1], texX[2], texY[0], texY[1], texY[2],
350 vert[0]->xyz[0], vert[0]->xyz[1], vert[0]->xyz[2], xyI[0], xyI[1],
351 vert[1]->xyz[0], vert[1]->xyz[1], vert[1]->xyz[2], xyJ[0], xyJ[1],
352 vert[2]->xyz[0], vert[2]->xyz[1], vert[2]->xyz[2], xyK[0], xyK[1]
355 /* print brush side */
356 /* ( 640 24 -224 ) ( 448 24 -224 ) ( 448 -232 -224 ) common/caulk 0 48 0 0.500000 0.500000 0 0 0 */
357 fprintf( f, "\t\t( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( ( %.8f %.8f %.8f ) ( %.8f %.8f %.8f ) ) %s %d 0 0\n",
358 pts[ 0 ][ 0 ], pts[ 0 ][ 1 ], pts[ 0 ][ 2 ],
359 pts[ 1 ][ 0 ], pts[ 1 ][ 1 ], pts[ 1 ][ 2 ],
360 pts[ 2 ][ 0 ], pts[ 2 ][ 1 ], pts[ 2 ][ 2 ],
361 buildSide->texMat[0][0], buildSide->texMat[0][1], buildSide->texMat[0][2],
362 buildSide->texMat[1][0], buildSide->texMat[1][1], buildSide->texMat[1][2],
364 // DEBUG: valid ? 0 : C_DETAIL
370 // invert QuakeTextureVecs
373 vec2_t stI, stJ, stK;
374 vec3_t xyzI, xyzJ, xyzK;
380 TextureAxisFromPlane(buildPlane, vecs[0], vecs[1]);
394 stI[0] = vert[0]->st[0] * si->shaderWidth; stI[1] = vert[0]->st[1] * si->shaderHeight;
395 stJ[0] = vert[1]->st[0] * si->shaderWidth; stJ[1] = vert[1]->st[1] * si->shaderHeight;
396 stK[0] = vert[2]->st[0] * si->shaderWidth; stK[1] = vert[2]->st[1] * si->shaderHeight;
399 vert[0]->xyz[sv], vert[0]->xyz[tv], 1,
400 vert[1]->xyz[sv], vert[1]->xyz[tv], 1,
401 vert[2]->xyz[sv], vert[2]->xyz[tv], 1
405 for(i = 0; i < 2; ++i)
408 stI[i], vert[0]->xyz[tv], 1,
409 stJ[i], vert[1]->xyz[tv], 1,
410 stK[i], vert[2]->xyz[tv], 1
413 vert[0]->xyz[sv], stI[i], 1,
414 vert[1]->xyz[sv], stJ[i], 1,
415 vert[2]->xyz[sv], stK[i], 1
418 vert[0]->xyz[sv], vert[0]->xyz[tv], stI[i],
419 vert[1]->xyz[sv], vert[1]->xyz[tv], stJ[i],
420 vert[2]->xyz[sv], vert[2]->xyz[tv], stK[i]
422 VectorSet(sts[i], D0 / D, D1 / D, D2 / D);
427 fprintf(stderr, "degenerate triangle found when solving texDef equations\n"); // FIXME add stuff here
429 // now we must solve:
430 // // now we must invert:
431 // ang = rotate / 180 * Q_PI;
434 // ns = cosv * vecs[0][sv];
435 // nt = sinv * vecs[0][sv];
436 // vecsrotscaled[0][sv] = ns / scale[0];
437 // vecsrotscaled[0][tv] = nt / scale[0];
438 // ns = -sinv * vecs[1][tv];
439 // nt = cosv * vecs[1][tv];
440 // vecsrotscaled[1][sv] = ns / scale[1];
441 // vecsrotscaled[1][tv] = nt / scale[1];
442 scale[0] = sqrt(sts[0][0] * sts[0][0] + sts[0][1] * sts[0][1]);
443 scale[1] = sqrt(sts[1][0] * sts[1][0] + sts[1][1] * sts[1][1]);
444 rotate = atan2(sts[0][1] - sts[1][0], sts[0][0] + sts[1][1]);
445 shift[0] = sts[0][2];
446 shift[1] = sts[1][2];
448 /* print brush side */
449 /* ( 640 24 -224 ) ( 448 24 -224 ) ( 448 -232 -224 ) common/caulk 0 48 0 0.500000 0.500000 0 0 0 */
450 fprintf( f, "\t\t( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) %.8f %.8f %.8f %.8f %.8f %s %d 0 0\n",
451 pts[ 0 ][ 0 ], pts[ 0 ][ 1 ], pts[ 0 ][ 2 ],
452 pts[ 1 ][ 0 ], pts[ 1 ][ 1 ], pts[ 1 ][ 2 ],
453 pts[ 2 ][ 0 ], pts[ 2 ][ 1 ], pts[ 2 ][ 2 ],
454 shift[0], shift[1], rotate, scale[0], scale[1],
456 // DEBUG: valid ? 0 : C_DETAIL
462 if(strncmp(buildSide->shaderInfo->shader, "textures/common/", 16))
463 fprintf(stderr, "no matching triangle for brushside using %s (hopefully nobody can see this side anyway)\n", buildSide->shaderInfo->shader);
469 fprintf( f, "\t}\n" );
471 fprintf( f, "\t}\n\n" );
475 /* iterate through the brush sides (ignore the first 6 bevel planes) */
476 for( i = 0; i < brush->numSides; i++ )
479 side = &bspBrushSides[ brush->firstSide + i ];
482 if( side->shaderNum < 0 || side->shaderNum >= numBSPShaders )
484 shader = &bspShaders[ side->shaderNum ];
485 if( !Q_stricmp( shader->shader, "default" ) || !Q_stricmp( shader->shader, "noshader" ) )
488 /* get texture name */
489 if( !Q_strncasecmp( shader->shader, "textures/", 9 ) )
490 texture = shader->shader + 9;
492 texture = shader->shader;
495 plane = &bspPlanes[ side->planeNum ];
497 /* make plane points */
502 MakeNormalVectors( plane->normal, vecs[ 0 ], vecs[ 1 ] );
503 VectorMA( vec3_origin, plane->dist, plane->normal, pts[ 0 ] );
504 VectorMA( pts[ 0 ], 256.0f, vecs[ 0 ], pts[ 1 ] );
505 VectorMA( pts[ 0 ], 256.0f, vecs[ 1 ], pts[ 2 ] );
508 /* offset by origin */
509 for( j = 0; j < 3; j++ )
510 VectorAdd( pts[ j ], origin, pts[ j ] );
512 /* print brush side */
513 /* ( 640 24 -224 ) ( 448 24 -224 ) ( 448 -232 -224 ) common/caulk 0 48 0 0.500000 0.500000 0 0 0 */
514 fprintf( f, "\t\t( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) %s 0 0 0 0.5 0.5 0 0 0\n",
515 pts[ 0 ][ 0 ], pts[ 0 ][ 1 ], pts[ 0 ][ 2 ],
516 pts[ 1 ][ 0 ], pts[ 1 ][ 1 ], pts[ 1 ][ 2 ],
517 pts[ 2 ][ 0 ], pts[ 2 ][ 1 ], pts[ 2 ][ 2 ],
526 converts a bsp patch to a map patch
534 ( ( 168 168 -192 0 2 ) ( 168 168 -64 0 1 ) ( 168 168 64 0 0 ) ... )
542 static void ConvertPatch( FILE *f, int num, bspDrawSurface_t *ds, vec3_t origin )
552 if( ds->surfaceType != MST_PATCH )
556 if( ds->shaderNum < 0 || ds->shaderNum >= numBSPShaders )
558 shader = &bspShaders[ ds->shaderNum ];
560 /* get texture name */
561 if( !Q_strncasecmp( shader->shader, "textures/", 9 ) )
562 texture = shader->shader + 9;
564 texture = shader->shader;
567 fprintf( f, "\t// patch %d\n", num );
568 fprintf( f, "\t{\n" );
569 fprintf( f, "\t\tpatchDef2\n" );
570 fprintf( f, "\t\t{\n" );
571 fprintf( f, "\t\t\t%s\n", texture );
572 fprintf( f, "\t\t\t( %d %d 0 0 0 )\n", ds->patchWidth, ds->patchHeight );
573 fprintf( f, "\t\t\t(\n" );
575 /* iterate through the verts */
576 for( x = 0; x < ds->patchWidth; x++ )
579 fprintf( f, "\t\t\t\t(" );
581 /* iterate through the row */
582 for( y = 0; y < ds->patchHeight; y++ )
585 dv = &bspDrawVerts[ ds->firstVert + (y * ds->patchWidth) + x ];
588 VectorAdd( origin, dv->xyz, xyz );
591 fprintf( f, " ( %f %f %f %f %f )", xyz[ 0 ], xyz[ 1 ], xyz[ 2 ], dv->st[ 0 ], dv->st[ 1 ] );
595 fprintf( f, " )\n" );
599 fprintf( f, "\t\t\t)\n" );
600 fprintf( f, "\t\t}\n" );
601 fprintf( f, "\t}\n\n" );
608 exports a bsp model to a map file
611 static void ConvertModel( FILE *f, bspModel_t *model, int modelNum, vec3_t origin, qboolean brushPrimitives )
615 bspDrawSurface_t *ds;
618 /* convert bsp planes to map planes */
619 nummapplanes = numBSPPlanes;
620 AUTOEXPAND_BY_REALLOC(mapplanes, nummapplanes, allocatedmapplanes, 1024);
621 for( i = 0; i < numBSPPlanes; i++ )
623 VectorCopy( bspPlanes[ i ].normal, mapplanes[ i ].normal );
624 mapplanes[ i ].dist = bspPlanes[ i ].dist;
625 mapplanes[ i ].type = PlaneTypeForNormal( mapplanes[ i ].normal );
626 mapplanes[ i ].hash_chain = 0;
629 /* allocate a build brush */
630 buildBrush = AllocBrush( 512 );
631 buildBrush->entityNum = 0;
632 buildBrush->original = buildBrush;
634 if(origin[0] != 0 || origin[1] != 0 || origin[2] != 0)
635 ConvertOriginBrush(f, -1, origin);
637 /* go through each brush in the model */
638 for( i = 0; i < model->numBSPBrushes; i++ )
640 num = i + model->firstBSPBrush;
641 brush = &bspBrushes[ num ];
642 ConvertBrush( f, num, brush, origin, brushPrimitives );
645 /* free the build brush */
648 /* go through each drawsurf in the model */
649 for( i = 0; i < model->numBSPSurfaces; i++ )
651 num = i + model->firstBSPSurface;
652 ds = &bspDrawSurfaces[ num ];
654 /* we only love patches */
655 if( ds->surfaceType == MST_PATCH )
656 ConvertPatch( f, num, ds, origin );
664 exports entity key/value pairs to a map file
667 static void ConvertEPairs( FILE *f, entity_t *e, qboolean skip_origin )
673 for( ep = e->epairs; ep != NULL; ep = ep->next )
675 /* ignore empty keys/values */
676 if( ep->key[ 0 ] == '\0' || ep->value[ 0 ] == '\0' )
679 /* ignore model keys with * prefixed values */
680 if( !Q_stricmp( ep->key, "model" ) && ep->value[ 0 ] == '*' )
683 /* ignore origin keys if skip_origin is set */
684 if( skip_origin && !Q_stricmp( ep->key, "origin" ) )
688 fprintf( f, "\t\"%s\" \"%s\"\n", ep->key, ep->value );
696 exports an quake map file from the bsp
699 int ConvertBSPToMap_Ext( char *bspName, qboolean brushPrimitives )
707 char name[ 1024 ], base[ 1024 ];
711 Sys_Printf( "--- Convert BSP to MAP ---\n" );
713 /* create the bsp filename from the bsp name */
714 strcpy( name, bspName );
715 StripExtension( name );
716 strcat( name, "_converted.map" );
717 Sys_Printf( "writing %s\n", name );
719 ExtractFileBase( bspName, base );
720 strcat( base, ".bsp" );
723 f = fopen( name, "wb" );
725 Error( "Open failed on %s\n", name );
728 fprintf( f, "// Generated by Q3Map2 (ydnar) -convert -format map\n" );
730 /* walk entity list */
731 for( i = 0; i < numEntities; i++ )
737 fprintf( f, "// entity %d\n", i );
745 value = ValueForKey( e, "model" );
746 if( value[ 0 ] == '*' )
747 modelNum = atoi( value + 1 );
753 ConvertEPairs( f, e, modelNum >= 0 );
756 /* only handle bsp models */
760 model = &bspModels[ modelNum ];
762 /* get entity origin */
763 value = ValueForKey( e, "origin" );
764 if( value[ 0 ] == '\0' )
765 VectorClear( origin );
767 GetVectorForKey( e, "origin", origin );
770 ConvertModel( f, model, modelNum, origin, brushPrimitives );
774 fprintf( f, "}\n\n" );
777 /* close the file and return */
780 /* return to sender */
784 int ConvertBSPToMap( char *bspName )
786 return ConvertBSPToMap(bspName, qfalse);
789 int ConvertBSPToMap_BP( char *bspName )
791 return ConvertBSPToMap(bspName, qtrue);