Fixed bug in convertMapToValve220 cmd. Added origin brushes

This commit is contained in:
Robert Beckebans 2023-10-17 21:57:57 +02:00
parent 11d78d37be
commit def152081d
3 changed files with 95 additions and 14 deletions

View file

@ -3,7 +3,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) 2015-2023 Robert Beckebans
Copyright (C) 2020 Admer (id Tech Fox)
Copyright (C) 2022 Harrie van Ginneken
@ -943,6 +943,8 @@ bool idMapBrush::WriteValve220( idFile* fp, int primitiveNum, const idVec3& orig
return true;
}
/*
===============
idMapBrush::GetGeometryCRC
@ -1151,7 +1153,11 @@ bool idMapEntity::Write( idFile* fp, int entityNum, bool valve220 ) const
fp->WriteFloatString( "\"%s\" \"%s\"\n", epairs.GetKeyVal( i )->GetKey().c_str(), epairs.GetKeyVal( i )->GetValue().c_str() );
}
epairs.GetVector( "origin", "0 0 0", origin );
// RB: the "origin" key might have been replaced by the origin brush
if( !epairs.GetVector( "origin", "0 0 0", origin ) )
{
origin += originOffset;
}
// write pritimives
for( i = 0; i < GetNumPrimitives(); i++ )
@ -2970,6 +2976,7 @@ bool idMapFile::ConvertToValve220Format()
// is this oldschool brushes & patches?
if( ent->GetNumPrimitives() > 0 )
{
bool removedOrigin = false;
#if 1
if( !transform.IsIdentity() &&
idStr::Icmp( classname, "func_static" ) != 0 &&
@ -2979,6 +2986,8 @@ bool idMapFile::ConvertToValve220Format()
ent->epairs.Delete( "rotation" );
ent->epairs.Delete( "angles" );
ent->epairs.Delete( "angle" );
removedOrigin = true;
}
#endif
@ -3009,6 +3018,16 @@ bool idMapFile::ConvertToValve220Format()
}
}
// add origin brush as a replacement for the removed "origin" key
if( removedOrigin && ( origin != vec3_origin ) )
{
idMapBrush* originBrush = idMapBrush::MakeOriginBrush( origin, vec3_one );
ent->AddPrimitive( originBrush );
//ent->CalculateBrushOrigin();
ent->originOffset = origin;
}
// collect some statistics
const idKeyValue* kv = classTypeOverview.FindKey( classname );
@ -3059,17 +3078,6 @@ bool idMapFile::ConvertToValve220Format()
ent->epairs.SetAngles( "angles", angles );
}
// TODO use angles instead of angle
#if 0
if( ent->epairs.FindKey( "angle" ) )
{
ent->epairs.Delete( "angle" );
idAngles angles = rot.ToAngles();
ent->epairs.SetAngles( "angles", angles );
}
#endif
const idKeyValue* kv = classTypeOverview.FindKey( classname );
if( kv && kv->GetValue().Length() )
{
@ -3311,4 +3319,64 @@ void idMapFile::WadTextureToMaterial( const char* material, idStr& matName )
}
/*
============
RB idMapBrush::MakeOriginBrush
moved it here so Astyle won't mess up this file
============
*/
idMapBrush* idMapBrush::MakeOriginBrush( const idVec3& origin, const idVec3& scale )
{
/*
TrenchBroom
// brush 0
{
( -1 -64 -16 ) ( -1 -63 -16 ) ( -1 -64 -15 ) rock/lfwall15_lanrock1 [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 0.5 0.5
( -64 -1 -16 ) ( -64 -1 -15 ) ( -63 -1 -16 ) rock/lfwall15_lanrock1 [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 0.5 0.5
( -64 -64 -1 ) ( -63 -64 -1 ) ( -64 -63 -1 ) rock/lfwall15_lanrock1 [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 0.5 0.5
( 64 64 1 ) ( 64 65 1 ) ( 65 64 1 ) rock/lfwall15_lanrock1 [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 0.5 0.5
( 64 1 16 ) ( 65 1 16 ) ( 64 1 17 ) rock/lfwall15_lanrock1 [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 0.5 0.5
( 1 64 16 ) ( 1 64 17 ) ( 1 65 16 ) rock/lfwall15_lanrock1 [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 0.5 0.5
}
*/
const char* tbUnitBrush = R"(
( -1 -64 -16 ) ( -1 -63 -16 ) ( -1 -64 -15 ) common/origin [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 0.5 0.5
( -64 -1 -16 ) ( -64 -1 -15 ) ( -63 -1 -16 ) common/origin [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 0.5 0.5
( -64 -64 -1 ) ( -63 -64 -1 ) ( -64 -63 -1 ) common/origin [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 0.5 0.5
( 64 64 1 ) ( 64 65 1 ) ( 65 64 1 ) common/origin [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 0.5 0.5
( 64 1 16 ) ( 65 1 16 ) ( 64 1 17 ) common/origin [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 0.5 0.5
( 1 64 16 ) ( 1 64 17 ) ( 1 65 16 ) common/origin [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 0.5 0.5
}
}
)";
idLexer src( LEXFL_NOSTRINGCONCAT | LEXFL_NOSTRINGESCAPECHARS | LEXFL_ALLOWPATHNAMES );
src.LoadMemory( tbUnitBrush, strlen( tbUnitBrush), "Origin Brush" );
idMapBrush* brush = idMapBrush::ParseValve220( src, origin );
idMat3 axis;
axis.Identity();
axis[0][0] = scale.x;
axis[1][1] = scale.y;
axis[2][2] = scale.z;
idMat4 transform( axis, origin );
for( int i = 0; i < brush->GetNumSides(); i++ )
{
auto side = brush->GetSide( i );
side->planepts[0] *= transform;
side->planepts[1] *= transform;
side->planepts[2] *= transform;
}
return brush;
}
// RB end

View file

@ -3,7 +3,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2015-2021 Robert Beckebans
Copyright (C) 2015-2023 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -187,6 +187,11 @@ public:
static idMapBrush* ParseValve220( idLexer& src, const idVec3& origin ); // RB
bool Write( idFile* fp, int primitiveNum, const idVec3& origin ) const;
bool WriteValve220( idFile* fp, int primitiveNum, const idVec3& origin ) const; // RB
// returns an origin brush with the size of (2, 2, 2) by default
// so we can center the brush on a grid size of 1 in TrenchBroom
static idMapBrush* MakeOriginBrush( const idVec3& origin, const idVec3& scale = vec3_one );
int GetNumSides() const
{
return sides.Num();

View file

@ -1030,6 +1030,12 @@ void LightEditor::Draw()
{
DuplicateLight();
}
if( ImGui::MenuItem( "Delete", "Backspace" ) )
{
// TODO
goto exitLightEditor;
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
@ -1160,6 +1166,8 @@ void LightEditor::Draw()
TempApplyChanges();
}
exitLightEditor:
if( isShown && !showTool )
{
isShown = showTool;