Bumped GLMB_MAGIC and BRM_MAGIC to save the MOC per model data

This commit is contained in:
Robert Beckebans 2024-10-11 15:34:29 +02:00
parent 1dde25ac28
commit b05d296fb6
3 changed files with 100 additions and 76 deletions

View file

@ -4,7 +4,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2014-2016 Kot in Action Creative Artel
Copyright (C) 2012-2021 Robert Beckebans
Copyright (C) 2012-2024 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -44,7 +44,11 @@ idCVar idRenderModelStatic::r_slopVertex( "r_slopVertex", "0.01", CVAR_RENDERER,
idCVar idRenderModelStatic::r_slopTexCoord( "r_slopTexCoord", "0.001", CVAR_RENDERER, "merge texture coordinates this far apart" );
idCVar idRenderModelStatic::r_slopNormal( "r_slopNormal", "0.02", CVAR_RENDERER, "merge normals that dot less than this" );
static const byte BRM_VERSION = 108;
static const byte BRM_VERSION_BFG = 108;
static const byte BRM_VERSION_MOC_DATA = 109;
static const byte BRM_VERSION = BRM_VERSION_MOC_DATA;
static const unsigned int BRM_MAGIC_BFG = ( 'B' << 24 ) | ( 'R' << 16 ) | ( 'M' << 8 ) | BRM_VERSION_BFG;
static const unsigned int BRM_MAGIC = ( 'B' << 24 ) | ( 'R' << 16 ) | ( 'M' << 8 ) | BRM_VERSION;
/*
@ -387,7 +391,7 @@ bool idRenderModelStatic::LoadBinaryModel( idFile* file, const ID_TIME_T sourceT
unsigned int magic = 0;
file->ReadBig( magic );
if( magic != BRM_MAGIC )
if( magic != BRM_MAGIC_BFG && magic != BRM_MAGIC )
{
return false;
}
@ -435,8 +439,11 @@ bool idRenderModelStatic::LoadBinaryModel( idFile* file, const ID_TIME_T sourceT
file->ReadVec3( tri.bounds[0] );
file->ReadVec3( tri.bounds[1] );
int ambientViewCount = 0; // FIXME: remove
file->ReadBig( ambientViewCount );
if( magic == BRM_MAGIC_BFG )
{
int ambientViewCount = 0; // FIXME: remove
file->ReadBig( ambientViewCount );
}
file->ReadBig( tri.generateNormals );
file->ReadBig( tri.tangentsCalculated );
file->ReadBig( tri.perfectHull );
@ -461,25 +468,29 @@ bool idRenderModelStatic::LoadBinaryModel( idFile* file, const ID_TIME_T sourceT
}
}
file->ReadBig( numInFile );
if( numInFile == 0 )
if( magic == BRM_MAGIC_BFG )
{
//tri.preLightShadowVertexes = NULL;
}
else
{
// jmarshall - keep compatibility.
//R_AllocStaticTriSurfPreLightShadowVerts( &tri, numInFile );
//for( int j = 0; j < numInFile; j++ )
//{
// file->ReadVec4( tri.preLightShadowVertexes[ j ].xyzw );
//}
for( int j = 0; j < numInFile; j++ )
// jmarshall - keep compatibility.
file->ReadBig( numInFile );
if( numInFile == 0 )
{
idVec4 stub;
file->ReadVec4( stub );
//tri.preLightShadowVertexes = NULL;
}
// jmarshall end
else
{
//R_AllocStaticTriSurfPreLightShadowVerts( &tri, numInFile );
//for( int j = 0; j < numInFile; j++ )
//{
// file->ReadVec4( tri.preLightShadowVertexes[ j ].xyzw );
//}
for( int j = 0; j < numInFile; j++ )
{
idVec4 stub;
file->ReadVec4( stub );
}
}
// jmarshall end
}
file->ReadBig( tri.numIndexes );
@ -512,21 +523,25 @@ bool idRenderModelStatic::LoadBinaryModel( idFile* file, const ID_TIME_T sourceT
R_AllocStaticTriSurfDupVerts( &tri, tri.numDupVerts );
file->ReadBigArray( tri.dupVerts, tri.numDupVerts * 2 );
}
// jmarshall - keep compatibility.
int numSilEdges = 0;
file->ReadBig( numSilEdges );
if( numSilEdges > 0 )
if( magic == BRM_MAGIC_BFG )
{
for( int j = 0; j < numSilEdges; j++ )
// jmarshall - keep compatibility.
int numSilEdges = 0;
file->ReadBig( numSilEdges );
if( numSilEdges > 0 )
{
triIndex_t stub;
file->ReadBig( stub );
file->ReadBig( stub );
file->ReadBig( stub );
file->ReadBig( stub );
for( int j = 0; j < numSilEdges; j++ )
{
triIndex_t stub;
file->ReadBig( stub );
file->ReadBig( stub );
file->ReadBig( stub );
file->ReadBig( stub );
}
}
// jmarshall end
}
// jmarshall end
file->ReadBig( temp );
tri.dominantTris = NULL;
@ -543,12 +558,39 @@ bool idRenderModelStatic::LoadBinaryModel( idFile* file, const ID_TIME_T sourceT
file->ReadFloat( tri.dominantTris[j].normalizationScale[2] );
}
}
// jmarshall - keep compatibility.
int stub;
file->ReadBig( stub );
file->ReadBig( stub );
file->ReadBig( stub );
// jmarshall end
if( magic == BRM_MAGIC_BFG )
{
// jmarshall - keep compatibility.
int stub;
file->ReadBig( stub );
file->ReadBig( stub );
file->ReadBig( stub );
// jmarshall end
}
// RB: read MOC data
if( magic == BRM_MAGIC )
{
tri.mocVerts = NULL;
tri.mocIndexes = NULL;
if( tri.numVerts > 0 )
{
R_AllocStaticTriSurfMocVerts( &tri, tri.numVerts );
for( int j = 0; j < tri.numVerts; j++ )
{
file->ReadVec4( tri.mocVerts[j] );
}
}
if( tri.numIndexes > 0 )
{
R_AllocStaticTriSurfMocIndexes( &tri, tri.numIndexes );
file->ReadBigArray( tri.mocIndexes, tri.numIndexes );
}
}
// RB end
tri.ambientSurface = NULL;
tri.nextDeferredFree = NULL;
@ -622,8 +664,6 @@ void idRenderModelStatic::WriteBinaryModel( idFile* file, ID_TIME_T* _timeStamp
file->WriteVec3( tri.bounds[0] );
file->WriteVec3( tri.bounds[1] );
int ambientViewCount = 0; // FIXME: remove
file->WriteBig( ambientViewCount );
file->WriteBig( tri.generateNormals );
file->WriteBig( tri.tangentsCalculated );
file->WriteBig( tri.perfectHull );
@ -653,22 +693,6 @@ void idRenderModelStatic::WriteBinaryModel( idFile* file, ID_TIME_T* _timeStamp
}
}
// jmarshall - keep compatibility.
//if( tri.preLightShadowVertexes != NULL )
//{
// file->WriteBig( tri.numVerts * 2 );
// for( int j = 0; j < tri.numVerts * 2; j++ )
// {
// file->WriteVec4( tri.preLightShadowVertexes[ j ].xyzw );
// }
//}
//else
//{
// file->WriteBig( ( int ) 0 );
//}
file->WriteBig( ( int )0 );
// jmarshall end
file->WriteBig( tri.numIndexes );
if( tri.numIndexes > 0 )
@ -702,20 +726,6 @@ void idRenderModelStatic::WriteBinaryModel( idFile* file, ID_TIME_T* _timeStamp
file->WriteBigArray( tri.dupVerts, tri.numDupVerts * 2 );
}
// jmarshall - keep compatibility.
file->WriteBig( ( int ) 0 );
//if( tri.numSilEdges > 0 )
//{
// for( int j = 0; j < tri.numSilEdges; j++ )
// {
// file->WriteBig( tri.silEdges[j].p1 );
// file->WriteBig( tri.silEdges[j].p2 );
// file->WriteBig( tri.silEdges[j].v1 );
// file->WriteBig( tri.silEdges[j].v2 );
// }
//}
// jmarshall end
file->WriteBig( tri.dominantTris != NULL );
if( tri.dominantTris != NULL )
{
@ -729,11 +739,20 @@ void idRenderModelStatic::WriteBinaryModel( idFile* file, ID_TIME_T* _timeStamp
}
}
// jmarshall - keep compatibility.
file->WriteBig( ( int ) 0 ); // tri.numShadowIndexesNoFrontCaps
file->WriteBig( ( int ) 0 ); // tri.numShadowIndexesNoCaps
file->WriteBig( ( int ) 0 ); // tri.shadowCapPlaneBits );
// jmarshall end
// RB: write Masked Occlusion data
if( tri.numVerts > 0 && tri.mocVerts != NULL )
{
for( int j = 0; j < tri.numVerts; j++ )
{
file->WriteVec4( tri.mocVerts[ j ] );
}
}
if( tri.numIndexes > 0 && tri.mocIndexes != NULL )
{
file->WriteBigArray( tri.mocIndexes, tri.numIndexes );
}
// RB end
}
}

View file

@ -49,7 +49,7 @@ idCVar gltf_modelSceneName( "gltf_modelSceneName", "Scene", CVAR_SYSTEM | CVAR_N
idCVar gltf_animSampleRate( "gltf_animSampleRate", "24", CVAR_SYSTEM | CVAR_INTEGER | CVAR_NEW, "The frame rate of the converted md5anim" );
static const byte GLMB_VERSION = 102;
static const byte GLMB_VERSION = 103;
static const unsigned int GLMB_MAGIC = ( 'M' << 24 ) | ( 'L' << 16 ) | ( 'G' << 8 ) | GLMB_VERSION;
static const char* GLTF_SnapshotName = "_GLTF_Snapshot_";
static const idMat4 blenderToDoomTransform( idAngles( 0.0f, 0.0f, 90 ).ToMat3(), vec3_origin );

View file

@ -1628,6 +1628,11 @@ void R_AllocStaticTriSurfDominantTris( srfTriangles_t* tri, int numVerts );
void R_AllocStaticTriSurfMirroredVerts( srfTriangles_t* tri, int numMirroredVerts );
void R_AllocStaticTriSurfDupVerts( srfTriangles_t* tri, int numDupVerts );
// RB begin
void R_AllocStaticTriSurfMocIndexes( srfTriangles_t* tri, int numIndexes );
void R_AllocStaticTriSurfMocVerts( srfTriangles_t* tri, int numVerts );
// RB end
srfTriangles_t* R_CopyStaticTriSurf( const srfTriangles_t* tri );
void R_ResizeStaticTriSurfVerts( srfTriangles_t* tri, int numVerts );