From fbf88ecefbbc49d4b64ba243cf11a191126c60ff Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 20 Dec 2024 15:52:06 +0500 Subject: [PATCH] mbspc: write decent default map220 texdef --- tools/mbspc/mbspc/map.c | 27 ++++++++++++++++++++------- tools/mbspc/mbspc/qbsp.h | 2 +- tools/mbspc/mbspc/textures.c | 6 +++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/tools/mbspc/mbspc/map.c b/tools/mbspc/mbspc/map.c index 0f551129..4832f1ce 100644 --- a/tools/mbspc/mbspc/map.c +++ b/tools/mbspc/mbspc/map.c @@ -684,6 +684,20 @@ get_shader_ptr(int bidx, int sidx) } qboolean g_bsp2map220; + +static void WriteDefaultTexDef( FILE *fp, const vec3_t normal ){ + if( g_bsp2map220 ){ // " [ 1 0 0 0 ] [ 0 1 0 0 ] 0 1 1" + vec3_t vecs[2]; + TextureAxisFromPlane(normal, vecs[0], vecs[1]); + fprintf(fp, " [ %g %g %g 0 ] [ %g %g %g 0 ] 0 1 1", + vecs[0][0], vecs[0][1], vecs[0][2], + vecs[1][0], vecs[1][1], vecs[1][2] ); + } + else{ + fprintf( fp, " 0 0 0 1 1" ); + } +} + //=========================================================================== // // Parameter: - @@ -699,7 +713,6 @@ qboolean WriteMapBrush(FILE *fp, mapbrush_t *brush, vec3_t origin) winding_t *w; side_t *s; plane_t *plane; - const char* defAlign = g_bsp2map220? "[ 1 0 0 0 ] [ 0 1 0 0 ] 0 1 1" : "0 0 0 1 1"; if (noliquids) { @@ -796,7 +809,7 @@ qboolean WriteMapBrush(FILE *fp, mapbrush_t *brush, vec3_t origin) Log_Write("brush->contents = %d\n", brush->contents); } - fprintf( fp, " %s", defAlign ); + WriteDefaultTexDef( fp, plane->normal ); if ( loadedmaptype == MAPTYPE_QUAKE3 ) fprintf( fp, " 0 0 0" ); @@ -816,7 +829,7 @@ qboolean WriteMapBrush(FILE *fp, mapbrush_t *brush, vec3_t origin) fprintf(fp, "generic/misc/red"); } - fprintf( fp, " %s", defAlign ); + WriteDefaultTexDef( fp, plane->normal ); } else if (loadedmaptype == MAPTYPE_QUAKE3) { @@ -847,7 +860,8 @@ qboolean WriteMapBrush(FILE *fp, mapbrush_t *brush, vec3_t origin) } } - fprintf( fp, " %s 0 0 0", defAlign ); + WriteDefaultTexDef( fp, plane->normal ); + fprintf( fp, " 0 0 0" ); } else @@ -858,7 +872,7 @@ qboolean WriteMapBrush(FILE *fp, mapbrush_t *brush, vec3_t origin) scale[0] = 1 / VectorNormalize2(ti->vecs[0], vecs[0]); scale[1] = 1 / VectorNormalize2(ti->vecs[1], vecs[1]); // - TextureAxisFromPlane(plane, axis[0], axis[1]); + TextureAxisFromPlane(plane->normal, axis[0], axis[1]); //calculate texture shift done by entity origin originshift[0] = DotProduct(origin, axis[0]); originshift[1] = DotProduct(origin, axis[1]); @@ -926,7 +940,6 @@ qboolean WriteOriginBrush(FILE *fp, vec3_t origin) float dist; int i, s; winding_t *w; - const char* defAlign = g_bsp2map220? "[ 1 0 0 0 ] [ 0 1 0 0 ] 0 1 1" : "0 0 0 1 1"; fprintf(fp, " {\n"); // @@ -966,7 +979,7 @@ qboolean WriteOriginBrush(FILE *fp, vec3_t origin) fprintf(fp, "origin"); } - fprintf( fp, " %s", defAlign ); + WriteDefaultTexDef(fp, normal); if ( loadedmaptype == MAPTYPE_QUAKE3 ) fprintf( fp, " 0 0 0" ); diff --git a/tools/mbspc/mbspc/qbsp.h b/tools/mbspc/mbspc/qbsp.h index 4bd3d8c7..afa2ad04 100644 --- a/tools/mbspc/mbspc/qbsp.h +++ b/tools/mbspc/mbspc/qbsp.h @@ -423,7 +423,7 @@ extern textureref_t textureref[MAX_MAP_TEXTURES]; int FindMiptex(char *name); int TexinfoForBrushTexture(plane_t *plane, brush_texture_t *bt, vec3_t origin); -void TextureAxisFromPlane(plane_t *pln, vec3_t xv, vec3_t yv); +void TextureAxisFromPlane(const vec3_t normal, vec3_t xv, vec3_t yv); //============================================================================= // csg diff --git a/tools/mbspc/mbspc/textures.c b/tools/mbspc/mbspc/textures.c index 3921f52f..69f2c4ea 100644 --- a/tools/mbspc/mbspc/textures.c +++ b/tools/mbspc/mbspc/textures.c @@ -82,7 +82,7 @@ vec3_t baseaxis[18] = {0,-1,0}, {1,0,0}, {0,0,-1} // north wall }; -void TextureAxisFromPlane(plane_t *pln, vec3_t xv, vec3_t yv) +void TextureAxisFromPlane(const vec3_t normal, vec3_t xv, vec3_t yv) { int bestaxis; vec_t dot,best; @@ -93,7 +93,7 @@ void TextureAxisFromPlane(plane_t *pln, vec3_t xv, vec3_t yv) for (i=0 ; i<6 ; i++) { - dot = DotProduct (pln->normal, baseaxis[i*3]); + dot = DotProduct (normal, baseaxis[i*3]); if (dot > best) { best = dot; @@ -128,7 +128,7 @@ int TexinfoForBrushTexture(plane_t *plane, brush_texture_t *bt, vec3_t origin) memset (&tx, 0, sizeof(tx)); strcpy (tx.texture, bt->name); - TextureAxisFromPlane(plane, vecs[0], vecs[1]); + TextureAxisFromPlane(plane->normal, vecs[0], vecs[1]); shift[0] = DotProduct (origin, vecs[0]); shift[1] = DotProduct (origin, vecs[1]);