Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5711: Add unimplemented legacy Q3 brush def exporter
- Loading branch information
1 parent
9979ea1
commit a34ace1
Showing
4 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
radiantcore/map/format/primitivewriters/LegacyBrushDefExporter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#pragma once | ||
|
||
#include "ibrush.h" | ||
#include "math/Plane3.h" | ||
#include "math/Matrix4.h" | ||
#include "shaderlib.h" | ||
|
||
#include "string/predicate.h" | ||
#include "ExportUtil.h" | ||
|
||
namespace map | ||
{ | ||
|
||
class LegacyBrushDefExporter | ||
{ | ||
public: | ||
|
||
// Writes an old Q3-style brush definition from the given brush to the given stream | ||
static void exportBrush(std::ostream& stream, const IBrushNodePtr& brushNode) | ||
{ | ||
const IBrush& brush = brushNode->getIBrush(); | ||
|
||
// Brush decl header | ||
stream << "{" << std::endl; | ||
stream << "brushDef" << std::endl; | ||
stream << "{" << std::endl; | ||
|
||
// Iterate over each brush face, exporting the tokens from all faces | ||
for (std::size_t i = 0; i < brush.getNumFaces(); ++i) | ||
{ | ||
writeFace(stream, brush.getFace(i), brush.getDetailFlag()); | ||
} | ||
|
||
// Close brush contents and header | ||
stream << "}" << std::endl << "}" << std::endl; | ||
} | ||
|
||
/* | ||
brushDef | ||
{ | ||
( -64 64 64 ) ( 64 -64 64 ) ( -64 -64 64 ) ( ( 0.015625 0 -0 ) ( -0 0.015625 0 ) ) common/caulk 0 0 0 | ||
( -64 64 64 ) ( 64 64 -64 ) ( 64 64 64 ) ( ( 0.015625 0 0 ) ( 0 0.015625 0 ) ) common/caulk 0 0 0 | ||
( 64 64 64 ) ( 64 -64 -64 ) ( 64 -64 64 ) ( ( 0.015625 0 -0 ) ( -0 0.015625 0 ) ) common/caulk 0 0 0 | ||
( 64 64 -64 ) ( -64 -64 -64 ) ( 64 -64 -64 ) ( ( 0.015625 0 -0 ) ( -0 0.015625 0 ) ) common/caulk 0 0 0 | ||
( 64 -64 -64 ) ( -64 -64 64 ) ( 64 -64 64 ) ( ( 0.015625 0 -0 ) ( -0 0.015625 0 ) ) common/caulk 0 0 0 | ||
( -64 -64 64 ) ( -64 64 -64 ) ( -64 64 64 ) ( ( 0.015625 0 -0 ) ( -0 0.015625 0 ) ) common/caulk 0 0 0 | ||
} | ||
*/ | ||
|
||
private: | ||
|
||
static void writeFace(std::ostream& stream, const IFace& face, IBrush::DetailFlag detailFlag) | ||
{ | ||
// greebo: Don't export faces with degenerate or empty windings (they are "non-contributing") | ||
const IWinding& winding = face.getWinding(); | ||
|
||
if (winding.size() <= 2) | ||
{ | ||
return; | ||
} | ||
|
||
// Each face plane is defined by three points | ||
|
||
stream << "( "; | ||
writeDoubleSafe(winding[2].vertex.x(), stream); | ||
stream << " "; | ||
writeDoubleSafe(winding[2].vertex.y(), stream); | ||
stream << " "; | ||
writeDoubleSafe(winding[2].vertex.z(), stream); | ||
stream << " "; | ||
stream << ") "; | ||
|
||
stream << "( "; | ||
writeDoubleSafe(winding[0].vertex.x(), stream); | ||
stream << " "; | ||
writeDoubleSafe(winding[0].vertex.y(), stream); | ||
stream << " "; | ||
writeDoubleSafe(winding[0].vertex.z(), stream); | ||
stream << " "; | ||
stream << ") "; | ||
|
||
stream << "( "; | ||
writeDoubleSafe(winding[1].vertex.x(), stream); | ||
stream << " "; | ||
writeDoubleSafe(winding[1].vertex.y(), stream); | ||
stream << " "; | ||
writeDoubleSafe(winding[1].vertex.z(), stream); | ||
stream << " "; | ||
stream << ") "; | ||
|
||
// Write TexDef | ||
Matrix4 texdef = face.getTexDefMatrix(); | ||
stream << "( "; | ||
|
||
stream << "( "; | ||
writeDoubleSafe(texdef.xx(), stream); | ||
stream << " "; | ||
writeDoubleSafe(texdef.yx(), stream); | ||
stream << " "; | ||
writeDoubleSafe(texdef.tx(), stream); | ||
stream << " ) "; | ||
|
||
stream << "( "; | ||
writeDoubleSafe(texdef.xy(), stream); | ||
stream << " "; | ||
writeDoubleSafe(texdef.yy(), stream); | ||
stream << " "; | ||
writeDoubleSafe(texdef.ty(), stream); | ||
stream << " ) "; | ||
|
||
stream << ") "; | ||
|
||
// Write Shader (without quotes) | ||
const std::string& shaderName = face.getShader(); | ||
|
||
if (shaderName.empty()) | ||
{ | ||
stream << "_default "; | ||
} | ||
else | ||
{ | ||
if (string::starts_with(shaderName, GlobalTexturePrefix_get())) | ||
{ | ||
// brushDef has an implicit "textures/" not written to the map, cut it off | ||
stream << "" << shader_get_textureName(shaderName.c_str()) << " "; | ||
} | ||
else | ||
{ | ||
stream << "" << shaderName << " "; | ||
} | ||
} | ||
|
||
// Export (dummy) contents/flags | ||
stream << detailFlag << " 0 0"; | ||
|
||
stream << std::endl; | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters