diff --git a/neo/idlib/MapFile.cpp b/neo/idlib/MapFile.cpp index f7ef3189..95b85b26 100644 --- a/neo/idlib/MapFile.cpp +++ b/neo/idlib/MapFile.cpp @@ -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"). diff --git a/neo/tools/compilers/aas/AASBuild.cpp b/neo/tools/compilers/aas/AASBuild.cpp index d294145b..528d407a 100644 --- a/neo/tools/compilers/aas/AASBuild.cpp +++ b/neo/tools/compilers/aas/AASBuild.cpp @@ -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& verts = mapMesh->GetDrawVerts( ); + const idList& 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; diff --git a/neo/tools/compilers/aas/AASBuild_local.h b/neo/tools/compilers/aas/AASBuild_local.h index dd1b42e3..d0907d63 100644 --- a/neo/tools/compilers/aas/AASBuild_local.h +++ b/neo/tools/compilers/aas/AASBuild_local.h @@ -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;