std::vector<bspDrawVert_t> bspDrawVerts
This commit is contained in:
parent
560060a908
commit
c58bd839da
|
|
@ -122,10 +122,10 @@ static void ProcessAdvertisements( void ) {
|
|||
|
||||
// store the ad quad for quick use at run time
|
||||
if ( adSurface.surfaceType == MST_PATCH ) {
|
||||
int v0 = adSurface.firstVert + adSurface.patchHeight - 1;
|
||||
int v1 = adSurface.firstVert + adSurface.numVerts - 1;
|
||||
int v2 = adSurface.firstVert + adSurface.numVerts - adSurface.patchWidth;
|
||||
int v3 = adSurface.firstVert;
|
||||
const int v0 = adSurface.firstVert + adSurface.patchHeight - 1;
|
||||
const int v1 = adSurface.firstVert + adSurface.numVerts - 1;
|
||||
const int v2 = adSurface.firstVert + adSurface.numVerts - adSurface.patchWidth;
|
||||
const int v3 = adSurface.firstVert;
|
||||
bspAds[numBSPAds].rect[0] = bspDrawVerts[v0].xyz;
|
||||
bspAds[numBSPAds].rect[1] = bspDrawVerts[v1].xyz;
|
||||
bspAds[numBSPAds].rect[2] = bspDrawVerts[v2].xyz;
|
||||
|
|
|
|||
|
|
@ -53,44 +53,6 @@
|
|||
|
||||
/* FIXME: remove the functions below that handle memory management of bsp file chunks */
|
||||
|
||||
int numBSPDrawVertsBuffer = 0;
|
||||
void IncDrawVerts(){
|
||||
numBSPDrawVerts++;
|
||||
|
||||
if ( bspDrawVerts == 0 ) {
|
||||
numBSPDrawVertsBuffer = 1024;
|
||||
|
||||
bspDrawVerts = safe_malloc_info( sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer, "IncDrawVerts" );
|
||||
|
||||
}
|
||||
else if ( numBSPDrawVerts > numBSPDrawVertsBuffer ) {
|
||||
bspDrawVert_t *newBspDrawVerts;
|
||||
|
||||
numBSPDrawVertsBuffer *= 3; // multiply by 1.5
|
||||
numBSPDrawVertsBuffer /= 2;
|
||||
|
||||
newBspDrawVerts = void_ptr( realloc( bspDrawVerts, sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer ) );
|
||||
|
||||
if ( !newBspDrawVerts ) {
|
||||
free (bspDrawVerts);
|
||||
Error( "realloc() failed (IncDrawVerts)" );
|
||||
}
|
||||
|
||||
bspDrawVerts = newBspDrawVerts;
|
||||
}
|
||||
|
||||
memset( bspDrawVerts + ( numBSPDrawVerts - 1 ), 0, sizeof( bspDrawVert_t ) );
|
||||
}
|
||||
|
||||
void SetDrawVerts( int n ){
|
||||
free( bspDrawVerts );
|
||||
|
||||
numBSPDrawVerts =
|
||||
numBSPDrawVertsBuffer = n;
|
||||
|
||||
bspDrawVerts = safe_calloc_info( sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer, "IncDrawVerts" );
|
||||
}
|
||||
|
||||
int numBSPDrawSurfacesBuffer = 0;
|
||||
void SetDrawSurfacesBuffer(){
|
||||
free( bspDrawSurfaces );
|
||||
|
|
@ -110,7 +72,7 @@ void SetDrawSurfaces( int n ){
|
|||
}
|
||||
|
||||
void BSPFilesCleanup(){
|
||||
free( bspDrawVerts );
|
||||
bspDrawVerts.clear();
|
||||
free( bspDrawSurfaces );
|
||||
bspLightBytes.clear();
|
||||
bspGridPoints.clear();
|
||||
|
|
@ -209,20 +171,20 @@ void SwapBSPFile( void ){
|
|||
( (int*) bspVisBytes.data() )[ 1 ] = LittleLong( ( (int*) bspVisBytes.data() )[ 1 ] );
|
||||
|
||||
/* drawverts (don't swap colors) */
|
||||
for ( i = 0; i < numBSPDrawVerts; i++ )
|
||||
for ( bspDrawVert_t& v : bspDrawVerts )
|
||||
{
|
||||
bspDrawVerts[ i ].xyz[ 0 ] = LittleFloat( bspDrawVerts[ i ].xyz[ 0 ] );
|
||||
bspDrawVerts[ i ].xyz[ 1 ] = LittleFloat( bspDrawVerts[ i ].xyz[ 1 ] );
|
||||
bspDrawVerts[ i ].xyz[ 2 ] = LittleFloat( bspDrawVerts[ i ].xyz[ 2 ] );
|
||||
bspDrawVerts[ i ].normal[ 0 ] = LittleFloat( bspDrawVerts[ i ].normal[ 0 ] );
|
||||
bspDrawVerts[ i ].normal[ 1 ] = LittleFloat( bspDrawVerts[ i ].normal[ 1 ] );
|
||||
bspDrawVerts[ i ].normal[ 2 ] = LittleFloat( bspDrawVerts[ i ].normal[ 2 ] );
|
||||
bspDrawVerts[ i ].st[ 0 ] = LittleFloat( bspDrawVerts[ i ].st[ 0 ] );
|
||||
bspDrawVerts[ i ].st[ 1 ] = LittleFloat( bspDrawVerts[ i ].st[ 1 ] );
|
||||
for ( j = 0; j < MAX_LIGHTMAPS; j++ )
|
||||
v.xyz[ 0 ] = LittleFloat( v.xyz[ 0 ] );
|
||||
v.xyz[ 1 ] = LittleFloat( v.xyz[ 1 ] );
|
||||
v.xyz[ 2 ] = LittleFloat( v.xyz[ 2 ] );
|
||||
v.normal[ 0 ] = LittleFloat( v.normal[ 0 ] );
|
||||
v.normal[ 1 ] = LittleFloat( v.normal[ 1 ] );
|
||||
v.normal[ 2 ] = LittleFloat( v.normal[ 2 ] );
|
||||
v.st[ 0 ] = LittleFloat( v.st[ 0 ] );
|
||||
v.st[ 1 ] = LittleFloat( v.st[ 1 ] );
|
||||
for ( Vector2& lm : v.lightmap )
|
||||
{
|
||||
bspDrawVerts[ i ].lightmap[ j ][ 0 ] = LittleFloat( bspDrawVerts[ i ].lightmap[ j ][ 0 ] );
|
||||
bspDrawVerts[ i ].lightmap[ j ][ 1 ] = LittleFloat( bspDrawVerts[ i ].lightmap[ j ][ 1 ] );
|
||||
lm[ 0 ] = LittleFloat( lm[ 0 ] );
|
||||
lm[ 1 ] = LittleFloat( lm[ 1 ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -496,8 +458,8 @@ void PrintBSPFileSizes( void ){
|
|||
planarCount );
|
||||
Sys_Printf( "%9d trisoup surfaces\n",
|
||||
trisoupCount );
|
||||
Sys_Printf( "%9d drawverts %9d *\n",
|
||||
numBSPDrawVerts, (int) ( numBSPDrawVerts * sizeof( *bspDrawVerts ) ) );
|
||||
Sys_Printf( "%9zu drawverts %9zu *\n",
|
||||
bspDrawVerts.size(), bspDrawVerts.size() * sizeof( bspDrawVerts[0] ) );
|
||||
Sys_Printf( "%9d drawindexes %9d\n",
|
||||
numBSPDrawIndexes, (int) ( numBSPDrawIndexes * sizeof( *bspDrawIndexes ) ) );
|
||||
Sys_Printf( "\n" );
|
||||
|
|
|
|||
|
|
@ -228,67 +228,25 @@ struct ibspDrawVert_t
|
|||
Vector2 lightmap;
|
||||
Vector3 normal;
|
||||
Color4b color;
|
||||
ibspDrawVert_t( const bspDrawVert_t& other ) :
|
||||
xyz( other.xyz ),
|
||||
st( other.st ),
|
||||
lightmap( other.lightmap[0] ),
|
||||
normal( other.normal ),
|
||||
color( other.color[0] ) {}
|
||||
operator bspDrawVert_t() {
|
||||
static_assert( MAX_LIGHTMAPS == 4 );
|
||||
return {
|
||||
xyz,
|
||||
st,
|
||||
{ lightmap, Vector2( 0, 0 ), Vector2( 0, 0 ), Vector2( 0, 0 ) },
|
||||
normal,
|
||||
{ color, Color4b( 0, 0, 0, 0 ), Color4b( 0, 0, 0, 0 ), Color4b( 0, 0, 0, 0 ) }
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static void CopyDrawVertsLump( ibspHeader_t *header ){
|
||||
int i;
|
||||
ibspDrawVert_t *in;
|
||||
bspDrawVert_t *out;
|
||||
|
||||
|
||||
/* get count */
|
||||
numBSPDrawVerts = GetLumpElements( (bspHeader_t*) header, LUMP_DRAWVERTS, sizeof( *in ) );
|
||||
SetDrawVerts( numBSPDrawVerts );
|
||||
|
||||
/* copy */
|
||||
in = GetLump( (bspHeader_t*) header, LUMP_DRAWVERTS );
|
||||
out = bspDrawVerts;
|
||||
for ( i = 0; i < numBSPDrawVerts; i++ )
|
||||
{
|
||||
out->xyz = in->xyz;
|
||||
out->st = in->st;
|
||||
out->lightmap[ 0 ] = in->lightmap;
|
||||
out->normal = in->normal;
|
||||
out->color[ 0 ] = in->color;
|
||||
in++;
|
||||
out++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void AddDrawVertsLump( FILE *file, ibspHeader_t *header ){
|
||||
int i, size;
|
||||
bspDrawVert_t *in;
|
||||
ibspDrawVert_t *buffer, *out;
|
||||
|
||||
|
||||
/* allocate output buffer */
|
||||
size = numBSPDrawVerts * sizeof( *buffer );
|
||||
buffer = safe_calloc( size );
|
||||
|
||||
/* convert */
|
||||
in = bspDrawVerts;
|
||||
out = buffer;
|
||||
for ( i = 0; i < numBSPDrawVerts; i++ )
|
||||
{
|
||||
out->xyz = in->xyz;
|
||||
out->st = in->st;
|
||||
out->lightmap = in->lightmap[ 0 ];
|
||||
out->normal = in->normal;
|
||||
out->color = in->color[ 0 ];
|
||||
in++;
|
||||
out++;
|
||||
}
|
||||
|
||||
/* write lump */
|
||||
AddLump( file, (bspHeader_t*) header, LUMP_DRAWVERTS, buffer, size );
|
||||
|
||||
/* free buffer */
|
||||
free( buffer );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* light grid */
|
||||
struct ibspGridPoint_t
|
||||
|
|
@ -355,7 +313,7 @@ void LoadIBSPFile( const char *filename ){
|
|||
|
||||
CopyLump<bspBrushSide_t, ibspBrushSide_t>( (bspHeader_t*) header, LUMP_BRUSHSIDES, bspBrushSides );
|
||||
|
||||
CopyDrawVertsLump( header );
|
||||
CopyLump<bspDrawVert_t, ibspDrawVert_t>( (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts );
|
||||
|
||||
CopyDrawSurfacesLump( header );
|
||||
|
||||
|
|
@ -462,7 +420,7 @@ void WriteIBSPFile( const char *filename ){
|
|||
AddLump( file, header->lumps[LUMP_LEAFSURFACES], bspLeafSurfaces );
|
||||
AddLump( file, header->lumps[LUMP_LEAFBRUSHES], bspLeafBrushes );
|
||||
AddLump( file, header->lumps[LUMP_MODELS], bspModels );
|
||||
AddDrawVertsLump( file, header );
|
||||
AddLump( file, header->lumps[LUMP_DRAWVERTS], std::vector<ibspDrawVert_t>( bspDrawVerts.begin(), bspDrawVerts.end() ) );
|
||||
AddDrawSurfacesLump( file, header );
|
||||
AddLump( file, header->lumps[LUMP_VISIBILITY], bspVisBytes );
|
||||
AddLump( file, header->lumps[LUMP_LIGHTMAPS], bspLightBytes );
|
||||
|
|
|
|||
|
|
@ -215,9 +215,7 @@ void LoadRBSPFile( const char *filename ){
|
|||
|
||||
CopyLump( (bspHeader_t*) header, LUMP_BRUSHSIDES, bspBrushSides );
|
||||
|
||||
numBSPDrawVerts = GetLumpElements( (bspHeader_t*) header, LUMP_DRAWVERTS, sizeof( bspDrawVerts[ 0 ] ) );
|
||||
SetDrawVerts( numBSPDrawVerts );
|
||||
CopyLump( (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts, sizeof( bspDrawVerts[ 0 ] ) );
|
||||
CopyLump( (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts );
|
||||
|
||||
numBSPDrawSurfaces = GetLumpElements( (bspHeader_t*) header, LUMP_SURFACES, sizeof( bspDrawSurfaces[ 0 ] ) );
|
||||
SetDrawSurfaces( numBSPDrawSurfaces );
|
||||
|
|
@ -284,7 +282,7 @@ void WriteRBSPFile( const char *filename ){
|
|||
AddLump( file, header->lumps[LUMP_LEAFSURFACES], bspLeafSurfaces );
|
||||
AddLump( file, header->lumps[LUMP_LEAFBRUSHES], bspLeafBrushes );
|
||||
AddLump( file, header->lumps[LUMP_MODELS], bspModels );
|
||||
AddLump( file, (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts, numBSPDrawVerts * sizeof( bspDrawVerts[ 0 ] ) );
|
||||
AddLump( file, header->lumps[LUMP_DRAWVERTS], bspDrawVerts );
|
||||
AddLump( file, (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces, numBSPDrawSurfaces * sizeof( bspDrawSurfaces[ 0 ] ) );
|
||||
AddLump( file, header->lumps[LUMP_VISIBILITY], bspVisBytes );
|
||||
AddLump( file, header->lumps[LUMP_LIGHTMAPS], bspLightBytes );
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@
|
|||
int numLightmapsASE = 0;
|
||||
|
||||
static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const std::vector<int>& lmIndices ){
|
||||
int i, v, face, a, b, c;
|
||||
bspDrawVert_t *dv;
|
||||
int i, face, a, b, c;
|
||||
char name[ 1024 ];
|
||||
|
||||
|
||||
|
|
@ -87,9 +86,8 @@ static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int sur
|
|||
fprintf( f, "\t\t*MESH_VERTEX_LIST\t{\r\n" );
|
||||
for ( i = 0; i < ds->numVerts; i++ )
|
||||
{
|
||||
v = i + ds->firstVert;
|
||||
dv = &bspDrawVerts[ v ];
|
||||
fprintf( f, "\t\t\t*MESH_VERTEX\t%d\t%f\t%f\t%f\r\n", i, dv->xyz[ 0 ], dv->xyz[ 1 ], dv->xyz[ 2 ] );
|
||||
const bspDrawVert_t& dv = bspDrawVerts[ ds->firstVert + i ];
|
||||
fprintf( f, "\t\t\t*MESH_VERTEX\t%d\t%f\t%f\t%f\r\n", i, dv.xyz[ 0 ], dv.xyz[ 1 ], dv.xyz[ 2 ] );
|
||||
}
|
||||
fprintf( f, "\t\t}\r\n" );
|
||||
|
||||
|
|
@ -111,13 +109,12 @@ static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int sur
|
|||
fprintf( f, "\t\t*MESH_TVERTLIST\t{\r\n" );
|
||||
for ( i = 0; i < ds->numVerts; i++ )
|
||||
{
|
||||
v = i + ds->firstVert;
|
||||
dv = &bspDrawVerts[ v ];
|
||||
const bspDrawVert_t& dv = bspDrawVerts[ ds->firstVert + i ];
|
||||
if ( lightmapsAsTexcoord ) {
|
||||
fprintf( f, "\t\t\t*MESH_TVERT\t%d\t%f\t%f\t%f\r\n", i, dv->lightmap[0][0], ( 1.0 - dv->lightmap[0][1] ), 1.0f ); // dv->lightmap[0][1] internal, ( 1.0 - dv->lightmap[0][1] ) external
|
||||
fprintf( f, "\t\t\t*MESH_TVERT\t%d\t%f\t%f\t%f\r\n", i, dv.lightmap[0][0], ( 1.0 - dv.lightmap[0][1] ), 1.0f ); // dv.lightmap[0][1] internal, ( 1.0 - dv.lightmap[0][1] ) external
|
||||
}
|
||||
else{
|
||||
fprintf( f, "\t\t\t*MESH_TVERT\t%d\t%f\t%f\t%f\r\n", i, dv->st[ 0 ], ( 1.0 - dv->st[ 1 ] ), 1.0f );
|
||||
fprintf( f, "\t\t\t*MESH_TVERT\t%d\t%f\t%f\t%f\r\n", i, dv.st[ 0 ], ( 1.0 - dv.st[ 1 ] ), 1.0f );
|
||||
}
|
||||
}
|
||||
fprintf( f, "\t\t}\r\n" );
|
||||
|
|
@ -146,8 +143,8 @@ static void ConvertSurface( FILE *f, int modelNum, bspDrawSurface_t *ds, int sur
|
|||
const Vector3 normal = VectorNormalized( bspDrawVerts[ a ].normal + bspDrawVerts[ b ].normal + bspDrawVerts[ c ].normal );
|
||||
fprintf( f, "\t\t\t*MESH_FACENORMAL\t%d\t%f\t%f\t%f\r\n", face, normal[ 0 ], normal[ 1 ], normal[ 2 ] );
|
||||
for( const auto idx : { a, b, c } ){
|
||||
dv = &bspDrawVerts[ idx ];
|
||||
fprintf( f, "\t\t\t\t*MESH_VERTEXNORMAL\t%d\t%f\t%f\t%f\r\n", idx, dv->normal[ 0 ], dv->normal[ 1 ], dv->normal[ 2 ] );
|
||||
const bspDrawVert_t& dv = bspDrawVerts[ idx ];
|
||||
fprintf( f, "\t\t\t\t*MESH_VERTEXNORMAL\t%d\t%f\t%f\t%f\r\n", idx, dv.normal[ 0 ], dv.normal[ 1 ], dv.normal[ 2 ] );
|
||||
}
|
||||
}
|
||||
fprintf( f, "\t\t}\r\n" );
|
||||
|
|
|
|||
|
|
@ -500,8 +500,8 @@ int ScaleBSPMain( Args& args ){
|
|||
|
||||
if ( texscale ) {
|
||||
Sys_Printf( "Using texture unlocking (and probably breaking texture alignment a lot)\n" );
|
||||
old_xyzst = safe_malloc( sizeof( *old_xyzst ) * numBSPDrawVerts * 5 );
|
||||
for ( i = 0; i < numBSPDrawVerts; i++ )
|
||||
old_xyzst = safe_malloc( sizeof( *old_xyzst ) * bspDrawVerts.size() * 5 );
|
||||
for ( size_t i = 0; i < bspDrawVerts.size(); i++ )
|
||||
{
|
||||
old_xyzst[5 * i + 0] = bspDrawVerts[i].xyz[0];
|
||||
old_xyzst[5 * i + 1] = bspDrawVerts[i].xyz[1];
|
||||
|
|
@ -512,11 +512,11 @@ int ScaleBSPMain( Args& args ){
|
|||
}
|
||||
|
||||
/* scale drawverts */
|
||||
for ( i = 0; i < numBSPDrawVerts; i++ )
|
||||
for ( bspDrawVert_t& vert : bspDrawVerts )
|
||||
{
|
||||
bspDrawVerts[i].xyz *= scale;
|
||||
bspDrawVerts[i].normal /= scale;
|
||||
VectorNormalize( bspDrawVerts[i].normal );
|
||||
vert.xyz *= scale;
|
||||
vert.normal /= scale;
|
||||
VectorNormalize( vert.normal );
|
||||
}
|
||||
|
||||
if ( texscale ) {
|
||||
|
|
@ -530,9 +530,11 @@ int ScaleBSPMain( Args& args ){
|
|||
}
|
||||
for ( j = bspDrawSurfaces[i].firstIndex; j < bspDrawSurfaces[i].firstIndex + bspDrawSurfaces[i].numIndexes; j += 3 )
|
||||
{
|
||||
int ia = bspDrawIndexes[j] + bspDrawSurfaces[i].firstVert, ib = bspDrawIndexes[j + 1] + bspDrawSurfaces[i].firstVert, ic = bspDrawIndexes[j + 2] + bspDrawSurfaces[i].firstVert;
|
||||
bspDrawVert_t *a = &bspDrawVerts[ia], *b = &bspDrawVerts[ib], *c = &bspDrawVerts[ic];
|
||||
float *oa = &old_xyzst[ia * 5], *ob = &old_xyzst[ib * 5], *oc = &old_xyzst[ic * 5];
|
||||
const int ia = bspDrawIndexes[j] + bspDrawSurfaces[i].firstVert,
|
||||
ib = bspDrawIndexes[j + 1] + bspDrawSurfaces[i].firstVert,
|
||||
ic = bspDrawIndexes[j + 2] + bspDrawSurfaces[i].firstVert;
|
||||
bspDrawVert_t &a = bspDrawVerts[ia], &b = bspDrawVerts[ib], &c = bspDrawVerts[ic];
|
||||
const float *oa = &old_xyzst[ia * 5], *ob = &old_xyzst[ib * 5], *oc = &old_xyzst[ic * 5];
|
||||
// extrapolate:
|
||||
// a->xyz -> oa
|
||||
// b->xyz -> ob
|
||||
|
|
@ -541,9 +543,9 @@ int ScaleBSPMain( Args& args ){
|
|||
&oa[0], &oa[3],
|
||||
&ob[0], &ob[3],
|
||||
&oc[0], &oc[3],
|
||||
a->xyz, a->st,
|
||||
b->xyz, b->st,
|
||||
c->xyz, c->st );
|
||||
a.xyz, a.st,
|
||||
b.xyz, b.st,
|
||||
c.xyz, c.st );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -596,7 +598,6 @@ int ScaleBSPMain( Args& args ){
|
|||
*/
|
||||
|
||||
int ShiftBSPMain( Args& args ){
|
||||
int i;
|
||||
Vector3 shift;
|
||||
Vector3 vec;
|
||||
char str[ 1024 ];
|
||||
|
|
@ -668,9 +669,9 @@ int ShiftBSPMain( Args& args ){
|
|||
}
|
||||
|
||||
/* shift drawverts */
|
||||
for ( i = 0; i < numBSPDrawVerts; i++ )
|
||||
for ( bspDrawVert_t& vert : bspDrawVerts )
|
||||
{
|
||||
bspDrawVerts[i].xyz += shift;
|
||||
vert.xyz += shift;
|
||||
}
|
||||
|
||||
/* shift planes */
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ static void write_json( const char *directory ){
|
|||
}
|
||||
{
|
||||
doc.RemoveAllMembers();
|
||||
for_indexed( auto&& vert : Span( bspDrawVerts, numBSPDrawVerts ) ){
|
||||
for_indexed( const auto& vert : bspDrawVerts ){
|
||||
rapidjson::Value value( rapidjson::kObjectType );
|
||||
value.AddMember( "xyz", value_for( vert.xyz, all ), all );
|
||||
value.AddMember( "st", value_for( vert.st, all ), all );
|
||||
|
|
@ -466,17 +466,14 @@ static void read_json( const char *directory ){
|
|||
}
|
||||
{
|
||||
const auto doc = load_json( StringOutputStream( 256 )( directory, "DrawVert.json" ) );
|
||||
static std::vector<bspDrawVert_t> items;
|
||||
for( auto&& obj : doc.GetObj() ){
|
||||
auto&& item = items.emplace_back();
|
||||
auto&& item = bspDrawVerts.emplace_back();
|
||||
value_to( obj.value["xyz"], item.xyz );
|
||||
value_to( obj.value["st"], item.st );
|
||||
value_to( obj.value["lightmap"], item.lightmap );
|
||||
value_to( obj.value["normal"], item.normal );
|
||||
value_to( obj.value["color"], item.color );
|
||||
}
|
||||
bspDrawVerts = items.data();
|
||||
numBSPDrawVerts = items.size();
|
||||
}
|
||||
{
|
||||
const auto doc = load_json( StringOutputStream( 256 )( directory, "DrawSurfaces.json" ) );
|
||||
|
|
|
|||
|
|
@ -47,13 +47,13 @@ static float Det3x3( float a00, float a01, float a02,
|
|||
+ a02 * ( a10 * a21 - a11 * a20 );
|
||||
}
|
||||
|
||||
void GetBestSurfaceTriangleMatchForBrushside( const side_t& buildSide, bspDrawVert_t *bestVert[3] ){
|
||||
void GetBestSurfaceTriangleMatchForBrushside( const side_t& buildSide, const bspDrawVert_t *bestVert[3] ){
|
||||
bspDrawSurface_t *s;
|
||||
int i;
|
||||
int t;
|
||||
float best = 0;
|
||||
float thisarea;
|
||||
bspDrawVert_t *vert[3];
|
||||
const bspDrawVert_t *vert[3];
|
||||
const plane_t& buildPlane = mapplanes[buildSide.planenum];
|
||||
int matches = 0;
|
||||
|
||||
|
|
@ -405,7 +405,7 @@ static void ConvertBrush( FILE *f, int num, const bspBrush_t& brush, const Vecto
|
|||
// - meshverts point in pairs of three into verts
|
||||
// - (triangles)
|
||||
// - find the triangle that has most in common with our
|
||||
bspDrawVert_t *vert[3];
|
||||
const bspDrawVert_t *vert[3];
|
||||
GetBestSurfaceTriangleMatchForBrushside( buildSide, vert );
|
||||
|
||||
/* get texture name */
|
||||
|
|
@ -746,12 +746,6 @@ for ( i = 0; i < brush->numSides; i++ )
|
|||
*/
|
||||
|
||||
static void ConvertPatch( FILE *f, int num, const bspDrawSurface_t& ds, const Vector3& origin ){
|
||||
int x, y;
|
||||
bspShader_t *shader;
|
||||
const char *texture;
|
||||
bspDrawVert_t *dv;
|
||||
|
||||
|
||||
/* only patches */
|
||||
if ( ds.surfaceType != MST_PATCH ) {
|
||||
return;
|
||||
|
|
@ -761,14 +755,15 @@ static void ConvertPatch( FILE *f, int num, const bspDrawSurface_t& ds, const Ve
|
|||
if ( ds.shaderNum < 0 || ds.shaderNum >= int( bspShaders.size() ) ) {
|
||||
return;
|
||||
}
|
||||
shader = &bspShaders[ ds.shaderNum ];
|
||||
|
||||
/* get texture name */
|
||||
if ( striEqualPrefix( shader->shader, "textures/" ) ) {
|
||||
texture = shader->shader + 9;
|
||||
const char *texture;
|
||||
if ( const bspShader_t& shader = bspShaders[ ds.shaderNum ];
|
||||
striEqualPrefix( shader.shader, "textures/" ) ) {
|
||||
texture = shader.shader + 9;
|
||||
}
|
||||
else{
|
||||
texture = shader->shader;
|
||||
texture = shader.shader;
|
||||
}
|
||||
|
||||
/* start patch */
|
||||
|
|
@ -781,22 +776,22 @@ static void ConvertPatch( FILE *f, int num, const bspDrawSurface_t& ds, const Ve
|
|||
fprintf( f, "\t\t\t(\n" );
|
||||
|
||||
/* iterate through the verts */
|
||||
for ( x = 0; x < ds.patchWidth; x++ )
|
||||
for ( int x = 0; x < ds.patchWidth; x++ )
|
||||
{
|
||||
/* start row */
|
||||
fprintf( f, "\t\t\t\t(" );
|
||||
|
||||
/* iterate through the row */
|
||||
for ( y = 0; y < ds.patchHeight; y++ )
|
||||
for ( int y = 0; y < ds.patchHeight; y++ )
|
||||
{
|
||||
/* get vert */
|
||||
dv = &bspDrawVerts[ ds.firstVert + ( y * ds.patchWidth ) + x ];
|
||||
const bspDrawVert_t& dv = bspDrawVerts[ ds.firstVert + ( y * ds.patchWidth ) + x ];
|
||||
|
||||
/* offset it */
|
||||
const Vector3 xyz = dv->xyz + origin;
|
||||
const Vector3 xyz = dv.xyz + origin;
|
||||
|
||||
/* print vertex */
|
||||
fprintf( f, " ( %f %f %f %f %f )", xyz[ 0 ], xyz[ 1 ], xyz[ 2 ], dv->st[ 0 ], dv->st[ 1 ] );
|
||||
fprintf( f, " ( %f %f %f %f %f )", xyz[ 0 ], xyz[ 1 ], xyz[ 2 ], dv.st[ 0 ], dv.st[ 1 ] );
|
||||
}
|
||||
|
||||
/* end row */
|
||||
|
|
|
|||
|
|
@ -45,8 +45,7 @@ int objVertexCount = 0;
|
|||
int objLastShaderNum = -1;
|
||||
|
||||
static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, int surfaceNum, const Vector3& origin, const std::vector<int>& lmIndices ){
|
||||
int i, v, a, b, c;
|
||||
bspDrawVert_t *dv;
|
||||
int i, a, b, c;
|
||||
|
||||
/* ignore patches for now */
|
||||
if ( ds->surfaceType != MST_PLANAR && ds->surfaceType != MST_TRIANGLE_SOUP ) {
|
||||
|
|
@ -91,16 +90,15 @@ static void ConvertSurfaceToOBJ( FILE *f, int modelNum, bspDrawSurface_t *ds, in
|
|||
/* export vertex */
|
||||
for ( i = 0; i < ds->numVerts; i++ )
|
||||
{
|
||||
v = i + ds->firstVert;
|
||||
dv = &bspDrawVerts[ v ];
|
||||
const bspDrawVert_t& dv = bspDrawVerts[ ds->firstVert + i ];
|
||||
fprintf( f, "# vertex %d\r\n", i + objVertexCount + 1 );
|
||||
fprintf( f, "v %f %f %f\r\n", dv->xyz[ 0 ], dv->xyz[ 2 ], -dv->xyz[ 1 ] );
|
||||
fprintf( f, "vn %f %f %f\r\n", dv->normal[ 0 ], dv->normal[ 2 ], -dv->normal[ 1 ] );
|
||||
fprintf( f, "v %f %f %f\r\n", dv.xyz[ 0 ], dv.xyz[ 2 ], -dv.xyz[ 1 ] );
|
||||
fprintf( f, "vn %f %f %f\r\n", dv.normal[ 0 ], dv.normal[ 2 ], -dv.normal[ 1 ] );
|
||||
if ( lightmapsAsTexcoord ) {
|
||||
fprintf( f, "vt %f %f\r\n", dv->lightmap[0][0], ( 1.0 - dv->lightmap[0][1] ) ); // dv->lightmap[0][1] internal, ( 1.0 - dv->lightmap[0][1] ) external
|
||||
fprintf( f, "vt %f %f\r\n", dv.lightmap[0][0], ( 1.0 - dv.lightmap[0][1] ) ); // dv.lightmap[0][1] internal, ( 1.0 - dv.lightmap[0][1] ) external
|
||||
}
|
||||
else{
|
||||
fprintf( f, "vt %f %f\r\n", dv->st[ 0 ], ( 1.0 - dv->st[ 1 ] ) );
|
||||
fprintf( f, "vt %f %f\r\n", dv.st[ 0 ], ( 1.0 - dv.st[ 1 ] ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -564,8 +564,8 @@ void SetEntityOrigins( void ){
|
|||
|
||||
|
||||
/* ydnar: copy drawverts into private storage for nefarious purposes */
|
||||
yDrawVerts = safe_malloc( numBSPDrawVerts * sizeof( bspDrawVert_t ) );
|
||||
memcpy( yDrawVerts, bspDrawVerts, numBSPDrawVerts * sizeof( bspDrawVert_t ) );
|
||||
yDrawVerts = safe_malloc( bspDrawVerts.size() * sizeof( bspDrawVert_t ) );
|
||||
memcpy( yDrawVerts, bspDrawVerts.data(), bspDrawVerts.size() * sizeof( bspDrawVert_t ) );
|
||||
|
||||
/* set the entity origins */
|
||||
for ( const auto& e : entities )
|
||||
|
|
|
|||
|
|
@ -161,6 +161,7 @@ void SmoothNormals( void ){
|
|||
float shadeAngle, defaultShadeAngle, maxShadeAngle;
|
||||
int indexes[ MAX_SAMPLES ];
|
||||
Vector3 votes[ MAX_SAMPLES ];
|
||||
const int numBSPDrawVerts = bspDrawVerts.size();
|
||||
|
||||
|
||||
/* allocate shade angle table */
|
||||
|
|
|
|||
|
|
@ -1149,8 +1149,8 @@ void SetupSurfaceLightmaps( void ){
|
|||
/* allocate vertex luxel storage */
|
||||
for ( k = 0; k < MAX_LIGHTMAPS; k++ )
|
||||
{
|
||||
vertexLuxels[ k ] = safe_calloc( numBSPDrawVerts * sizeof( *vertexLuxels[ 0 ] ) );
|
||||
radVertexLuxels[ k ] = safe_calloc( numBSPDrawVerts * sizeof( *radVertexLuxels[ 0 ] ) );
|
||||
vertexLuxels[ k ] = safe_calloc( bspDrawVerts.size() * sizeof( *vertexLuxels[ 0 ] ) );
|
||||
radVertexLuxels[ k ] = safe_calloc( bspDrawVerts.size() * sizeof( *radVertexLuxels[ 0 ] ) );
|
||||
}
|
||||
|
||||
/* emit some stats */
|
||||
|
|
|
|||
|
|
@ -1845,8 +1845,6 @@ shaderInfo_t *ShaderInfoForShaderNull( const char *shader );
|
|||
|
||||
/* bspfile_abstract.c */
|
||||
void SetGridPoints( int n );
|
||||
void SetDrawVerts( int n );
|
||||
void IncDrawVerts();
|
||||
void SetDrawSurfaces( int n );
|
||||
void SetDrawSurfacesBuffer();
|
||||
void BSPFilesCleanup();
|
||||
|
|
@ -2360,8 +2358,7 @@ Q_EXTERN std::vector<bspGridPoint_t> bspGridPoints;
|
|||
|
||||
Q_EXTERN std::vector<byte> bspVisBytes; // MAX_MAP_VISIBILITY
|
||||
|
||||
Q_EXTERN int numBSPDrawVerts Q_ASSIGN( 0 );
|
||||
Q_EXTERN bspDrawVert_t *bspDrawVerts Q_ASSIGN( NULL );
|
||||
Q_EXTERN std::vector<bspDrawVert_t> bspDrawVerts;
|
||||
|
||||
Q_EXTERN int numBSPDrawIndexes Q_ASSIGN( 0 );
|
||||
Q_EXTERN int allocatedBSPDrawIndexes Q_ASSIGN( 0 );
|
||||
|
|
|
|||
|
|
@ -2035,45 +2035,34 @@ static int FilterFlareSurfIntoTree( mapDrawSurface_t *ds, tree_t& tree ){
|
|||
emits bsp drawverts from a map drawsurface
|
||||
*/
|
||||
|
||||
void EmitDrawVerts( mapDrawSurface_t *ds, bspDrawSurface_t *out ){
|
||||
int i, k;
|
||||
bspDrawVert_t *dv;
|
||||
shaderInfo_t *si;
|
||||
float offset;
|
||||
|
||||
|
||||
void EmitDrawVerts( const mapDrawSurface_t *ds, bspDrawSurface_t *out ){
|
||||
/* get stuff */
|
||||
si = ds->shaderInfo;
|
||||
offset = si->offset;
|
||||
const float offset = ds->shaderInfo->offset;
|
||||
|
||||
/* copy the verts */
|
||||
out->firstVert = numBSPDrawVerts;
|
||||
out->firstVert = bspDrawVerts.size();
|
||||
out->numVerts = ds->numVerts;
|
||||
for ( i = 0; i < ds->numVerts; i++ )
|
||||
for ( int i = 0; i < ds->numVerts; i++ )
|
||||
{
|
||||
/* allocate a new vert */
|
||||
IncDrawVerts();
|
||||
dv = &bspDrawVerts[ numBSPDrawVerts - 1 ];
|
||||
|
||||
/* copy it */
|
||||
memcpy( dv, &ds->verts[ i ], sizeof( *dv ) );
|
||||
/* allocate a new vert */ /* copy it */
|
||||
bspDrawVert_t& dv = bspDrawVerts.emplace_back( ds->verts[ i ] );
|
||||
|
||||
/* offset? */
|
||||
if ( offset != 0.0f ) {
|
||||
dv->xyz += dv->normal * offset;
|
||||
dv.xyz += dv.normal * offset;
|
||||
}
|
||||
|
||||
/* expand model bounds
|
||||
necessary because of misc_model surfaces on entities
|
||||
note: does not happen on worldspawn as its bounds is only used for determining lightgrid bounds */
|
||||
if ( bspModels.size() > 1 ) {
|
||||
bspModels.back().minmax.extend( dv->xyz );
|
||||
bspModels.back().minmax.extend( dv.xyz );
|
||||
}
|
||||
|
||||
/* debug color? */
|
||||
if ( debugSurfaces ) {
|
||||
for ( k = 0; k < MAX_LIGHTMAPS; k++ )
|
||||
dv->color[ k ].rgb() = debugColors[ ( ds - mapDrawSurfs ) % 12 ];
|
||||
for ( int k = 0; k < MAX_LIGHTMAPS; k++ )
|
||||
dv.color[ k ].rgb() = debugColors[ ( ds - mapDrawSurfs ) % 12 ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user