AAS support for MapPolygonMehses

This commit is contained in:
HarrievG 2022-08-03 02:14:06 +02:00
parent b6bccf19d0
commit 7e7ee22f3b
3 changed files with 120 additions and 0 deletions

View file

@ -5,6 +5,7 @@ Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2015-2022 Robert Beckebans
Copyright (C) 2020 Admer (id Tech Fox)
Copyright (C) 2022 Harrie van Ginneken
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").

View file

@ -3,6 +3,8 @@
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
Copyright (C) 2022 Harrie van Ginneken
Copyright (C) 2022 Robert Beckebans
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
@ -417,6 +419,115 @@ idBrushList idAASBuild::AddBrushesForMapBrush( const idMapBrush* mapBrush, const
return brushList;
}
/*
============
idAASBuild::AddBrushesForMapPolygonMesh
============
*/
idBrushList idAASBuild::AddBrushesForMapPolygonMesh( const MapPolygonMesh* mapMesh, const idVec3& origin, const idMat3& axis, int entityNum, int primitiveNum, idBrushList brushList )
{
int contents = 0;
int validBrushes = 0;
idFixedWinding w;
idPlane plane;
idVec3 d1, d2;
idBrush* brush;
const idMaterial* mat;
//per map polygon
for( int p = 0 ; p < mapMesh->GetNumPolygons(); p++ )
{
const MapPolygon& face = mapMesh->GetFace( p );
mat = declManager->FindMaterial( face.GetMaterial() );
contents = ContentsForAAS( mat->GetContentFlags( ) );
if( !contents )
{
return brushList;
}
const idList<idDrawVert>& verts = mapMesh->GetDrawVerts( );
const idList<int>& indices = face.GetIndexes( );
idVec3 triNormal;
int v1 = 0;
int v2 = 1;
int v3 = 2;
//create brush with 2 triangles
// 1 frontface from the mappoly verts
// 1 backface, offset in direction off frontface normal at unit distance
//Front face
d1 = verts[indices[1]].xyz - verts[indices[0]].xyz;
d2 = verts[indices[2]].xyz - verts[indices[0]].xyz;
plane.SetNormal( d1.Cross( d2 ) );
if( plane.Normalize( ) != 0.0f )
{
plane.FitThroughPoint( verts[indices[2]].xyz );
w.Clear( );
w += verts[indices[0]].xyz;
w += verts[indices[1]].xyz;
w += verts[indices[2]].xyz;
brush = new idBrush( );
brush->SetContents( contents );
if( brush->FromWinding( w, plane ) )
{
brush->SetEntityNum( entityNum );
brush->SetPrimitiveNum( primitiveNum );
brush->SetFlag( BFL_PATCH );
brush->Transform( origin, axis );
brushList.AddToTail( brush );
validBrushes++;
}
else
{
delete brush;
}
}
//Back face
triNormal = plane.Normal();
plane.SetNormal( d2.Cross( d1 ) );
if( plane.Normalize( ) != 0.0f )
{
plane.FitThroughPoint( verts[indices[0]].xyz );
w.Clear( );
w += verts[indices[2]].xyz + triNormal;
w += verts[indices[1]].xyz + triNormal;
w += verts[indices[0]].xyz + triNormal;
brush = new idBrush( );
brush->SetContents( contents );
if( brush->FromWinding( w, plane ) )
{
brush->SetEntityNum( entityNum );
brush->SetPrimitiveNum( primitiveNum );
brush->SetFlag( BFL_PATCH );
brush->Transform( origin, axis );
brushList.AddToTail( brush );
validBrushes++;
}
else
{
delete brush;
}
}
}
if( !validBrushes )
{
common->Warning( "map polygon primitive %d on entity %d is completely degenerate", primitiveNum, entityNum );
}
return brushList;
}
/*
============
@ -613,6 +724,11 @@ idBrushList idAASBuild::AddBrushesForMapEntity( const idMapEntity* mapEnt, int e
}
continue;
}
//HVG: Map polygon mesh support
if( mapPrim->GetType( ) == idMapPrimitive::TYPE_MESH )
{
brushList = AddBrushesForMapPolygonMesh( static_cast< MapPolygonMesh* >( mapPrim ), origin, axis, entityNum, i, brushList );
}
}
return brushList;

View file

@ -3,6 +3,8 @@
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
Copyright (C) 2022 Harrie van Ginneken
Copyright (C) 2022 Robert Beckebans
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
@ -104,6 +106,7 @@ private: // map loading
int ContentsForAAS( int contents );
idBrushList AddBrushesForMapBrush( const idMapBrush* mapBrush, const idVec3& origin, const idMat3& axis, int entityNum, int primitiveNum, idBrushList brushList );
idBrushList AddBrushesForMapPatch( const idMapPatch* mapPatch, const idVec3& origin, const idMat3& axis, int entityNum, int primitiveNum, idBrushList brushList );
idBrushList AddBrushesForMapPolygonMesh( const MapPolygonMesh* mapMesh, const idVec3& origin, const idMat3& axis, int entityNum, int primitiveNum, idBrushList brushList );
idBrushList AddBrushesForMapEntity( const idMapEntity* mapEnt, int entityNum, idBrushList brushList );
idBrushList AddBrushesForMapFile( const idMapFile* mapFile, idBrushList brushList );
bool CheckForEntities( const idMapFile* mapFile, idStrList& entityClassNames ) const;